LLVM API Documentation
00001 //===-------- BlockFrequency.h - Block Frequency Wrapper --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements Block Frequency class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H 00015 #define LLVM_SUPPORT_BLOCKFREQUENCY_H 00016 00017 #include "llvm/Support/DataTypes.h" 00018 00019 namespace llvm { 00020 00021 class raw_ostream; 00022 class BranchProbability; 00023 00024 // This class represents Block Frequency as a 64-bit value. 00025 class BlockFrequency { 00026 uint64_t Frequency; 00027 00028 public: 00029 BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { } 00030 00031 /// \brief Returns the maximum possible frequency, the saturation value. 00032 static uint64_t getMaxFrequency() { return -1ULL; } 00033 00034 /// \brief Returns the frequency as a fixpoint number scaled by the entry 00035 /// frequency. 00036 uint64_t getFrequency() const { return Frequency; } 00037 00038 /// \brief Multiplies with a branch probability. The computation will never 00039 /// overflow. 00040 BlockFrequency &operator*=(const BranchProbability &Prob); 00041 const BlockFrequency operator*(const BranchProbability &Prob) const; 00042 00043 /// \brief Divide by a non-zero branch probability using saturating 00044 /// arithmetic. 00045 BlockFrequency &operator/=(const BranchProbability &Prob); 00046 BlockFrequency operator/(const BranchProbability &Prob) const; 00047 00048 /// \brief Adds another block frequency using saturating arithmetic. 00049 BlockFrequency &operator+=(const BlockFrequency &Freq); 00050 const BlockFrequency operator+(const BlockFrequency &Freq) const; 00051 00052 /// \brief Shift block frequency to the right by count digits saturating to 1. 00053 BlockFrequency &operator>>=(const unsigned count); 00054 00055 bool operator<(const BlockFrequency &RHS) const { 00056 return Frequency < RHS.Frequency; 00057 } 00058 00059 bool operator<=(const BlockFrequency &RHS) const { 00060 return Frequency <= RHS.Frequency; 00061 } 00062 00063 bool operator>(const BlockFrequency &RHS) const { 00064 return Frequency > RHS.Frequency; 00065 } 00066 00067 bool operator>=(const BlockFrequency &RHS) const { 00068 return Frequency >= RHS.Frequency; 00069 } 00070 }; 00071 00072 } 00073 00074 #endif