From: Duncan P. N. Exon Smith Date: Tue, 24 Jun 2014 00:15:19 +0000 (+0000) Subject: Support: Extract ScaledNumbers::MinScale and MaxScale X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=784bb5992ac36b693dbca9e9e5b03b76756dcdd9;p=oota-llvm.git Support: Extract ScaledNumbers::MinScale and MaxScale git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211558 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/include/llvm/Analysis/BlockFrequencyInfoImpl.h index 618b6e33663..02ffbed83a0 100644 --- a/include/llvm/Analysis/BlockFrequencyInfoImpl.h +++ b/include/llvm/Analysis/BlockFrequencyInfoImpl.h @@ -42,8 +42,6 @@ namespace llvm { class ScaledNumberBase { public: - static const int32_t MaxScale = 16383; - static const int32_t MinScale = -16382; static const int DefaultPrecision = 10; static void dump(uint64_t D, int16_t E, int Width); @@ -146,7 +144,7 @@ public: static ScaledNumber getZero() { return ScaledNumber(0, 0); } static ScaledNumber getOne() { return ScaledNumber(1, 0); } static ScaledNumber getLargest() { - return ScaledNumber(DigitsLimits::max(), MaxScale); + return ScaledNumber(DigitsLimits::max(), ScaledNumbers::MaxScale); } static ScaledNumber getFloat(uint64_t N) { return adjustToWidth(N, 0); } static ScaledNumber getInverseFloat(uint64_t N) { @@ -235,7 +233,7 @@ public: std::tie(Digits, Scale) = ScaledNumbers::getSum(Digits, Scale, X.Digits, X.Scale); // Check for exponent past MaxScale. - if (Scale > MaxScale) + if (Scale > ScaledNumbers::MaxScale) *this = getLargest(); return *this; } @@ -331,8 +329,9 @@ private: /// /// \pre Shift >= MinScale && Shift + 64 <= MaxScale. static ScaledNumber adjustToWidth(uint64_t N, int32_t Shift) { - assert(Shift >= MinScale && "Shift should be close to 0"); - assert(Shift <= MaxScale - 64 && "Shift should be close to 0"); + assert(Shift >= ScaledNumbers::MinScale && "Shift should be close to 0"); + assert(Shift <= ScaledNumbers::MaxScale - 64 && + "Shift should be close to 0"); auto Adjusted = ScaledNumbers::getAdjusted(N, Shift); return Adjusted; } @@ -462,7 +461,7 @@ template void ScaledNumber::shiftLeft(int32_t Shift) { } // Shift as much as we can in the exponent. - int32_t ScaleShift = std::min(Shift, MaxScale - Scale); + int32_t ScaleShift = std::min(Shift, ScaledNumbers::MaxScale - Scale); Scale += ScaleShift; if (ScaleShift == Shift) return; @@ -493,7 +492,7 @@ template void ScaledNumber::shiftRight(int32_t Shift) { } // Shift as much as we can in the exponent. - int32_t ScaleShift = std::min(Shift, Scale - MinScale); + int32_t ScaleShift = std::min(Shift, Scale - ScaledNumbers::MinScale); Scale -= ScaleShift; if (ScaleShift == Shift) return; diff --git a/include/llvm/Support/ScaledNumber.h b/include/llvm/Support/ScaledNumber.h index a561def0375..b12f347806d 100644 --- a/include/llvm/Support/ScaledNumber.h +++ b/include/llvm/Support/ScaledNumber.h @@ -32,6 +32,12 @@ namespace llvm { namespace ScaledNumbers { +/// \brief Maximum scale; same as APFloat for easy debug printing. +const int32_t MaxScale = 16383; + +/// \brief Maximum scale; same as APFloat for easy debug printing. +const int32_t MinScale = -16382; + /// \brief Get the width of a number. template inline int getWidth() { return sizeof(DigitsT) * 8; } diff --git a/lib/Analysis/BlockFrequencyInfoImpl.cpp b/lib/Analysis/BlockFrequencyInfoImpl.cpp index fb3f7b97797..37ff0c3ccab 100644 --- a/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ b/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -27,11 +27,6 @@ using namespace llvm::bfi_detail; // ScaledNumber implementation. // //===----------------------------------------------------------------------===// -#ifndef _MSC_VER -const int32_t ScaledNumberBase::MaxScale; -const int32_t ScaledNumberBase::MinScale; -#endif - static void appendDigit(std::string &Str, unsigned D) { assert(D < 10); Str += '0' + D % 10; @@ -58,22 +53,22 @@ static bool doesRoundUp(char Digit) { } static std::string toStringAPFloat(uint64_t D, int E, unsigned Precision) { - assert(E >= ScaledNumberBase::MinScale); - assert(E <= ScaledNumberBase::MaxScale); + assert(E >= ScaledNumbers::MinScale); + assert(E <= ScaledNumbers::MaxScale); // Find a new E, but don't let it increase past MaxScale. int LeadingZeros = ScaledNumberBase::countLeadingZeros64(D); - int NewE = std::min(ScaledNumberBase::MaxScale, E + 63 - LeadingZeros); + int NewE = std::min(ScaledNumbers::MaxScale, E + 63 - LeadingZeros); int Shift = 63 - (NewE - E); assert(Shift <= LeadingZeros); - assert(Shift == LeadingZeros || NewE == ScaledNumberBase::MaxScale); + assert(Shift == LeadingZeros || NewE == ScaledNumbers::MaxScale); D <<= Shift; E = NewE; // Check for a denormal. unsigned AdjustedE = E + 16383; if (!(D >> 63)) { - assert(E == ScaledNumberBase::MaxScale); + assert(E == ScaledNumbers::MaxScale); AdjustedE = 0; }