[llvm-commits] [llvm] r136398 - /llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
Jakub Staszak
jstaszak at apple.com
Thu Jul 28 14:33:46 PDT 2011
Author: kuba
Date: Thu Jul 28 16:33:46 2011
New Revision: 136398
URL: http://llvm.org/viewvc/llvm-project?rev=136398&view=rev
Log:
Add InEdges (edges from header to the loop) in Loop Branch Heuristics, so
there is no frequency difference whether condition is in the header or in
the latch.
Modified:
llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=136398&r1=136397&r2=136398&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Thu Jul 28 16:33:46 2011
@@ -205,6 +205,9 @@
SmallVector<BasicBlock *, 8> BackEdges;
SmallVector<BasicBlock *, 8> ExitingEdges;
+ SmallVector<BasicBlock *, 8> InEdges; // Edges from header to the loop.
+
+ bool isHeader = BB == L->getHeader();
for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
BasicBlock *Succ = *I;
@@ -213,6 +216,8 @@
ExitingEdges.push_back(Succ);
else if (Succ == L->getHeader())
BackEdges.push_back(Succ);
+ else if (isHeader)
+ InEdges.push_back(Succ);
}
if (uint32_t numBackEdges = BackEdges.size()) {
@@ -227,6 +232,18 @@
}
}
+ if (uint32_t numInEdges = InEdges.size()) {
+ uint32_t inWeight = LBH_TAKEN_WEIGHT / numInEdges;
+ if (inWeight < NORMAL_WEIGHT)
+ inWeight = NORMAL_WEIGHT;
+
+ for (SmallVector<BasicBlock *, 8>::iterator EI = InEdges.begin(),
+ EE = InEdges.end(); EI != EE; ++EI) {
+ BasicBlock *Back = *EI;
+ BP->setEdgeWeight(BB, Back, inWeight);
+ }
+ }
+
uint32_t numExitingEdges = ExitingEdges.size();
if (uint32_t numNonExitingEdges = numSuccs - numExitingEdges) {
uint32_t exitWeight = LBH_NONTAKEN_WEIGHT / numNonExitingEdges;
More information about the llvm-commits
mailing list