diff options
author | Jakub Staszak <jstaszak@apple.com> | 2011-06-23 23:52:11 +0000 |
---|---|---|
committer | Jakub Staszak <jstaszak@apple.com> | 2011-06-23 23:52:11 +0000 |
commit | 66dddd1da3e036d05f94df82221a97b7d26e3498 (patch) | |
tree | dab8e540bcd86316d6e64b1fa8e04d2bcd15fc86 /include | |
parent | 0edb05b9e4a63d469a6cc9e15fa0dc8de7ee1cdf (diff) |
Calculate backedge probability correctly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133776 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Analysis/BlockFrequencyImpl.h | 17 | ||||
-rw-r--r-- | include/llvm/Analysis/BranchProbabilityInfo.h | 10 |
2 files changed, 13 insertions, 14 deletions
diff --git a/include/llvm/Analysis/BlockFrequencyImpl.h b/include/llvm/Analysis/BlockFrequencyImpl.h index 7447e80a31..cef375f10e 100644 --- a/include/llvm/Analysis/BlockFrequencyImpl.h +++ b/include/llvm/Analysis/BlockFrequencyImpl.h @@ -133,6 +133,15 @@ class BlockFrequencyImpl { } + /// Return a probability of getting to the DST block through SRC->DST edge. + /// + BranchProbability getBackEdgeProbability(BlockT *Src, BlockT *Dst) const { + uint32_t N = getEdgeFreq(Src, Dst); + uint32_t D = getBlockFreq(Dst); + + return BranchProbability(N, D); + } + /// isReachable - Returns if BB block is reachable from the entry. /// bool isReachable(BlockT *BB) { @@ -213,7 +222,9 @@ class BlockFrequencyImpl { return; assert(START_FREQ >= CycleProb[BB]); - divBlockFreq(BB, BranchProbability(START_FREQ - CycleProb[BB], START_FREQ)); + uint32_t CProb = CycleProb[BB]; + uint32_t Numerator = START_FREQ - CProb ? START_FREQ - CProb : 1; + divBlockFreq(BB, BranchProbability(Numerator, START_FREQ)); } /// doLoop - Propagate block frequency down throught the loop. @@ -238,19 +249,17 @@ class BlockFrequencyImpl { BlockT *Pred = *PI; assert(Pred); if (isReachable(Pred) && isBackedge(Pred, Head)) { - BranchProbability Prob = BPI->getBackEdgeProbability(Pred, Head); + BranchProbability Prob = getBackEdgeProbability(Pred, Head); uint64_t N = Prob.getNumerator(); uint64_t D = Prob.getDenominator(); uint64_t Res = (N * START_FREQ) / D; - // CycleProb[Head] += getEdgeFreq(Pred, Head); assert(Res <= UINT32_MAX); CycleProb[Head] += (uint32_t) Res; } } } - friend class BlockFrequency; void doFunction(FunctionT *fn, BlockProbInfoT *bpi) { diff --git a/include/llvm/Analysis/BranchProbabilityInfo.h b/include/llvm/Analysis/BranchProbabilityInfo.h index e40d2044dc..5a17a76f5b 100644 --- a/include/llvm/Analysis/BranchProbabilityInfo.h +++ b/include/llvm/Analysis/BranchProbabilityInfo.h @@ -39,9 +39,6 @@ class BranchProbabilityInfo : public FunctionPass { // Get sum of the block successors' weights. uint32_t getSumForBlock(BasicBlock *BB) const; - // Get sum of the edge weights going to the BB block. - uint32_t getBackSumForBlock(BasicBlock *BB) const; - public: static char ID; @@ -74,13 +71,6 @@ public: // only iff SRC block has only one successor. BranchProbability getEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const; - // Return a probability of getting to the DST block through SRC->DST edge. - // Returned value is a fraction between 0 (0% probability) and - // 1 (100% probability), however the value is never equal to 0, and can be 1 - // only iff DST block has only one predecesor. - BranchProbability getBackEdgeProbability(BasicBlock *Src, - BasicBlock *Dst) const; - // Print value between 0 (0% probability) and 1 (100% probability), // however the value is never equal to 0, and can be 1 only iff SRC block // has only one successor. |