LLVM 17.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.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements Block Frequency class.
10//
11//===----------------------------------------------------------------------===//
12
15#include <cassert>
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
42 uint64_t Before = Freq.Frequency;
43 Frequency += Freq.Frequency;
44
45 // If overflow, set frequency to the maximum value.
46 if (Frequency < Before)
47 Frequency = UINT64_MAX;
48
49 return *this;
50}
51
53 BlockFrequency NewFreq(Frequency);
54 NewFreq += Freq;
55 return NewFreq;
56}
57
59 // If underflow, set frequency to 0.
60 if (Frequency <= Freq.Frequency)
61 Frequency = 0;
62 else
63 Frequency -= Freq.Frequency;
64 return *this;
65}
66
68 BlockFrequency NewFreq(Frequency);
69 NewFreq -= Freq;
70 return NewFreq;
71}
72
74 // Frequency can never be 0 by design.
75 assert(Frequency != 0);
76
77 // Shift right by count.
78 Frequency >>= count;
79
80 // Saturate to 1 if we are 0.
81 Frequency |= Frequency == 0;
82 return *this;
83}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BlockFrequency operator-(BlockFrequency Freq) const
BlockFrequency operator/(BranchProbability Prob) const
BlockFrequency & operator-=(BlockFrequency Freq)
Subtracts another block frequency using saturating arithmetic.
BlockFrequency & operator+=(BlockFrequency Freq)
Adds another block frequency using saturating arithmetic.
BlockFrequency & operator>>=(const unsigned count)
Shift block frequency to the right by count digits saturating to 1.
BlockFrequency operator*(BranchProbability Prob) const
BlockFrequency operator+(BlockFrequency Freq) 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.
#define UINT64_MAX
Definition: DataTypes.h:77
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:2011