diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-03-09 14:42:55 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-03-09 14:42:55 +0000 |
| commit | 79da941f3ac36356feaacbc96846f914d5838df8 (patch) | |
| tree | e78a75d822d089ceb82d09b28b62ec2c9dec558d /llvm/lib/Transforms | |
| parent | fe3e0a2abff09d47696115b8cfcb0e0054a3eaf7 (diff) | |
| download | bcm5719-llvm-79da941f3ac36356feaacbc96846f914d5838df8.tar.gz bcm5719-llvm-79da941f3ac36356feaacbc96846f914d5838df8.zip | |
SimplifyCFG: Simplify the weight scaling algorithm.
No change in functionality.
llvm-svn: 203413
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 80f122ab83c..5b3bdbe4be2 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -732,8 +732,7 @@ static void GetBranchWeights(TerminatorInst *TI, MDNode* MD = TI->getMetadata(LLVMContext::MD_prof); assert(MD); for (unsigned i = 1, e = MD->getNumOperands(); i < e; ++i) { - ConstantInt* CI = dyn_cast<ConstantInt>(MD->getOperand(i)); - assert(CI); + ConstantInt *CI = cast<ConstantInt>(MD->getOperand(i)); Weights.push_back(CI->getValue().getZExtValue()); } @@ -750,19 +749,11 @@ static void GetBranchWeights(TerminatorInst *TI, /// Keep halving the weights until all can fit in uint32_t. static void FitWeights(MutableArrayRef<uint64_t> Weights) { - while (true) { - bool Halve = false; - for (unsigned i = 0; i < Weights.size(); ++i) - if (Weights[i] > UINT_MAX) { - Halve = true; - break; - } - - if (! Halve) - return; - - for (unsigned i = 0; i < Weights.size(); ++i) - Weights[i] /= 2; + uint64_t Max = *std::max_element(Weights.begin(), Weights.end()); + if (Max > UINT_MAX) { + unsigned Offset = 32 - countLeadingZeros(Max); + for (uint64_t &I : Weights) + I >>= Offset; } } |

