[llvm] r253417 - Modify the interface BranchProbability::normalizeProbabilities to let it accept a pair of iterators. NFC.
Cong Hou via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 17 17:03:19 PST 2015
Author: conghou
Date: Tue Nov 17 19:03:19 2015
New Revision: 253417
URL: http://llvm.org/viewvc/llvm-project?rev=253417&view=rev
Log:
Modify the interface BranchProbability::normalizeProbabilities to let it accept a pair of iterators. NFC.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
llvm/trunk/include/llvm/Support/BranchProbability.h
Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=253417&r1=253416&r2=253417&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Tue Nov 17 19:03:19 2015
@@ -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
Modified: llvm/trunk/include/llvm/Support/BranchProbability.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/BranchProbability.h?rev=253417&r1=253416&r2=253417&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/BranchProbability.h (original)
+++ llvm/trunk/include/llvm/Support/BranchProbability.h Tue Nov 17 19:03:19 2015
@@ -56,8 +56,9 @@ public:
// Normalize given probabilties so that the sum of them becomes approximate
// one.
- template <class ProbabilityList>
- static void normalizeProbabilities(ProbabilityList &Probs);
+ template <class ProbabilityIter>
+ 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/(Branc
return BranchProbability::getRaw(LHS.getNumerator() / RHS);
}
-template <class ProbabilityList>
-void BranchProbability::normalizeProbabilities(ProbabilityList &Probs) {
+template <class ProbabilityIter>
+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 <class WeightListIter>
More information about the llvm-commits
mailing list