Skip to content

Commit

Permalink
Modify the interface BranchProbability::normalizeProbabilities to let…
Browse files Browse the repository at this point in the history
… it accept a pair of iterators. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253417 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Cong Hou committed Nov 18, 2015
1 parent d4cf584 commit 1763c9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/llvm/CodeGen/MachineBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class MachineBasicBlock
/// 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
Expand Down
21 changes: 13 additions & 8 deletions include/llvm/Support/BranchProbability.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class BranchProbability {

// 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.
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 1763c9f

Please sign in to comment.