LLVM  3.7.0
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 
17 #include <cassert>
18 
19 using namespace llvm;
20 
22  Frequency = Prob.scale(Frequency);
23  return *this;
24 }
25 
26 const BlockFrequency
28  BlockFrequency Freq(Frequency);
29  Freq *= Prob;
30  return Freq;
31 }
32 
34  Frequency = Prob.scaleByInverse(Frequency);
35  return *this;
36 }
37 
39  BlockFrequency Freq(Frequency);
40  Freq /= Prob;
41  return Freq;
42 }
43 
45  uint64_t Before = Freq.Frequency;
46  Frequency += Freq.Frequency;
47 
48  // If overflow, set frequency to the maximum value.
49  if (Frequency < Before)
50  Frequency = UINT64_MAX;
51 
52  return *this;
53 }
54 
55 const BlockFrequency
57  BlockFrequency Freq(Frequency);
58  Freq += Prob;
59  return Freq;
60 }
61 
63  // Frequency can never be 0 by design.
64  assert(Frequency != 0);
65 
66  // Shift right by count.
67  Frequency >>= count;
68 
69  // Saturate to 1 if we are 0.
70  Frequency |= Frequency == 0;
71  return *this;
72 }
BlockFrequency & operator+=(const BlockFrequency &Freq)
Adds another block frequency using saturating arithmetic.
BlockFrequency & operator/=(const 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.
const BlockFrequency operator+(const BlockFrequency &Freq) const
const BlockFrequency operator*(const BranchProbability &Prob) const
BlockFrequency & operator*=(const BranchProbability &Prob)
Multiplies with a branch probability.
BlockFrequency operator/(const BranchProbability &Prob) const
uint64_t scale(uint64_t Num) const
Scale a large integer.
BlockFrequency & operator>>=(const unsigned count)
Shift block frequency to the right by count digits saturating to 1.