diff options
author | Cong Hou <congh@google.com> | 2015-08-06 18:17:29 +0000 |
---|---|---|
committer | Cong Hou <congh@google.com> | 2015-08-06 18:17:29 +0000 |
commit | ec105872056880da9689cfffdb296e32ca1ba876 (patch) | |
tree | 5363b408f75223b073c2cef8c7cba8cdd9d61735 /llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp | |
parent | f032c956de59891e0c64e8d85a3f68533ddc8de6 (diff) | |
download | bcm5719-llvm-ec105872056880da9689cfffdb296e32ca1ba876.tar.gz bcm5719-llvm-ec105872056880da9689cfffdb296e32ca1ba876.zip |
Revert r244154 which causes some build failure. See https://llvm.org/bugs/show_bug.cgi?id=24377.
llvm-svn: 244239
Diffstat (limited to 'llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp b/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp index fe03d4d0b5f..6fbc2be7048 100644 --- a/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp +++ b/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp @@ -28,35 +28,36 @@ char MachineBranchProbabilityInfo::ID = 0; void MachineBranchProbabilityInfo::anchor() { } -uint32_t -MachineBranchProbabilityInfo::getSumForBlock(MachineBasicBlock *MBB) const { - // Normalize the weights of MBB's all successors so that the sum is guaranteed - // to be no greater than UINT32_MAX. - MBB->normalizeSuccWeights(); - - SmallVector<uint32_t, 8> Weights; +uint32_t MachineBranchProbabilityInfo:: +getSumForBlock(const MachineBasicBlock *MBB, uint32_t &Scale) const { + // First we compute the sum with 64-bits of precision, ensuring that cannot + // overflow by bounding the number of weights considered. Hopefully no one + // actually needs 2^32 successors. + assert(MBB->succ_size() < UINT32_MAX); + uint64_t Sum = 0; + Scale = 1; for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(), - E = MBB->succ_end(); - I != E; ++I) - Weights.push_back(getEdgeWeight(MBB, I)); + E = MBB->succ_end(); I != E; ++I) { + uint32_t Weight = getEdgeWeight(MBB, I); + Sum += Weight; + } - return std::accumulate(Weights.begin(), Weights.end(), 0u); -} + // If the computed sum fits in 32-bits, we're done. + if (Sum <= UINT32_MAX) + return Sum; -uint32_t -MachineBranchProbabilityInfo::getSumForBlock(const MachineBasicBlock *MBB, - uint32_t &Scale) const { - SmallVector<uint32_t, 8> Weights; + // Otherwise, compute the scale necessary to cause the weights to fit, and + // re-sum with that scale applied. + assert((Sum / UINT32_MAX) < UINT32_MAX); + Scale = (Sum / UINT32_MAX) + 1; + Sum = 0; for (MachineBasicBlock::const_succ_iterator I = MBB->succ_begin(), - E = MBB->succ_end(); - I != E; ++I) - Weights.push_back(getEdgeWeight(MBB, I)); - - if (MBB->areSuccWeightsNormalized()) - Scale = 1; - else - Scale = MachineBranchProbabilityInfo::normalizeEdgeWeights(Weights); - return std::accumulate(Weights.begin(), Weights.end(), 0u); + E = MBB->succ_end(); I != E; ++I) { + uint32_t Weight = getEdgeWeight(MBB, I); + Sum += Weight / Scale; + } + assert(Sum <= UINT32_MAX); + return Sum; } uint32_t MachineBranchProbabilityInfo:: |