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 BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
31 /// \brief Returns the maximum possible frequency, the saturation value.
32 static uint64_t getMaxFrequency() { return -1ULL; }
34 /// \brief Returns the frequency as a fixpoint number scaled by the entry
36 uint64_t getFrequency() const { return Frequency; }
38 /// \brief Multiplies with a branch probability. The computation will never
40 BlockFrequency &operator*=(const BranchProbability &Prob);
41 const BlockFrequency operator*(const BranchProbability &Prob) const;
43 /// \brief Divide by a non-zero branch probability using saturating
45 BlockFrequency &operator/=(const BranchProbability &Prob);
46 BlockFrequency operator/(const BranchProbability &Prob) const;
48 /// \brief Adds another block frequency using saturating arithmetic.
49 BlockFrequency &operator+=(const BlockFrequency &Freq);
50 const BlockFrequency operator+(const BlockFrequency &Freq) const;
52 /// \brief Shift block frequency to the right by count digits saturating to 1.
53 BlockFrequency &operator>>=(const unsigned count);
55 bool operator<(const BlockFrequency &RHS) const {
56 return Frequency < RHS.Frequency;
59 bool operator<=(const BlockFrequency &RHS) const {
60 return Frequency <= RHS.Frequency;
63 bool operator>(const BlockFrequency &RHS) const {
64 return Frequency > RHS.Frequency;
67 bool operator>=(const BlockFrequency &RHS) const {
68 return Frequency >= RHS.Frequency;