LCOV - code coverage report
Current view: top level - include/llvm/CodeGen - MachineBranchProbabilityInfo.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 5 5 100.0 %
Date: 2018-10-20 13:21:21 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //=- MachineBranchProbabilityInfo.h - Branch Probability Analysis -*- C++ -*-=//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This pass is used to evaluate branch probabilties on machine basic blocks.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #ifndef LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
      15             : #define LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
      16             : 
      17             : #include "llvm/CodeGen/MachineBasicBlock.h"
      18             : #include "llvm/Pass.h"
      19             : #include "llvm/Support/BranchProbability.h"
      20             : #include <climits>
      21             : #include <numeric>
      22             : 
      23             : namespace llvm {
      24             : 
      25             : class MachineBranchProbabilityInfo : public ImmutablePass {
      26             :   virtual void anchor();
      27             : 
      28             :   // Default weight value. Used when we don't have information about the edge.
      29             :   // TODO: DEFAULT_WEIGHT makes sense during static predication, when none of
      30             :   // the successors have a weight yet. But it doesn't make sense when providing
      31             :   // weight to an edge that may have siblings with non-zero weights. This can
      32             :   // be handled various ways, but it's probably fine for an edge with unknown
      33             :   // weight to just "inherit" the non-zero weight of an adjacent successor.
      34             :   static const uint32_t DEFAULT_WEIGHT = 16;
      35             : 
      36             : public:
      37             :   static char ID;
      38             : 
      39       27454 :   MachineBranchProbabilityInfo() : ImmutablePass(ID) {
      40       27454 :     PassRegistry &Registry = *PassRegistry::getPassRegistry();
      41       27454 :     initializeMachineBranchProbabilityInfoPass(Registry);
      42             :   }
      43             : 
      44       27454 :   void getAnalysisUsage(AnalysisUsage &AU) const override {
      45             :     AU.setPreservesAll();
      46       27454 :   }
      47             : 
      48             :   // Return edge probability.
      49             :   BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
      50             :                                        const MachineBasicBlock *Dst) const;
      51             : 
      52             :   // Same as above, but using a const_succ_iterator from Src. This is faster
      53             :   // when the iterator is already available.
      54             :   BranchProbability
      55             :   getEdgeProbability(const MachineBasicBlock *Src,
      56             :                      MachineBasicBlock::const_succ_iterator Dst) const;
      57             : 
      58             :   // A 'Hot' edge is an edge which probability is >= 80%.
      59             :   bool isEdgeHot(const MachineBasicBlock *Src,
      60             :                  const MachineBasicBlock *Dst) const;
      61             : 
      62             :   // Return a hot successor for the block BB or null if there isn't one.
      63             :   // NB: This routine's complexity is linear on the number of successors.
      64             :   MachineBasicBlock *getHotSucc(MachineBasicBlock *MBB) const;
      65             : 
      66             :   // Print value between 0 (0% probability) and 1 (100% probability),
      67             :   // however the value is never equal to 0, and can be 1 only iff SRC block
      68             :   // has only one successor.
      69             :   raw_ostream &printEdgeProbability(raw_ostream &OS,
      70             :                                     const MachineBasicBlock *Src,
      71             :                                     const MachineBasicBlock *Dst) const;
      72             : };
      73             : 
      74             : }
      75             : 
      76             : 
      77             : #endif

Generated by: LCOV version 1.13