From 7241caf7b841db57a21a44f64415e3d1a3398a9c Mon Sep 17 00:00:00 2001 From: Jakub Staszak Date: Thu, 28 Jul 2011 21:45:07 +0000 Subject: [PATCH] Heuristics are in descending priority now. If we use one of them, skip the rest. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136402 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BranchProbabilityInfo.cpp | 36 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/Analysis/BranchProbabilityInfo.cpp b/lib/Analysis/BranchProbabilityInfo.cpp index 5ac2d814a00..527a4ecbd88 100644 --- a/lib/Analysis/BranchProbabilityInfo.cpp +++ b/lib/Analysis/BranchProbabilityInfo.cpp @@ -134,13 +134,13 @@ public: } // Return Heuristics - void calcReturnHeuristics(BasicBlock *BB); + bool calcReturnHeuristics(BasicBlock *BB); // Pointer Heuristics - void calcPointerHeuristics(BasicBlock *BB); + bool calcPointerHeuristics(BasicBlock *BB); // Loop Branch Heuristics - void calcLoopBranchHeuristics(BasicBlock *BB); + bool calcLoopBranchHeuristics(BasicBlock *BB); bool runOnFunction(Function &F); }; @@ -148,34 +148,38 @@ public: // Calculate Edge Weights using "Return Heuristics". Predict a successor which // leads directly to Return Instruction will not be taken. -void BranchProbabilityAnalysis::calcReturnHeuristics(BasicBlock *BB){ +bool BranchProbabilityAnalysis::calcReturnHeuristics(BasicBlock *BB){ if (BB->getTerminator()->getNumSuccessors() == 1) - return; + return false; + bool Any = false; for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) { BasicBlock *Succ = *I; if (isReturningBlock(Succ)) { decEdgeWeight(BB, Succ); + Any = true; } } + + return Any; } // Calculate Edge Weights using "Pointer Heuristics". Predict a comparsion // between two pointer or pointer and NULL will fail. -void BranchProbabilityAnalysis::calcPointerHeuristics(BasicBlock *BB) { +bool BranchProbabilityAnalysis::calcPointerHeuristics(BasicBlock *BB) { BranchInst * BI = dyn_cast(BB->getTerminator()); if (!BI || !BI->isConditional()) - return; + return false; Value *Cond = BI->getCondition(); ICmpInst *CI = dyn_cast(Cond); if (!CI || !CI->isEquality()) - return; + return false; Value *LHS = CI->getOperand(0); if (!LHS->getType()->isPointerTy()) - return; + return false; assert(CI->getOperand(1)->getType()->isPointerTy()); @@ -192,16 +196,17 @@ void BranchProbabilityAnalysis::calcPointerHeuristics(BasicBlock *BB) { incEdgeWeight(BB, Taken); decEdgeWeight(BB, NonTaken); + return true; } // Calculate Edge Weights using "Loop Branch Heuristics". Predict backedges // as taken, exiting edges as not-taken. -void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) { +bool BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) { uint32_t numSuccs = BB->getTerminator()->getNumSuccessors(); Loop *L = LI->getLoopFor(BB); if (!L) - return; + return false; SmallVector BackEdges; SmallVector ExitingEdges; @@ -256,6 +261,8 @@ void BranchProbabilityAnalysis::calcLoopBranchHeuristics(BasicBlock *BB) { BP->setEdgeWeight(BB, Exiting, exitWeight); } } + + return true; } bool BranchProbabilityAnalysis::runOnFunction(Function &F) { @@ -264,12 +271,15 @@ bool BranchProbabilityAnalysis::runOnFunction(Function &F) { BasicBlock *BB = I++; // Only LBH uses setEdgeWeight method. - calcLoopBranchHeuristics(BB); + if (calcLoopBranchHeuristics(BB)) + continue; // PH and RH use only incEdgeWeight and decEwdgeWeight methods to // not efface LBH results. + if (calcReturnHeuristics(BB)) + continue; + calcPointerHeuristics(BB); - calcReturnHeuristics(BB); } return false;