Modify the interface BranchProbability::normalizeProbabilities to let it accept a...
authorCong Hou <congh@google.com>
Wed, 18 Nov 2015 01:03:19 +0000 (01:03 +0000)
committerCong Hou <congh@google.com>
Wed, 18 Nov 2015 01:03:19 +0000 (01:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253417 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineBasicBlock.h
include/llvm/Support/BranchProbability.h

index 4f76b21..a2b1a85 100644 (file)
@@ -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
index e3acb56..71c0cf9 100644 (file)
@@ -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/(BranchProbability LHS, uint32_t RHS) {
   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>