For PR950:
authorReid Spencer <rspencer@reidspencer.com>
Wed, 6 Dec 2006 20:30:17 +0000 (20:30 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Wed, 6 Dec 2006 20:30:17 +0000 (20:30 +0000)
Remove the getMaxValue and getMinValue functions from ConstantIntegral.
They don't make sense for a signless type. Also, for isMaxValue and
isMinValue, have the caller provided the signedness rather than obtaining
it from the constant's type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32287 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constants.h
lib/VMCore/Constants.cpp

index b4db582ea63fe132d3624a4bbe3909c08ccd3cc0..8c31ba327591ae1ff5764678b715e4fdf23e065b 100644 (file)
@@ -75,14 +75,14 @@ public:
   /// constant's type.
   /// @returns true if the constant's value is maximal.
   /// @brief Determine if the value is maximal.
-  virtual bool isMaxValue() const = 0;
+  virtual bool isMaxValue(bool isSigned) const = 0;
 
   /// This function is implemented by subclasses and will return true iff this 
   /// constant represents the smallest value that may be represented by this 
   /// constant's type.
   /// @returns true if the constant's value is minimal
   /// @brief Determine if the value is minimal.
-  virtual bool isMinValue() const = 0;
+  virtual bool isMinValue(bool isSigned) const = 0;
 
   /// This function is implemented by subclasses and will return true iff every
   /// bit in this constant is set to true.
@@ -90,14 +90,6 @@ public:
   /// @brief Determine if the value is all ones.
   virtual bool isAllOnesValue() const = 0;
 
-  /// @returns the largest value for an integer constant of the given type 
-  /// @brief Get the maximal value
-  static ConstantIntegral *getMaxValue(const Type *Ty);
-
-  /// @returns the smallest value for an integer constant of the given type 
-  /// @brief Get the minimal value
-  static ConstantIntegral *getMinValue(const Type *Ty);
-
   /// @returns the value for an integer constant of the given type that has all
   /// its bits set to true.
   /// @brief Get the all ones value
@@ -147,8 +139,8 @@ public:
   /// @see ConstantIntegral for details
   /// @brief Implement overrides
   virtual bool isNullValue() const { return getValue() == false; }
-  virtual bool isMaxValue() const { return getValue() == true; }
-  virtual bool isMinValue() const { return getValue() == false; }
+  virtual bool isMaxValue(bool isSigned) const { return getValue() == true; }
+  virtual bool isMinValue(bool isSigned) const { return getValue() == false; }
   virtual bool isAllOnesValue() const { return getValue() == true; }
 
   /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
@@ -208,8 +200,8 @@ public:
   /// by this type.
   /// @see ConstantIntegeral
   /// @brief Override implementation
-  virtual bool isMaxValue() const {
-    if (getType()->isSigned()) {
+  virtual bool isMaxValue(bool isSigned) const {
+    if (isSigned) {
       int64_t V = getSExtValue();
       if (V < 0) return false;    // Be careful about wrap-around on 'long's
       ++V;
@@ -222,8 +214,8 @@ public:
   /// this type.
   /// @see ConstantIntegral
   /// @brief Override implementation
-  virtual bool isMinValue() const {
-    if (getType()->isSigned()) {
+  virtual bool isMinValue(bool isSigned) const {
+    if (isSigned) {
       int64_t V = getSExtValue();
       if (V > 0) return false;    // Be careful about wrap-around on 'long's
       --V;
index f52504298e196143f0c25952f207e2abd9fb5067..f9271178a4d139a6a896d6a465db7e8e492d3f58 100644 (file)
@@ -152,53 +152,6 @@ Constant *Constant::getNullValue(const Type *Ty) {
   }
 }
 
-// Static constructor to create the maximum constant of an integral type...
-ConstantIntegral *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 getAllOnesValue(Ty);
-
-  default: return 0;
-  }
-}
-
-// Static constructor to create the minimum constant for an integral type...
-ConstantIntegral *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 constructor to create an integral constant with all bits set
 ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {