diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-10-21 20:12:47 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-10-21 20:12:47 +0000 |
commit | c888aa47bdf4b5766f30e4d1a2c3c2d4e06a18b5 (patch) | |
tree | a87eaa70903f839194e6ac791e8bf0222df22271 | |
parent | cdcfa280568d5d48ebeba2dcfc87915105e090d1 (diff) | |
download | external_llvm-c888aa47bdf4b5766f30e4d1a2c3c2d4e06a18b5.zip external_llvm-c888aa47bdf4b5766f30e4d1a2c3c2d4e06a18b5.tar.gz external_llvm-c888aa47bdf4b5766f30e4d1a2c3c2d4e06a18b5.tar.bz2 |
BranchProbabilityInfo: floating point equality is unlikely.
This is from the same paper from Ball and Larus as the rest of the currently implemented heuristics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142677 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/BranchProbabilityInfo.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/Analysis/BranchProbabilityInfo.cpp b/lib/Analysis/BranchProbabilityInfo.cpp index 52090c9..6e8d7e0 100644 --- a/lib/Analysis/BranchProbabilityInfo.cpp +++ b/lib/Analysis/BranchProbabilityInfo.cpp @@ -76,6 +76,9 @@ class BranchProbabilityAnalysis { static const uint32_t ZH_TAKEN_WEIGHT = 20; static const uint32_t ZH_NONTAKEN_WEIGHT = 12; + static const uint32_t FPH_TAKEN_WEIGHT = 20; + static const uint32_t FPH_NONTAKEN_WEIGHT = 12; + // Standard weight value. Used when none of the heuristics set weight for // the edge. static const uint32_t NORMAL_WEIGHT = 16; @@ -131,9 +134,12 @@ public: // Loop Branch Heuristics bool calcLoopBranchHeuristics(BasicBlock *BB); - // Zero Heurestics + // Zero Heuristics bool calcZeroHeuristics(BasicBlock *BB); + // Floating Point Heuristics + bool calcFloatingPointHeuristics(BasicBlock *BB); + bool runOnFunction(Function &F); }; } // end anonymous namespace @@ -378,6 +384,29 @@ bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) { return true; } +bool BranchProbabilityAnalysis::calcFloatingPointHeuristics(BasicBlock *BB) { + BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator()); + if (!BI || !BI->isConditional()) + return false; + + Value *Cond = BI->getCondition(); + FCmpInst *FCmp = dyn_cast<FCmpInst>(Cond); + if (!FCmp || !FCmp->isEquality()) + return false; + + BasicBlock *Taken = BI->getSuccessor(0); + BasicBlock *NonTaken = BI->getSuccessor(1); + + // f1 == f2 -> Unlikely + // f1 != f2 -> Likely + if (FCmp->isTrueWhenEqual()) + std::swap(Taken, NonTaken); + + BP->setEdgeWeight(BB, Taken, FPH_TAKEN_WEIGHT); + BP->setEdgeWeight(BB, NonTaken, FPH_NONTAKEN_WEIGHT); + + return true; +} bool BranchProbabilityAnalysis::runOnFunction(Function &F) { @@ -396,7 +425,10 @@ bool BranchProbabilityAnalysis::runOnFunction(Function &F) { if (calcPointerHeuristics(BB)) continue; - calcZeroHeuristics(BB); + if (calcZeroHeuristics(BB)) + continue; + + calcFloatingPointHeuristics(BB); } return false; |