diff options
author | Juergen Ributzka <juergen@apple.com> | 2014-12-09 17:32:12 +0000 |
---|---|---|
committer | Juergen Ributzka <juergen@apple.com> | 2014-12-09 17:32:12 +0000 |
commit | 194350a93697fc8f16dceb08d511c574fd423804 (patch) | |
tree | 5ede44745f85cbf0f2847290b80d54d9e7cf4d2c /llvm/lib/CodeGen | |
parent | 04aef05537387b26a3e939831199b198ab3dfbbe (diff) | |
download | bcm5719-llvm-194350a93697fc8f16dceb08d511c574fd423804.tar.gz bcm5719-llvm-194350a93697fc8f16dceb08d511c574fd423804.zip |
Revert "Move function to obtain branch weights into the BranchInst class. NFC."
This reverts commit r223784 and copies the 'ExtractBranchMetadata' to CodeGenPrepare.
llvm-svn: 223795
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 8b92cf2e9f4..e043bfbfa27 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -3800,6 +3800,27 @@ bool CodeGenPrepare::sinkAndCmp(Function &F) { return MadeChange; } +/// \brief Retrieve the probabilities of a conditional branch. Returns true on +/// success, or returns false if no or invalid metadata was found. +static bool extractBranchMetadata(BranchInst *BI, + uint64_t &ProbTrue, uint64_t &ProbFalse) { + assert(BI->isConditional() && + "Looking for probabilities on unconditional branch?"); + auto *ProfileData = BI->getMetadata(LLVMContext::MD_prof); + if (!ProfileData || ProfileData->getNumOperands() != 3) + return false; + + const auto *CITrue = dyn_cast<ConstantInt>(ProfileData->getOperand(1)); + const auto *CIFalse = dyn_cast<ConstantInt>(ProfileData->getOperand(2)); + if (!CITrue || !CIFalse) + return false; + + ProbTrue = CITrue->getValue().getZExtValue(); + ProbFalse = CIFalse->getValue().getZExtValue(); + + return true; +} + /// \brief Scale down both weights to fit into uint32_t. static void scaleWeights(uint64_t &NewTrue, uint64_t &NewFalse) { uint64_t NewMax = (NewTrue > NewFalse) ? NewTrue : NewFalse; @@ -3942,7 +3963,7 @@ bool CodeGenPrepare::splitBranchCondition(Function &F) { // Another choice is to assume TrueProb for BB1 equals to TrueProb for // TmpBB, but the math is more complicated. uint64_t TrueWeight, FalseWeight; - if (Br1->getBranchWeights(TrueWeight, FalseWeight)) { + if (extractBranchMetadata(Br1, TrueWeight, FalseWeight)) { uint64_t NewTrueWeight = TrueWeight; uint64_t NewFalseWeight = TrueWeight + 2 * FalseWeight; scaleWeights(NewTrueWeight, NewFalseWeight); @@ -3975,7 +3996,7 @@ bool CodeGenPrepare::splitBranchCondition(Function &F) { // assumes that // FalseProb for BB1 == TrueProb for BB1 * FalseProb for TmpBB. uint64_t TrueWeight, FalseWeight; - if (Br1->getBranchWeights(TrueWeight, FalseWeight)) { + if (extractBranchMetadata(Br1, TrueWeight, FalseWeight)) { uint64_t NewTrueWeight = 2 * TrueWeight + FalseWeight; uint64_t NewFalseWeight = FalseWeight; scaleWeights(NewTrueWeight, NewFalseWeight); |