[PATCH] D15489: Use getEdgeProbability() instead of getEdgeWeight() in BFI and remove getEdgeWeight() interfaces from MBPI.

Cong Hou via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 14 02:34:33 PST 2015


congh created this revision.
congh added a reviewer: davidxl.
congh added a subscriber: llvm-commits.

This patch remove 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.

http://reviews.llvm.org/D15489

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

Index: test/Analysis/BlockFrequencyInfo/bad_input.ll
===================================================================
--- test/Analysis/BlockFrequencyInfo/bad_input.ll
+++ test/Analysis/BlockFrequencyInfo/bad_input.ll
@@ -9,8 +9,8 @@
 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)
Index: lib/CodeGen/MachineBranchProbabilityInfo.cpp
===================================================================
--- lib/CodeGen/MachineBranchProbabilityInfo.cpp
+++ lib/CodeGen/MachineBranchProbabilityInfo.cpp
@@ -28,19 +28,6 @@
 
 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 {
Index: include/llvm/CodeGen/MachineBranchProbabilityInfo.h
===================================================================
--- include/llvm/CodeGen/MachineBranchProbabilityInfo.h
+++ include/llvm/CodeGen/MachineBranchProbabilityInfo.h
@@ -45,16 +45,6 @@
     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;
Index: include/llvm/Analysis/BlockFrequencyInfoImpl.h
===================================================================
--- include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1189,10 +1189,8 @@
     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),
-                     BPI->getEdgeWeight(BB, SI)))
+                     BPI->getEdgeProbability(BB, SI).getNumerator()))
         // Irreducible backedge.
         return false;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15489.42696.patch
Type: text/x-patch
Size: 3192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151214/1b029c06/attachment.bin>


More information about the llvm-commits mailing list