Let operator/ with uint32_t rhs operand be a member of BranchProbability and add a new operator /=. NFC.

llvm-svn: 255595
This commit is contained in:
Cong Hou 2015-12-15 01:21:14 +00:00
parent 48b840dda1
commit 750c9e0457
1 changed files with 13 additions and 6 deletions

View File

@ -117,6 +117,14 @@ public:
return *this;
}
BranchProbability &operator/=(uint32_t RHS) {
assert(N != UnknownN &&
"Unknown probability cannot participate in arithmetics.");
assert(RHS > 0 && "The divider cannot be zero.");
N /= RHS;
return *this;
}
BranchProbability operator+(BranchProbability RHS) const {
BranchProbability Prob(*this);
return Prob += RHS;
@ -132,6 +140,11 @@ public:
return Prob *= RHS;
}
BranchProbability operator/(uint32_t RHS) const {
BranchProbability Prob(*this);
return Prob /= RHS;
}
bool operator==(BranchProbability RHS) const { return N == RHS.N; }
bool operator!=(BranchProbability RHS) const { return !(*this == RHS); }
@ -164,12 +177,6 @@ inline raw_ostream &operator<<(raw_ostream &OS, BranchProbability Prob) {
return Prob.print(OS);
}
inline BranchProbability operator/(BranchProbability LHS, uint32_t RHS) {
assert(LHS != BranchProbability::getUnknown() &&
"Unknown probability cannot participate in arithmetics.");
return BranchProbability::getRaw(LHS.getNumerator() / RHS);
}
template <class ProbabilityIter>
void BranchProbability::normalizeProbabilities(ProbabilityIter Begin,
ProbabilityIter End) {