Create a wrapper pass for BranchProbabilityInfo.
[oota-llvm.git] / include / llvm / Analysis / BranchProbabilityInfo.h
index 9d867567ba2942e70af9ce6705881d00f0252fc1..9f7c0f9d747e5af89eede0d7e522cac0f1c2dc48 100644 (file)
@@ -25,9 +25,9 @@ namespace llvm {
 class LoopInfo;
 class raw_ostream;
 
-/// \brief Analysis pass providing branch probability information.
+/// \brief Analysis providing branch probability information.
 ///
-/// This is a function analysis pass which provides information on the relative
+/// This is a function analysis which provides information on the relative
 /// probabilities of each "edge" in the function's CFG where such an edge is
 /// defined by a pair (PredBlock and an index in the successors). The
 /// probability of an edge from one block is always relative to the
@@ -37,20 +37,11 @@ class raw_ostream;
 /// identify an edge, since we can have multiple edges from Src to Dst.
 /// As an example, we can have a switch which jumps to Dst with value 0 and
 /// value 10.
-class BranchProbabilityInfo : public FunctionPass {
+class BranchProbabilityInfo {
 public:
-  static char ID;
-
-  BranchProbabilityInfo() : FunctionPass(ID) {
-    initializeBranchProbabilityInfoPass(*PassRegistry::getPassRegistry());
-  }
-
-  void getAnalysisUsage(AnalysisUsage &AU) const override;
-  bool runOnFunction(Function &F) override;
+  void releaseMemory();
 
-  void releaseMemory() override;
-
-  void print(raw_ostream &OS, const Module *M = nullptr) const override;
+  void print(raw_ostream &OS) const;
 
   /// \brief Get an edge's probability, relative to other out-edges of the Src.
   ///
@@ -118,6 +109,8 @@ public:
     return IsLikely ? (1u << 20) - 1 : 1;
   }
 
+  void calculate(Function &F, const LoopInfo& LI);
+
 private:
   // Since we allow duplicate edges from one basic block to another, we use
   // a pair (PredBlock and an index in the successors) to specify an edge.
@@ -152,12 +145,33 @@ private:
   bool calcMetadataWeights(BasicBlock *BB);
   bool calcColdCallHeuristics(BasicBlock *BB);
   bool calcPointerHeuristics(BasicBlock *BB);
-  bool calcLoopBranchHeuristics(BasicBlock *BB);
+  bool calcLoopBranchHeuristics(BasicBlock *BB, const LoopInfo &LI);
   bool calcZeroHeuristics(BasicBlock *BB);
   bool calcFloatingPointHeuristics(BasicBlock *BB);
   bool calcInvokeHeuristics(BasicBlock *BB);
 };
 
+/// \brief Legacy analysis pass which computes \c BranchProbabilityInfo.
+class BranchProbabilityInfoWrapperPass : public FunctionPass {
+  BranchProbabilityInfo BPI;
+
+public:
+  static char ID;
+
+  BranchProbabilityInfoWrapperPass() : FunctionPass(ID) {
+    initializeBranchProbabilityInfoWrapperPassPass(
+        *PassRegistry::getPassRegistry());
+  }
+
+  BranchProbabilityInfo &getBPI() { return BPI; }
+  const BranchProbabilityInfo &getBPI() const { return BPI; }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override;
+  bool runOnFunction(Function &F) override;
+  void releaseMemory() override;
+  void print(raw_ostream &OS, const Module *M = nullptr) const override;
+};
+
 }
 
 #endif