LLVM  3.7.0
MachineBranchProbabilityInfo.h
Go to the documentation of this file.
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 
18 #include "llvm/Pass.h"
20 #include <climits>
21 
22 namespace llvm {
23 
25  virtual void anchor();
26 
27  // Default weight value. Used when we don't have information about the edge.
28  // TODO: DEFAULT_WEIGHT makes sense during static predication, when none of
29  // the successors have a weight yet. But it doesn't make sense when providing
30  // weight to an edge that may have siblings with non-zero weights. This can
31  // be handled various ways, but it's probably fine for an edge with unknown
32  // weight to just "inherit" the non-zero weight of an adjacent successor.
33  static const uint32_t DEFAULT_WEIGHT = 16;
34 
35 public:
36  static char ID;
37 
41  }
42 
43  void getAnalysisUsage(AnalysisUsage &AU) const override {
44  AU.setPreservesAll();
45  }
46 
47  // Return edge weight. If we don't have any informations about it - return
48  // DEFAULT_WEIGHT.
49  uint32_t getEdgeWeight(const MachineBasicBlock *Src,
50  const MachineBasicBlock *Dst) const;
51 
52  // Same thing, but using a const_succ_iterator from Src. This is faster when
53  // the iterator is already available.
54  uint32_t getEdgeWeight(const MachineBasicBlock *Src,
56 
57  // Get sum of the block successors' weights, potentially scaling them to fit
58  // within 32-bits. If scaling is required, sets Scale based on the necessary
59  // adjustment. Any edge weights used with the sum should be divided by Scale.
60  uint32_t getSumForBlock(const MachineBasicBlock *MBB, uint32_t &Scale) const;
61 
62  // A 'Hot' edge is an edge which probability is >= 80%.
63  bool isEdgeHot(const MachineBasicBlock *Src,
64  const MachineBasicBlock *Dst) const;
65 
66  // Return a hot successor for the block BB or null if there isn't one.
67  // NB: This routine's complexity is linear on the number of successors.
69 
70  // Return a probability as a fraction between 0 (0% probability) and
71  // 1 (100% probability), however the value is never equal to 0, and can be 1
72  // only iff SRC block has only one successor.
73  // NB: This routine's complexity is linear on the number of successors of
74  // Src. Querying sequentially for each successor's probability is a quadratic
75  // query pattern.
77  const MachineBasicBlock *Dst) const;
78 
79  // Print value between 0 (0% probability) and 1 (100% probability),
80  // however the value is never equal to 0, and can be 1 only iff SRC block
81  // has only one successor.
83  const MachineBasicBlock *Src,
84  const MachineBasicBlock *Dst) const;
85 };
86 
87 }
88 
89 
90 #endif
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:61
Represent the analysis usage information of a pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:262
MachineBasicBlock * getHotSucc(MachineBasicBlock *MBB) const
void setPreservesAll()
Set by analyses that do not transform their input at all.
uint32_t getSumForBlock(const MachineBasicBlock *MBB, uint32_t &Scale) const
bool isEdgeHot(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
void initializeMachineBranchProbabilityInfoPass(PassRegistry &)
uint32_t getEdgeWeight(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
raw_ostream & printEdgeProbability(raw_ostream &OS, const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:41
BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const