LLVM 20.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
18
19using namespace llvm;
20
22 Frequency = Prob.scale(Frequency);
23 return *this;
24}
25
27 BlockFrequency Freq(Frequency);
28 Freq *= Prob;
29 return Freq;
30}
31
33 Frequency = Prob.scaleByInverse(Frequency);
34 return *this;
35}
36
38 BlockFrequency Freq(Frequency);
39 Freq /= Prob;
40 return Freq;
41}
42
43std::optional<BlockFrequency> BlockFrequency::mul(uint64_t Factor) const {
44 bool Overflow;
45 uint64_t ResultFrequency = SaturatingMultiply(Frequency, Factor, &Overflow);
46 if (Overflow)
47 return {};
48 return BlockFrequency(ResultFrequency);
49}
50
52 BlockFrequency Freq) {
53 if (Freq == BlockFrequency(0)) {
54 OS << "0";
55 return;
56 }
57 if (EntryFreq == BlockFrequency(0)) {
58 OS << "<invalid BFI>";
59 return;
60 }
62 ScaledNumber<uint64_t> Entry(EntryFreq.getFrequency(), 0);
63 OS << Block / Entry;
64}
raw_pwrite_stream & OS
BlockFrequency operator/(BranchProbability Prob) const
std::optional< BlockFrequency > mul(uint64_t Factor) const
Multiplies frequency with Factor. Returns nullopt in case of overflow.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
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.
Simple representation of a scaled number.
Definition: ScaledNumber.h:493
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.