blob: 4b468f7acb322f3a8a40f3c83277075db485444c [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-------- BlockFrequency.h - Block Frequency Wrapper --------*- 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#ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H
15#define LLVM_SUPPORT_BLOCKFREQUENCY_H
16
17#include "llvm/Support/BranchProbability.h"
18#include "llvm/Support/DataTypes.h"
19
20namespace llvm {
21
22class raw_ostream;
23
24// This class represents Block Frequency as a 64-bit value.
25class BlockFrequency {
26 uint64_t Frequency;
27
28public:
29 BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
30
Andrew Scullcdfcccc2018-10-05 20:58:37 +010031 /// Returns the maximum possible frequency, the saturation value.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010032 static uint64_t getMaxFrequency() { return -1ULL; }
33
Andrew Scullcdfcccc2018-10-05 20:58:37 +010034 /// Returns the frequency as a fixpoint number scaled by the entry
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010035 /// frequency.
36 uint64_t getFrequency() const { return Frequency; }
37
Andrew Scullcdfcccc2018-10-05 20:58:37 +010038 /// Multiplies with a branch probability. The computation will never
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010039 /// overflow.
40 BlockFrequency &operator*=(BranchProbability Prob);
41 BlockFrequency operator*(BranchProbability Prob) const;
42
Andrew Scullcdfcccc2018-10-05 20:58:37 +010043 /// Divide by a non-zero branch probability using saturating
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010044 /// arithmetic.
45 BlockFrequency &operator/=(BranchProbability Prob);
46 BlockFrequency operator/(BranchProbability Prob) const;
47
Andrew Scullcdfcccc2018-10-05 20:58:37 +010048 /// Adds another block frequency using saturating arithmetic.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010049 BlockFrequency &operator+=(BlockFrequency Freq);
50 BlockFrequency operator+(BlockFrequency Freq) const;
51
Andrew Scullcdfcccc2018-10-05 20:58:37 +010052 /// Subtracts another block frequency using saturating arithmetic.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010053 BlockFrequency &operator-=(BlockFrequency Freq);
54 BlockFrequency operator-(BlockFrequency Freq) const;
55
Andrew Scullcdfcccc2018-10-05 20:58:37 +010056 /// Shift block frequency to the right by count digits saturating to 1.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010057 BlockFrequency &operator>>=(const unsigned count);
58
59 bool operator<(BlockFrequency RHS) const {
60 return Frequency < RHS.Frequency;
61 }
62
63 bool operator<=(BlockFrequency RHS) const {
64 return Frequency <= RHS.Frequency;
65 }
66
67 bool operator>(BlockFrequency RHS) const {
68 return Frequency > RHS.Frequency;
69 }
70
71 bool operator>=(BlockFrequency RHS) const {
72 return Frequency >= RHS.Frequency;
73 }
74
75 bool operator==(BlockFrequency RHS) const {
76 return Frequency == RHS.Frequency;
77 }
78};
79
80}
81
82#endif