diff --git a/llvm/include/llvm/Support/BlockFrequency.h b/llvm/include/llvm/Support/BlockFrequency.h --- a/llvm/include/llvm/Support/BlockFrequency.h +++ b/llvm/include/llvm/Support/BlockFrequency.h @@ -13,6 +13,7 @@ #ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H #define LLVM_SUPPORT_BLOCKFREQUENCY_H +#include #include namespace llvm { @@ -44,15 +45,49 @@ BlockFrequency operator/(BranchProbability Prob) const; /// Adds another block frequency using saturating arithmetic. - BlockFrequency &operator+=(BlockFrequency Freq); - BlockFrequency operator+(BlockFrequency Freq) const; + BlockFrequency &operator+=(BlockFrequency Freq) { + uint64_t Before = Freq.Frequency; + Frequency += Freq.Frequency; + + // If overflow, set frequency to the maximum value. + if (Frequency < Before) + Frequency = UINT64_MAX; + + return *this; + } + BlockFrequency operator+(BlockFrequency Freq) const { + BlockFrequency NewFreq(Frequency); + NewFreq += Freq; + return NewFreq; + } /// Subtracts another block frequency using saturating arithmetic. - BlockFrequency &operator-=(BlockFrequency Freq); - BlockFrequency operator-(BlockFrequency Freq) const; + BlockFrequency &operator-=(BlockFrequency Freq) { + // If underflow, set frequency to 0. + if (Frequency <= Freq.Frequency) + Frequency = 0; + else + Frequency -= Freq.Frequency; + return *this; + } + BlockFrequency operator-(BlockFrequency Freq) const { + BlockFrequency NewFreq(Frequency); + NewFreq -= Freq; + return NewFreq; + } /// Shift block frequency to the right by count digits saturating to 1. - BlockFrequency &operator>>=(const unsigned count); + BlockFrequency &operator>>=(const unsigned count) { + // Frequency can never be 0 by design. + assert(Frequency != 0); + + // Shift right by count. + Frequency >>= count; + + // Saturate to 1 if we are 0. + Frequency |= Frequency == 0; + return *this; + } bool operator<(BlockFrequency RHS) const { return Frequency < RHS.Frequency; diff --git a/llvm/lib/Support/BlockFrequency.cpp b/llvm/lib/Support/BlockFrequency.cpp --- a/llvm/lib/Support/BlockFrequency.cpp +++ b/llvm/lib/Support/BlockFrequency.cpp @@ -12,7 +12,6 @@ #include "llvm/Support/BlockFrequency.h" #include "llvm/Support/BranchProbability.h" -#include using namespace llvm; @@ -37,47 +36,3 @@ Freq /= Prob; return Freq; } - -BlockFrequency &BlockFrequency::operator+=(BlockFrequency Freq) { - uint64_t Before = Freq.Frequency; - Frequency += Freq.Frequency; - - // If overflow, set frequency to the maximum value. - if (Frequency < Before) - Frequency = UINT64_MAX; - - return *this; -} - -BlockFrequency BlockFrequency::operator+(BlockFrequency Freq) const { - BlockFrequency NewFreq(Frequency); - NewFreq += Freq; - return NewFreq; -} - -BlockFrequency &BlockFrequency::operator-=(BlockFrequency Freq) { - // If underflow, set frequency to 0. - if (Frequency <= Freq.Frequency) - Frequency = 0; - else - Frequency -= Freq.Frequency; - return *this; -} - -BlockFrequency BlockFrequency::operator-(BlockFrequency Freq) const { - BlockFrequency NewFreq(Frequency); - NewFreq -= Freq; - return NewFreq; -} - -BlockFrequency &BlockFrequency::operator>>=(const unsigned count) { - // Frequency can never be 0 by design. - assert(Frequency != 0); - - // Shift right by count. - Frequency >>= count; - - // Saturate to 1 if we are 0. - Frequency |= Frequency == 0; - return *this; -}