From fa44725233aa622b61942ec099b1c46806140b72 Mon Sep 17 00:00:00 2001 From: Jakub Staszak Date: Thu, 28 Jul 2011 21:33:46 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136398 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BranchProbabilityInfo.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Analysis/BranchProbabilityInfo.cpp b/lib/Analysis/BranchProbabilityInfo.cpp index e39cd221b5a..5ac2d814a00 100644 --- a/lib/Analysis/BranchProbabilityInfo.cpp +++ b/lib/Analysis/BranchProbabilityInfo.cpp @@ -205,6 +205,9 @@ void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) { SmallVector BackEdges; SmallVector ExitingEdges; + SmallVector 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 @@ void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) { 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 @@ void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) { } } + if (uint32_t numInEdges = InEdges.size()) { + uint32_t inWeight = LBH_TAKEN_WEIGHT / numInEdges; + if (inWeight < NORMAL_WEIGHT) + inWeight = NORMAL_WEIGHT; + + for (SmallVector::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;