llvm.org GIT mirror llvm / 1763c9f
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 Cong Hou 4 years ago
2 changed file(s) with 14 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
475475 /// Normalize probabilities of all successors so that the sum of them becomes
476476 /// one.
477477 void normalizeSuccProbs() {
478 BranchProbability::normalizeProbabilities(Probs);
478 BranchProbability::normalizeProbabilities(Probs.begin(), Probs.end());
479479 }
480480
481481 /// Remove successor from the successors list of this MachineBasicBlock. The
5555
5656 // Normalize given probabilties so that the sum of them becomes approximate
5757 // one.
58 template
59 static void normalizeProbabilities(ProbabilityList &Probs);
58 template
59 static void normalizeProbabilities(ProbabilityIter Begin,
60 ProbabilityIter End);
6061
6162 // Normalize a list of weights by scaling them down so that the sum of them
6263 // doesn't exceed UINT32_MAX.
139140 return BranchProbability::getRaw(LHS.getNumerator() / RHS);
140141 }
141142
142 template
143 void BranchProbability::normalizeProbabilities(ProbabilityList &Probs) {
143 template
144 void BranchProbability::normalizeProbabilities(ProbabilityIter Begin,
145 ProbabilityIter End) {
146 if (Begin == End)
147 return;
148
144149 uint64_t Sum = 0;
145 for (auto Prob : Probs)
146 Sum += Prob.N;
150 for (auto I = Begin; I != End; ++I)
151 Sum += I->N;
147152 assert(Sum > 0);
148 for (auto &Prob : Probs)
149 Prob.N = (Prob.N * uint64_t(D) + Sum / 2) / Sum;
153 for (auto I = Begin; I != End; ++I)
154 I->N = (I->N * uint64_t(D) + Sum / 2) / Sum;
150155 }
151156
152157 template