LLVM  15.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 
17 using 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 }
llvm::BlockFrequency::operator+
BlockFrequency operator+(BlockFrequency Freq) const
Definition: BlockFrequency.cpp:52
llvm::BranchProbability::scaleByInverse
uint64_t scaleByInverse(uint64_t Num) const
Scale a large integer by the inverse.
Definition: BranchProbability.cpp:111
llvm::BlockFrequency::operator-=
BlockFrequency & operator-=(BlockFrequency Freq)
Subtracts another block frequency using saturating arithmetic.
Definition: BlockFrequency.cpp:58
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::BlockFrequency::operator+=
BlockFrequency & operator+=(BlockFrequency Freq)
Adds another block frequency using saturating arithmetic.
Definition: BlockFrequency.cpp:41
BlockFrequency.h
llvm::BlockFrequency::operator*=
BlockFrequency & operator*=(BranchProbability Prob)
Multiplies with a branch probability.
Definition: BlockFrequency.cpp:19
llvm::BlockFrequency::operator>>=
BlockFrequency & operator>>=(const unsigned count)
Shift block frequency to the right by count digits saturating to 1.
Definition: BlockFrequency.cpp:73
llvm::BranchProbability::scale
uint64_t scale(uint64_t Num) const
Scale a large integer.
Definition: BranchProbability.cpp:107
UINT64_MAX
#define UINT64_MAX
Definition: DataTypes.h:77
BranchProbability.h
llvm::BlockFrequency
Definition: BlockFrequency.h:23
llvm::count
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:1699
uint64_t
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::BranchProbability
Definition: BranchProbability.h:29
llvm::BlockFrequency::operator/=
BlockFrequency & operator/=(BranchProbability Prob)
Divide by a non-zero branch probability using saturating arithmetic.
Definition: BlockFrequency.cpp:30
llvm::BlockFrequency::operator/
BlockFrequency operator/(BranchProbability Prob) const
Definition: BlockFrequency.cpp:35
llvm::BlockFrequency::operator*
BlockFrequency operator*(BranchProbability Prob) const
Definition: BlockFrequency.cpp:24
llvm::BlockFrequency::operator-
BlockFrequency operator-(BlockFrequency Freq) const
Definition: BlockFrequency.cpp:67