diff options
author | Manman Ren <manman.ren@gmail.com> | 2014-01-27 23:39:03 +0000 |
---|---|---|
committer | Manman Ren <manman.ren@gmail.com> | 2014-01-27 23:39:03 +0000 |
commit | aa6627016ff797a0b206791d170aa7e677096553 (patch) | |
tree | 47bfb0fdea769fcb8932872907583e0f83e7877e /lib | |
parent | 01df6842c1e8890d8f529683ed6d6e7b6bb172d8 (diff) | |
download | llvm-aa6627016ff797a0b206791d170aa7e677096553.tar.gz llvm-aa6627016ff797a0b206791d170aa7e677096553.tar.bz2 llvm-aa6627016ff797a0b206791d170aa7e677096553.tar.xz |
PGO branch weight: keep halving the weights until they can fit into
uint32.
When folding branches to common destination, the updated branch weights
can exceed uint32 by more than factor of 2. We should keep halving the
weights until they can fit into uint32.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200262 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index e43c9e2708..0401b9a7f7 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -748,21 +748,22 @@ static void GetBranchWeights(TerminatorInst *TI, } } -/// Sees if any of the weights are too big for a uint32_t, and halves all the -/// weights if any are. +/// Keep halving the weights until all can fit in uint32_t. static void FitWeights(MutableArrayRef<uint64_t> Weights) { - bool Halve = false; - for (unsigned i = 0; i < Weights.size(); ++i) - if (Weights[i] > UINT_MAX) { - Halve = true; - break; - } + while (true) { + bool Halve = false; + for (unsigned i = 0; i < Weights.size(); ++i) + if (Weights[i] > UINT_MAX) { + Halve = true; + break; + } - if (! Halve) - return; + if (! Halve) + return; - for (unsigned i = 0; i < Weights.size(); ++i) - Weights[i] /= 2; + for (unsigned i = 0; i < Weights.size(); ++i) + Weights[i] /= 2; + } } /// FoldValueComparisonIntoPredecessors - The specified terminator is a value |