Adjust to new ConstantIntegral interface for Max/Min tests.
authorReid Spencer <rspencer@reidspencer.com>
Wed, 6 Dec 2006 20:45:15 +0000 (20:45 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Wed, 6 Dec 2006 20:45:15 +0000 (20:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32289 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantRange.cpp
lib/Support/ConstantRange.cpp
lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index 309edb3f50bf0fac7d59495cbae0ac2a0d7de610..1f1a1b5757fa9c66c77fbe17dbf27963855a3e02 100644 (file)
 #include <ostream>
 using namespace llvm;
 
+static ConstantIntegral *getMaxValue(const Type *Ty) {
+  switch (Ty->getTypeID()) {
+  case Type::BoolTyID:   return ConstantBool::getTrue();
+  case Type::SByteTyID:
+  case Type::ShortTyID:
+  case Type::IntTyID:
+  case Type::LongTyID: {
+    // Calculate 011111111111111...
+    unsigned TypeBits = Ty->getPrimitiveSize()*8;
+    int64_t Val = INT64_MAX;             // All ones
+    Val >>= 64-TypeBits;                 // Shift out unwanted 1 bits...
+    return ConstantInt::get(Ty, Val);
+  }
+
+  case Type::UByteTyID:
+  case Type::UShortTyID:
+  case Type::UIntTyID:
+  case Type::ULongTyID:  return ConstantInt::getAllOnesValue(Ty);
+
+  default: return 0;
+  }
+}
+
+// Static constructor to create the minimum constant for an integral type...
+static ConstantIntegral *getMinValue(const Type *Ty) {
+  switch (Ty->getTypeID()) {
+  case Type::BoolTyID:   return ConstantBool::getFalse();
+  case Type::SByteTyID:
+  case Type::ShortTyID:
+  case Type::IntTyID:
+  case Type::LongTyID: {
+     // Calculate 1111111111000000000000
+     unsigned TypeBits = Ty->getPrimitiveSize()*8;
+     int64_t Val = -1;                    // All ones
+     Val <<= TypeBits-1;                  // Shift over to the right spot
+     return ConstantInt::get(Ty, Val);
+  }
+
+  case Type::UByteTyID:
+  case Type::UShortTyID:
+  case Type::UIntTyID:
+  case Type::ULongTyID:  return ConstantInt::get(Ty, 0);
+
+  default: return 0;
+  }
+}
 static ConstantIntegral *Next(ConstantIntegral *CI) {
   if (ConstantBool *CB = dyn_cast<ConstantBool>(CI))
     return ConstantBool::get(!CB->getValue());
@@ -65,9 +111,9 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) {
   assert(Ty->isIntegral() &&
          "Cannot make constant range of non-integral type!");
   if (Full)
-    Lower = Upper = ConstantIntegral::getMaxValue(Ty);
+    Lower = Upper = getMaxValue(Ty);
   else
-    Lower = Upper = ConstantIntegral::getMinValue(Ty);
+    Lower = Upper = getMinValue(Ty);
 }
 
 /// Initialize a range to hold the single specified value.
@@ -86,8 +132,8 @@ ConstantRange::ConstantRange(Constant *L, Constant *U)
          "Incompatible types for ConstantRange!");
 
   // Make sure that if L & U are equal that they are either Min or Max...
-  assert((L != U || (L == ConstantIntegral::getMaxValue(L->getType()) ||
-                     L == ConstantIntegral::getMinValue(L->getType()))) &&
+  assert((L != U || (L == getMaxValue(L->getType()) ||
+                     L == getMinValue(L->getType()))) &&
          "Lower == Upper, but they aren't min or max for type!");
 }
 
@@ -99,20 +145,20 @@ ConstantRange::ConstantRange(unsigned SetCCOpcode, ConstantIntegral *C) {
   case Instruction::SetEQ: Lower = C; Upper = Next(C); return;
   case Instruction::SetNE: Upper = C; Lower = Next(C); return;
   case Instruction::SetLT:
-    Lower = ConstantIntegral::getMinValue(C->getType());
+    Lower = getMinValue(C->getType());
     Upper = C;
     return;
   case Instruction::SetGT:
     Lower = Next(C);
-    Upper = ConstantIntegral::getMinValue(C->getType());  // Min = Next(Max)
+    Upper = getMinValue(C->getType());  // Min = Next(Max)
     return;
   case Instruction::SetLE:
-    Lower = ConstantIntegral::getMinValue(C->getType());
+    Lower = getMinValue(C->getType());
     Upper = Next(C);
     return;
   case Instruction::SetGE:
     Lower = C;
-    Upper = ConstantIntegral::getMinValue(C->getType());  // Min = Next(Max)
+    Upper = getMinValue(C->getType());  // Min = Next(Max)
     return;
   }
 }
@@ -124,13 +170,13 @@ const Type *ConstantRange::getType() const { return Lower->getType(); }
 /// isFullSet - Return true if this set contains all of the elements possible
 /// for this data-type
 bool ConstantRange::isFullSet() const {
-  return Lower == Upper && Lower == ConstantIntegral::getMaxValue(getType());
+  return Lower == Upper && Lower == getMaxValue(getType());
 }
 
 /// isEmptySet - Return true if this set contains no members.
 ///
 bool ConstantRange::isEmptySet() const {
-  return Lower == Upper && Lower == ConstantIntegral::getMinValue(getType());
+  return Lower == Upper && Lower == getMinValue(getType());
 }
 
 /// isWrappedSet - Return true if this set wraps around the top of the range,
index 309edb3f50bf0fac7d59495cbae0ac2a0d7de610..1f1a1b5757fa9c66c77fbe17dbf27963855a3e02 100644 (file)
 #include <ostream>
 using namespace llvm;
 
+static ConstantIntegral *getMaxValue(const Type *Ty) {
+  switch (Ty->getTypeID()) {
+  case Type::BoolTyID:   return ConstantBool::getTrue();
+  case Type::SByteTyID:
+  case Type::ShortTyID:
+  case Type::IntTyID:
+  case Type::LongTyID: {
+    // Calculate 011111111111111...
+    unsigned TypeBits = Ty->getPrimitiveSize()*8;
+    int64_t Val = INT64_MAX;             // All ones
+    Val >>= 64-TypeBits;                 // Shift out unwanted 1 bits...
+    return ConstantInt::get(Ty, Val);
+  }
+
+  case Type::UByteTyID:
+  case Type::UShortTyID:
+  case Type::UIntTyID:
+  case Type::ULongTyID:  return ConstantInt::getAllOnesValue(Ty);
+
+  default: return 0;
+  }
+}
+
+// Static constructor to create the minimum constant for an integral type...
+static ConstantIntegral *getMinValue(const Type *Ty) {
+  switch (Ty->getTypeID()) {
+  case Type::BoolTyID:   return ConstantBool::getFalse();
+  case Type::SByteTyID:
+  case Type::ShortTyID:
+  case Type::IntTyID:
+  case Type::LongTyID: {
+     // Calculate 1111111111000000000000
+     unsigned TypeBits = Ty->getPrimitiveSize()*8;
+     int64_t Val = -1;                    // All ones
+     Val <<= TypeBits-1;                  // Shift over to the right spot
+     return ConstantInt::get(Ty, Val);
+  }
+
+  case Type::UByteTyID:
+  case Type::UShortTyID:
+  case Type::UIntTyID:
+  case Type::ULongTyID:  return ConstantInt::get(Ty, 0);
+
+  default: return 0;
+  }
+}
 static ConstantIntegral *Next(ConstantIntegral *CI) {
   if (ConstantBool *CB = dyn_cast<ConstantBool>(CI))
     return ConstantBool::get(!CB->getValue());
@@ -65,9 +111,9 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) {
   assert(Ty->isIntegral() &&
          "Cannot make constant range of non-integral type!");
   if (Full)
-    Lower = Upper = ConstantIntegral::getMaxValue(Ty);
+    Lower = Upper = getMaxValue(Ty);
   else
-    Lower = Upper = ConstantIntegral::getMinValue(Ty);
+    Lower = Upper = getMinValue(Ty);
 }
 
 /// Initialize a range to hold the single specified value.
@@ -86,8 +132,8 @@ ConstantRange::ConstantRange(Constant *L, Constant *U)
          "Incompatible types for ConstantRange!");
 
   // Make sure that if L & U are equal that they are either Min or Max...
-  assert((L != U || (L == ConstantIntegral::getMaxValue(L->getType()) ||
-                     L == ConstantIntegral::getMinValue(L->getType()))) &&
+  assert((L != U || (L == getMaxValue(L->getType()) ||
+                     L == getMinValue(L->getType()))) &&
          "Lower == Upper, but they aren't min or max for type!");
 }
 
@@ -99,20 +145,20 @@ ConstantRange::ConstantRange(unsigned SetCCOpcode, ConstantIntegral *C) {
   case Instruction::SetEQ: Lower = C; Upper = Next(C); return;
   case Instruction::SetNE: Upper = C; Lower = Next(C); return;
   case Instruction::SetLT:
-    Lower = ConstantIntegral::getMinValue(C->getType());
+    Lower = getMinValue(C->getType());
     Upper = C;
     return;
   case Instruction::SetGT:
     Lower = Next(C);
-    Upper = ConstantIntegral::getMinValue(C->getType());  // Min = Next(Max)
+    Upper = getMinValue(C->getType());  // Min = Next(Max)
     return;
   case Instruction::SetLE:
-    Lower = ConstantIntegral::getMinValue(C->getType());
+    Lower = getMinValue(C->getType());
     Upper = Next(C);
     return;
   case Instruction::SetGE:
     Lower = C;
-    Upper = ConstantIntegral::getMinValue(C->getType());  // Min = Next(Max)
+    Upper = getMinValue(C->getType());  // Min = Next(Max)
     return;
   }
 }
@@ -124,13 +170,13 @@ const Type *ConstantRange::getType() const { return Lower->getType(); }
 /// isFullSet - Return true if this set contains all of the elements possible
 /// for this data-type
 bool ConstantRange::isFullSet() const {
-  return Lower == Upper && Lower == ConstantIntegral::getMaxValue(getType());
+  return Lower == Upper && Lower == getMaxValue(getType());
 }
 
 /// isEmptySet - Return true if this set contains no members.
 ///
 bool ConstantRange::isEmptySet() const {
-  return Lower == Upper && Lower == ConstantIntegral::getMinValue(getType());
+  return Lower == Upper && Lower == getMinValue(getType());
 }
 
 /// isWrappedSet - Return true if this set wraps around the top of the range,
index 6d83aeb85db6e27fcef350b37cd9155e877e1c76..53adc49f8e94ebe10a6274d1e43eee42ff72a0cd 100644 (file)
@@ -753,7 +753,7 @@ void CWriter::printConstant(Constant *CPV) {
     break;
 
   case Type::LongTyID:
-    if (cast<ConstantInt>(CPV)->isMinValue())
+    if (cast<ConstantInt>(CPV)->isMinValue(CPV->getType()->isSigned()))
       Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
     else
       Out << cast<ConstantInt>(CPV)->getSExtValue() << "ll";
index 6d83aeb85db6e27fcef350b37cd9155e877e1c76..53adc49f8e94ebe10a6274d1e43eee42ff72a0cd 100644 (file)
@@ -753,7 +753,7 @@ void CWriter::printConstant(Constant *CPV) {
     break;
 
   case Type::LongTyID:
-    if (cast<ConstantInt>(CPV)->isMinValue())
+    if (cast<ConstantInt>(CPV)->isMinValue(CPV->getType()->isSigned()))
       Out << "(/*INT64_MIN*/(-9223372036854775807LL)-1)";
     else
       Out << cast<ConstantInt>(CPV)->getSExtValue() << "ll";