Use getEdgeProbability() instead of getEdgeWeight() in BFI and remove getEdgeWeight...
authorCong Hou <congh@google.com>
Fri, 18 Dec 2015 21:53:24 +0000 (21:53 +0000)
committerCong Hou <congh@google.com>
Fri, 18 Dec 2015 21:53:24 +0000 (21:53 +0000)
This patch removes all getEdgeWeight() interfaces from CodeGen directory. As
getEdgeProbability() is a little more expensive than getEdgeWeight(), I will
compose a patch soon in which BPI only stores probabilities instead of edge
weights so that getEdgeProbability() will have O(1) time.

Differential revision: http://reviews.llvm.org/D15489

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256039 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/BlockFrequencyInfoImpl.h
include/llvm/CodeGen/MachineBranchProbabilityInfo.h
lib/CodeGen/MachineBranchProbabilityInfo.cpp
test/Analysis/BlockFrequencyInfo/bad_input.ll

index d7379b8fbeaa8cf14e55bec82593a01086af3efe..387e9a887d93ceb8c8b11b29ba2fa2eab042e497 100644 (file)
@@ -1173,6 +1173,13 @@ void BlockFrequencyInfoImpl<BT>::computeIrreducibleMass(
   updateLoopWithIrreducible(*OuterLoop);
 }
 
   updateLoopWithIrreducible(*OuterLoop);
 }
 
+namespace {
+// A helper function that converts a branch probability into weight.
+inline uint32_t getWeightFromBranchProb(const BranchProbability Prob) {
+  return Prob.getNumerator();
+}
+} // namespace
+
 template <class BT>
 bool
 BlockFrequencyInfoImpl<BT>::propagateMassToSuccessors(LoopData *OuterLoop,
 template <class BT>
 bool
 BlockFrequencyInfoImpl<BT>::propagateMassToSuccessors(LoopData *OuterLoop,
@@ -1189,10 +1196,8 @@ BlockFrequencyInfoImpl<BT>::propagateMassToSuccessors(LoopData *OuterLoop,
     const BlockT *BB = getBlock(Node);
     for (auto SI = Successor::child_begin(BB), SE = Successor::child_end(BB);
          SI != SE; ++SI)
     const BlockT *BB = getBlock(Node);
     for (auto SI = Successor::child_begin(BB), SE = Successor::child_end(BB);
          SI != SE; ++SI)
-      // Do not dereference SI, or getEdgeWeight() is linear in the number of
-      // successors.
       if (!addToDist(Dist, OuterLoop, Node, getNode(*SI),
       if (!addToDist(Dist, OuterLoop, Node, getNode(*SI),
-                     BPI->getEdgeWeight(BB, SI)))
+                     getWeightFromBranchProb(BPI->getEdgeProbability(BB, SI))))
         // Irreducible backedge.
         return false;
   }
         // Irreducible backedge.
         return false;
   }
index 608e8d257874db1fb6cecb7fbe09750aa041b00e..81b0524cf0a4d44e0bfa9a1cb8ad52475b0aed4d 100644 (file)
@@ -45,16 +45,6 @@ public:
     AU.setPreservesAll();
   }
 
     AU.setPreservesAll();
   }
 
-  // Return edge weight. If we don't have any informations about it - return
-  // DEFAULT_WEIGHT.
-  uint32_t getEdgeWeight(const MachineBasicBlock *Src,
-                         const MachineBasicBlock *Dst) const;
-
-  // Same thing, but using a const_succ_iterator from Src. This is faster when
-  // the iterator is already available.
-  uint32_t getEdgeWeight(const MachineBasicBlock *Src,
-                         MachineBasicBlock::const_succ_iterator Dst) const;
-
   // Return edge probability.
   BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
                                        const MachineBasicBlock *Dst) const;
   // Return edge probability.
   BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
                                        const MachineBasicBlock *Dst) const;
index 5478dcba261af90fcf58aea6efb73dbf911c187d..cf6d4018cb703ad1967407aab2bac6258ebea171 100644 (file)
@@ -28,19 +28,6 @@ char MachineBranchProbabilityInfo::ID = 0;
 
 void MachineBranchProbabilityInfo::anchor() { }
 
 
 void MachineBranchProbabilityInfo::anchor() { }
 
-uint32_t MachineBranchProbabilityInfo::getEdgeWeight(
-    const MachineBasicBlock *Src,
-    MachineBasicBlock::const_succ_iterator Dst) const {
-  return Src->getSuccProbability(Dst).getNumerator();
-}
-
-uint32_t MachineBranchProbabilityInfo::getEdgeWeight(
-    const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const {
-  // This is a linear search. Try to use the const_succ_iterator version when
-  // possible.
-  return getEdgeWeight(Src, std::find(Src->succ_begin(), Src->succ_end(), Dst));
-}
-
 BranchProbability MachineBranchProbabilityInfo::getEdgeProbability(
     const MachineBasicBlock *Src,
     MachineBasicBlock::const_succ_iterator Dst) const {
 BranchProbability MachineBranchProbabilityInfo::getEdgeProbability(
     const MachineBasicBlock *Src,
     MachineBasicBlock::const_succ_iterator Dst) const {
index e5b1f500e1e6476d14e93174843b39e149102727..20b87e6dfcb407d14f7c65610b6594b874300b08 100644 (file)
@@ -9,8 +9,8 @@ define void @branch_weight_0(i32 %a) {
 entry:
   br label %for.body
 
 entry:
   br label %for.body
 
-; Check that we get 1,4 instead of 0,3.
-; CHECK-NEXT: for.body: float = 4.0,
+; Check that we get 1 and a huge frequency instead of 0,3.
+; CHECK-NEXT: for.body: float = 2147483647.8,
 for.body:
   %i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
   call void @g(i32 %i)
 for.body:
   %i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
   call void @g(i32 %i)