LLVM 18.0.0git
BlockFrequency.cpp
Go to the documentation of this file.
1//====--------------- lib/Support/BlockFrequency.cpp -----------*- C++ -*-====//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements Block Frequency class.
10//
11//===----------------------------------------------------------------------===//
12
16
17using namespace llvm;
18
20 Frequency = Prob.scale(Frequency);
21 return *this;
22}
23
25 BlockFrequency Freq(Frequency);
26 Freq *= Prob;
27 return Freq;
28}
29
31 Frequency = Prob.scaleByInverse(Frequency);
32 return *this;
33}
34
36 BlockFrequency Freq(Frequency);
37 Freq /= Prob;
38 return Freq;
39}
40
41std::optional<BlockFrequency> BlockFrequency::mul(uint64_t Factor) const {
42 bool Overflow;
43 uint64_t ResultFrequency = SaturatingMultiply(Frequency, Factor, &Overflow);
44 if (Overflow)
45 return {};
46 return BlockFrequency(ResultFrequency);
47}
BlockFrequency operator/(BranchProbability Prob) const
std::optional< BlockFrequency > mul(uint64_t Factor) const
Multiplies frequency with Factor. Returns nullopt in case of overflow.
BlockFrequency operator*(BranchProbability Prob) const
BlockFrequency & operator*=(BranchProbability Prob)
Multiplies with a branch probability.
BlockFrequency & operator/=(BranchProbability Prob)
Divide by a non-zero branch probability using saturating arithmetic.
uint64_t scaleByInverse(uint64_t Num) const
Scale a large integer by the inverse.
uint64_t scale(uint64_t Num) const
Scale a large integer.
This is an optimization pass for GlobalISel generic memory operations.