LLVM  10.0.0svn
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 
14 #include <cassert>
15 
16 using namespace llvm;
17 
19  Frequency = Prob.scale(Frequency);
20  return *this;
21 }
22 
24  BlockFrequency Freq(Frequency);
25  Freq *= Prob;
26  return Freq;
27 }
28 
30  Frequency = Prob.scaleByInverse(Frequency);
31  return *this;
32 }
33 
35  BlockFrequency Freq(Frequency);
36  Freq /= Prob;
37  return Freq;
38 }
39 
41  uint64_t Before = Freq.Frequency;
42  Frequency += Freq.Frequency;
43 
44  // If overflow, set frequency to the maximum value.
45  if (Frequency < Before)
46  Frequency = UINT64_MAX;
47 
48  return *this;
49 }
50 
52  BlockFrequency NewFreq(Frequency);
53  NewFreq += Freq;
54  return NewFreq;
55 }
56 
58  // If underflow, set frequency to 0.
59  if (Frequency <= Freq.Frequency)
60  Frequency = 0;
61  else
62  Frequency -= Freq.Frequency;
63  return *this;
64 }
65 
67  BlockFrequency NewFreq(Frequency);
68  NewFreq -= Freq;
69  return NewFreq;
70 }
71 
73  // Frequency can never be 0 by design.
74  assert(Frequency != 0);
75 
76  // Shift right by count.
77  Frequency >>= count;
78 
79  // Saturate to 1 if we are 0.
80  Frequency |= Frequency == 0;
81  return *this;
82 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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:1231
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.