Line data Source code
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 :
14 : #include "llvm/Support/BlockFrequency.h"
15 : #include <cassert>
16 :
17 : using namespace llvm;
18 :
19 649802 : BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
20 649802 : Frequency = Prob.scale(Frequency);
21 649802 : return *this;
22 : }
23 :
24 616244 : BlockFrequency BlockFrequency::operator*(BranchProbability Prob) const {
25 616244 : BlockFrequency Freq(Frequency);
26 616244 : Freq *= Prob;
27 616244 : return Freq;
28 : }
29 :
30 3180 : BlockFrequency &BlockFrequency::operator/=(BranchProbability Prob) {
31 3180 : Frequency = Prob.scaleByInverse(Frequency);
32 3180 : return *this;
33 : }
34 :
35 3151 : BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
36 3151 : BlockFrequency Freq(Frequency);
37 3151 : Freq /= Prob;
38 3151 : return Freq;
39 : }
40 :
41 19562988 : BlockFrequency &BlockFrequency::operator+=(BlockFrequency Freq) {
42 : uint64_t Before = Freq.Frequency;
43 19562988 : Frequency += Freq.Frequency;
44 :
45 : // If overflow, set frequency to the maximum value.
46 19562988 : if (Frequency < Before)
47 102308 : Frequency = UINT64_MAX;
48 :
49 19562988 : return *this;
50 : }
51 :
52 8668233 : BlockFrequency BlockFrequency::operator+(BlockFrequency Freq) const {
53 8668233 : BlockFrequency NewFreq(Frequency);
54 8668233 : NewFreq += Freq;
55 8668233 : return NewFreq;
56 : }
57 :
58 4550 : BlockFrequency &BlockFrequency::operator-=(BlockFrequency Freq) {
59 : // If underflow, set frequency to 0.
60 4550 : if (Frequency <= Freq.Frequency)
61 2030 : Frequency = 0;
62 : else
63 2520 : Frequency -= Freq.Frequency;
64 4550 : return *this;
65 : }
66 :
67 4550 : BlockFrequency BlockFrequency::operator-(BlockFrequency Freq) const {
68 4550 : BlockFrequency NewFreq(Frequency);
69 4550 : NewFreq -= Freq;
70 4550 : return NewFreq;
71 : }
72 :
73 2 : BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
74 : // Frequency can never be 0 by design.
75 : assert(Frequency != 0);
76 :
77 : // Shift right by count.
78 2 : Frequency >>= count;
79 :
80 : // Saturate to 1 if we are 0.
81 2 : Frequency |= Frequency == 0;
82 2 : return *this;
83 : }
|