LLVM  8.0.1
BlockFrequency.cpp
Go to the documentation of this file.
1 //====--------------- lib/Support/BlockFrequency.cpp -----------*- C++ -*-====//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements Block Frequency class.
11 //
12 //===----------------------------------------------------------------------===//
13 
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 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
uint64_t scaleByInverse(uint64_t Num) const
Scale a large integer by the inverse.
#define UINT64_MAX
Definition: DataTypes.h:83
BlockFrequency operator*(BranchProbability Prob) const
BlockFrequency & operator/=(BranchProbability Prob)
Divide by a non-zero branch probability using saturating arithmetic.
BlockFrequency operator/(BranchProbability Prob) const
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:1252
BlockFrequency & operator+=(BlockFrequency Freq)
Adds another block frequency using saturating arithmetic.
BlockFrequency operator+(BlockFrequency Freq) const
BlockFrequency operator-(BlockFrequency Freq) const
BlockFrequency & operator-=(BlockFrequency Freq)
Subtracts another block frequency using saturating arithmetic.
BlockFrequency & operator*=(BranchProbability Prob)
Multiplies with a branch probability.
uint64_t scale(uint64_t Num) const
Scale a large integer.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BlockFrequency & operator>>=(const unsigned count)
Shift block frequency to the right by count digits saturating to 1.