Support: Extract ScaledNumbers::MinScale and MaxScale
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 24 Jun 2014 00:15:19 +0000 (00:15 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 24 Jun 2014 00:15:19 +0000 (00:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211558 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/BlockFrequencyInfoImpl.h
include/llvm/Support/ScaledNumber.h
lib/Analysis/BlockFrequencyInfoImpl.cpp

index 618b6e33663029d45af12e533cda0186caf5efa6..02ffbed83a00b9985b7278812a3617701d9153fd 100644 (file)
@@ -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<DigitsT>(N, Shift);
     return Adjusted;
   }
@@ -462,7 +461,7 @@ template <class DigitsT> void ScaledNumber<DigitsT>::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 <class DigitsT> void ScaledNumber<DigitsT>::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;
index a561def03758401ac46248e3e79e7ab582cdba62..b12f347806df8aedc21de441a0d88129cde437ba 100644 (file)
 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 <class DigitsT> inline int getWidth() { return sizeof(DigitsT) * 8; }
 
index fb3f7b9779784b1b604f6ea9e85d536ce4035a96..37ff0c3ccabf0c8cdd79cf731bf93bcf99402139 100644 (file)
@@ -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;
   }