From: Cong Hou Date: Wed, 18 Nov 2015 01:03:19 +0000 (+0000) Subject: Modify the interface BranchProbability::normalizeProbabilities to let it accept a... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1763c9fe3ae7eadf92d5ca2ad256ebe9a9366d9a;p=oota-llvm.git Modify the interface BranchProbability::normalizeProbabilities to let it accept a pair of iterators. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253417 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index 4f76b21fb00..a2b1a850ec7 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -476,7 +476,7 @@ public: /// Normalize probabilities of all successors so that the sum of them becomes /// one. void normalizeSuccProbs() { - BranchProbability::normalizeProbabilities(Probs); + BranchProbability::normalizeProbabilities(Probs.begin(), Probs.end()); } /// Remove successor from the successors list of this MachineBasicBlock. The diff --git a/include/llvm/Support/BranchProbability.h b/include/llvm/Support/BranchProbability.h index e3acb566b73..71c0cf9afea 100644 --- a/include/llvm/Support/BranchProbability.h +++ b/include/llvm/Support/BranchProbability.h @@ -56,8 +56,9 @@ public: // Normalize given probabilties so that the sum of them becomes approximate // one. - template - static void normalizeProbabilities(ProbabilityList &Probs); + template + static void normalizeProbabilities(ProbabilityIter Begin, + ProbabilityIter End); // Normalize a list of weights by scaling them down so that the sum of them // doesn't exceed UINT32_MAX. @@ -140,14 +141,18 @@ inline BranchProbability operator/(BranchProbability LHS, uint32_t RHS) { return BranchProbability::getRaw(LHS.getNumerator() / RHS); } -template -void BranchProbability::normalizeProbabilities(ProbabilityList &Probs) { +template +void BranchProbability::normalizeProbabilities(ProbabilityIter Begin, + ProbabilityIter End) { + if (Begin == End) + return; + uint64_t Sum = 0; - for (auto Prob : Probs) - Sum += Prob.N; + for (auto I = Begin; I != End; ++I) + Sum += I->N; assert(Sum > 0); - for (auto &Prob : Probs) - Prob.N = (Prob.N * uint64_t(D) + Sum / 2) / Sum; + for (auto I = Begin; I != End; ++I) + I->N = (I->N * uint64_t(D) + Sum / 2) / Sum; } template