14 #ifndef LLVM_SUPPORT_BRANCHPROBABILITY_H 15 #define LLVM_SUPPORT_BRANCHPROBABILITY_H 37 static const uint32_t UnknownN = UINT32_MAX;
47 bool isZero()
const {
return N == 0; }
58 uint64_t Denominator);
62 template <
class ProbabilityIter>
82 uint64_t
scale(uint64_t Num)
const;
93 assert(N != UnknownN && RHS.N != UnknownN &&
94 "Unknown probability cannot participate in arithmetics.");
96 N = (uint64_t(N) + RHS.N > D) ? D : N + RHS.N;
101 assert(N != UnknownN && RHS.N != UnknownN &&
102 "Unknown probability cannot participate in arithmetics.");
104 N = N < RHS.N ? 0 : N - RHS.N;
109 assert(N != UnknownN && RHS.N != UnknownN &&
110 "Unknown probability cannot participate in arithmetics.");
111 N = (
static_cast<uint64_t
>(N) * RHS.N + D / 2) / D;
117 "Unknown probability cannot participate in arithmetics.");
118 N = (uint64_t(N) * RHS > D) ? D : N * RHS;
124 "Unknown probability cannot participate in arithmetics.");
125 assert(RHS > 0 &&
"The divider cannot be zero.");
159 assert(N != UnknownN && RHS.N != UnknownN &&
160 "Unknown probability cannot participate in comparisons.");
165 assert(N != UnknownN && RHS.N != UnknownN &&
166 "Unknown probability cannot participate in comparisons.");
171 assert(N != UnknownN && RHS.N != UnknownN &&
172 "Unknown probability cannot participate in comparisons.");
173 return !(RHS < *
this);
177 assert(N != UnknownN && RHS.N != UnknownN &&
178 "Unknown probability cannot participate in comparisons.");
179 return !(*
this < RHS);
184 return Prob.
print(OS);
187 template <
class ProbabilityIter>
189 ProbabilityIter End) {
193 unsigned UnknownProbCount = 0;
194 uint64_t Sum = std::accumulate(Begin, End, uint64_t(0),
202 if (UnknownProbCount > 0) {
211 std::replace_if(Begin, End,
221 std::fill(Begin, End, BP);
225 for (
auto I = Begin;
I != End; ++
I)
226 I->N = (
I->N * uint64_t(D) + Sum / 2) / Sum;
BranchProbability getCompl() const
bool operator<(BranchProbability RHS) const
This class represents lattice values for constants.
bool operator>(BranchProbability RHS) const
static BranchProbability getRaw(uint32_t N)
static BranchProbability getOne()
BranchProbability operator/(uint32_t RHS) const
BranchProbability operator+(BranchProbability RHS) const
uint64_t scaleByInverse(uint64_t Num) const
Scale a large integer by the inverse.
BranchProbability operator*(uint32_t RHS) const
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
BranchProbability & operator+=(BranchProbability RHS)
bool operator==(BranchProbability RHS) const
bool operator<=(BranchProbability RHS) const
static BranchProbability getUnknown()
static uint32_t getDenominator()
static BranchProbability getBranchProbability(uint64_t Numerator, uint64_t Denominator)
uint64_t scale(uint64_t Num) const
Scale a large integer.
BranchProbability & operator-=(BranchProbability RHS)
BranchProbability & operator/=(uint32_t RHS)
BranchProbability operator-(BranchProbability RHS) const
bool operator>=(BranchProbability RHS) const
BranchProbability & operator*=(uint32_t RHS)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
BranchProbability & operator*=(BranchProbability RHS)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_ostream & print(raw_ostream &OS) const
This class implements an extremely fast bulk output stream that can only output to a stream...
static BranchProbability getZero()
BranchProbability operator*(BranchProbability RHS) const
bool operator!=(BranchProbability RHS) const
uint32_t getNumerator() const