LLVM  6.0.0svn
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 
16 #include <cassert>
17 
18 using namespace llvm;
19 
21  Frequency = Prob.scale(Frequency);
22  return *this;
23 }
24 
26  BlockFrequency Freq(Frequency);
27  Freq *= Prob;
28  return Freq;
29 }
30 
32  Frequency = Prob.scaleByInverse(Frequency);
33  return *this;
34 }
35 
37  BlockFrequency Freq(Frequency);
38  Freq /= Prob;
39  return Freq;
40 }
41 
43  uint64_t Before = Freq.Frequency;
44  Frequency += Freq.Frequency;
45 
46  // If overflow, set frequency to the maximum value.
47  if (Frequency < Before)
48  Frequency = UINT64_MAX;
49 
50  return *this;
51 }
52 
54  BlockFrequency NewFreq(Frequency);
55  NewFreq += Freq;
56  return NewFreq;
57 }
58 
60  // If underflow, set frequency to 0.
61  if (Frequency <= Freq.Frequency)
62  Frequency = 0;
63  else
64  Frequency -= Freq.Frequency;
65  return *this;
66 }
67 
69  BlockFrequency NewFreq(Frequency);
70  NewFreq -= Freq;
71  return NewFreq;
72 }
73 
75  // Frequency can never be 0 by design.
76  assert(Frequency != 0);
77 
78  // Shift right by count.
79  Frequency >>= count;
80 
81  // Saturate to 1 if we are 0.
82  Frequency |= Frequency == 0;
83  return *this;
84 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
uint64_t scaleByInverse(uint64_t Num) const
Scale a large integer by the inverse.
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:874
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.