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 | f1cb16e481a60dbac58affcf8c8e423dac3937cb (patch) | |
| tree | 08a9ce4e0a12bbfc194996f31a44b4b6a445ba46 /llvm/lib | |
| parent | c67e7976b3c71f718cb08364a65377d3f15c2499 (diff) | |
| download | bcm5719-llvm-f1cb16e481a60dbac58affcf8c8e423dac3937cb.tar.gz bcm5719-llvm-f1cb16e481a60dbac58affcf8c8e423dac3937cb.zip | |
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.
llvm-svn: 200262
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index e43c9e2708d..0401b9a7f7d 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/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 |

