1 //===-------- BlockFrequency.h - Block Frequency Wrapper --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements Block Frequency class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H
15 #define LLVM_SUPPORT_BLOCKFREQUENCY_H
17 #include "llvm/Support/DataTypes.h"
22 class BranchProbability;
24 // This class represents Block Frequency as a 64-bit value.
25 class BlockFrequency {
29 /// \brief Scale the given BlockFrequency by N/D. Return the remainder from
30 /// the division by D. Upon overflow, the routine will saturate and
31 /// additionally will return the remainder set to D.
32 uint32_t scale(uint32_t N, uint32_t D);
35 BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
37 /// \brief Returns the maximum possible frequency, the saturation value.
38 static uint64_t getMaxFrequency() { return -1ULL; }
40 /// \brief Returns the frequency as a fixpoint number scaled by the entry
42 uint64_t getFrequency() const { return Frequency; }
44 /// \brief Multiplies with a branch probability. The computation will never
46 BlockFrequency &operator*=(const BranchProbability &Prob);
47 const BlockFrequency operator*(const BranchProbability &Prob) const;
49 /// \brief Divide by a non-zero branch probability using saturating
51 BlockFrequency &operator/=(const BranchProbability &Prob);
52 BlockFrequency operator/(const BranchProbability &Prob) const;
54 /// \brief Adds another block frequency using saturating arithmetic.
55 BlockFrequency &operator+=(const BlockFrequency &Freq);
56 const BlockFrequency operator+(const BlockFrequency &Freq) const;
58 /// \brief Shift block frequency to the right by count digits saturating to 1.
59 BlockFrequency &operator>>=(const unsigned count);
61 /// \brief Scale the given BlockFrequency by N/D. Return the remainder from
62 /// the division by D. Upon overflow, the routine will saturate.
63 uint32_t scale(const BranchProbability &Prob);
65 bool operator<(const BlockFrequency &RHS) const {
66 return Frequency < RHS.Frequency;
69 bool operator<=(const BlockFrequency &RHS) const {
70 return Frequency <= RHS.Frequency;
73 bool operator>(const BlockFrequency &RHS) const {
74 return Frequency > RHS.Frequency;
77 bool operator>=(const BlockFrequency &RHS) const {
78 return Frequency >= RHS.Frequency;