[llvm-commits] [SignlessTypes] CVS: llvm/include/llvm/Constants.h Value.h

Reid Spencer reid at x10sys.com
Wed Oct 18 20:58:57 PDT 2006



Changes in directory llvm/include/llvm:

Constants.h updated: 1.88 -> 1.88.2.1
Value.h updated: 1.84 -> 1.84.4.1
---
Log message:

For PR950: http://llvm.org/PR950 :
This commit (on SignlessTypes branch) provides the first Iteration for 
moving LLVM away from Signed types. This patch removes the ConstantSInt
and ConstantUInt classes from Type.h and makes all necessary changes in
LLVM to compensate.


---
Diffs of the changes:  (+44 -98)

 Constants.h |  139 ++++++++++++++++++------------------------------------------
 Value.h     |    3 -
 2 files changed, 44 insertions(+), 98 deletions(-)


Index: llvm/include/llvm/Constants.h
diff -u llvm/include/llvm/Constants.h:1.88 llvm/include/llvm/Constants.h:1.88.2.1
--- llvm/include/llvm/Constants.h:1.88	Thu Sep 28 18:36:21 2006
+++ llvm/include/llvm/Constants.h	Wed Oct 18 22:57:55 2006
@@ -46,6 +46,7 @@
     uint64_t Unsigned;
   } Val;
   ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
+  ConstantIntegral(const Type *Ty, ValueTy VT, int64_t V);
 public:
 
   /// @brief Return the raw value of the constant as a 64-bit integer value.
@@ -111,8 +112,7 @@
   static inline bool classof(const ConstantIntegral *) { return true; }
   static bool classof(const Value *V) {
     return V->getValueType() == ConstantBoolVal ||
-           V->getValueType() == ConstantSIntVal ||
-           V->getValueType() == ConstantUIntVal;
+           V->getValueType() == ConstantIntVal;
   }
 };
 
@@ -165,13 +165,15 @@
 
 
 //===----------------------------------------------------------------------===//
-/// This is the abstract superclass of ConstantSInt & ConstantUInt, to make 
-/// dealing with integral constants easier when sign is irrelevant.
-/// @brief Abstract clas for constant integers.
+/// This is concrete integer subclass of ConstantIntegral that represents 
+/// both signed and unsigned integral constants, other than boolean.
+/// @brief Class for constant integers.
 class ConstantInt : public ConstantIntegral {
 protected:
   ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
-  ConstantInt(const Type *Ty, ValueTy VT, uint64_t V);
+  ConstantInt(const Type *Ty, uint64_t V);
+  ConstantInt(const Type *Ty, int64_t V);
+  friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
 public:
   /// A helper method that can be used to determine if the constant contained 
   /// within is equal to a constant.  This only works for very small values, 
@@ -184,44 +186,18 @@
   }
 
   /// Return a ConstantInt with the specified value for the specified type. 
-  /// This only works for very small values, because this is all that can be 
-  /// represented with all types integer types.
+  /// Overloads for ll the integer types are provided to ensure that implicit
+  /// conversions don't bite us and to get around compiler errors where the 
+  /// compiler can't find a suitable overload for a given integer value.
   /// @brief Get a ConstantInt for a specific value.
-  static ConstantInt *get(const Type *Ty, unsigned char V);
-
-  /// @returns true if this is the null integer value.
-  /// @see ConstantIntegral for details
-  /// @brief Implement override.
-  virtual bool isNullValue() const { return Val.Unsigned == 0; }
-
-  /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
-  static inline bool classof(const ConstantInt *) { return true; }
-  static bool classof(const Value *V) {
-    return V->getValueType() == ConstantSIntVal ||
-           V->getValueType() == ConstantUIntVal;
-  }
-};
-
-
-//===----------------------------------------------------------------------===//
-/// A concrete class to represent constant signed integer values for the types
-/// sbyte, short, int, and long.
-/// @brief Constant Signed Integer Class.
-class ConstantSInt : public ConstantInt {
-  ConstantSInt(const ConstantSInt &);      // DO NOT IMPLEMENT
-  friend struct ConstantCreator<ConstantSInt, Type, int64_t>;
-
-protected:
-  ConstantSInt(const Type *Ty, int64_t V);
-public:
-  /// This static factory methods returns objects of the specified value. Note
-  /// that repeated calls with the same operands return the same object.
-  /// @returns A ConstantSInt instant for the type and value requested.
-  /// @brief Get a signed integer constant.
-  static ConstantSInt *get(
-    const Type *Ty,  ///< The type of constant (SByteTy, IntTy, ShortTy, LongTy)
-    int64_t V        ///< The value for the constant integer.
-  );
+  static ConstantInt *get(const Type *Ty, int8_t V);
+  static ConstantInt *get(const Type *Ty, uint8_t V);
+  static ConstantInt *get(const Type *Ty, int16_t V);
+  static ConstantInt *get(const Type *Ty, uint16_t V);
+  static ConstantInt *get(const Type *Ty, int32_t V);
+  static ConstantInt *get(const Type *Ty, uint32_t V);
+  static ConstantInt *get(const Type *Ty, uint64_t V);
+  static ConstantInt *get(const Type *Ty, int64_t V);
 
   /// This static method returns true if the type Ty is big enough to 
   /// represent the value V. This can be used to avoid having the get method 
@@ -229,25 +205,30 @@
   /// @returns true if V is a valid value for type Ty
   /// @brief Determine if the value is in range for the given type.
   static bool isValueValidForType(const Type *Ty, int64_t V);
+  static bool isValueValidForType(const Type *Ty, uint64_t V);
 
-  /// @returns the underlying value of this constant.
-  /// @brief Get the constant value.
-  inline int64_t getValue() const { return Val.Signed; }
+  /// @returns true if this is the null integer value.
+  /// @see ConstantIntegral for details
+  /// @brief Implement override.
+  virtual bool isNullValue() const { return Val.Unsigned == 0; }
 
   /// @returns true iff this constant's bits are all set to true.
   /// @see ConstantIntegral
   /// @brief Override implementation
-  virtual bool isAllOnesValue() const { return getValue() == -1; }
+  virtual bool isAllOnesValue() const { return getSExtValue() == -1; }
 
   /// @returns true iff this is the largest value that may be represented 
   /// by this type.
   /// @see ConstantIntegeral
   /// @brief Override implementation
   virtual bool isMaxValue() const {
-    int64_t V = getValue();
-    if (V < 0) return false;    // Be careful about wrap-around on 'long's
-    ++V;
-    return !isValueValidForType(getType(), V) || V < 0;
+    if (getType()->isSigned()) {
+      int64_t V = getSExtValue();
+      if (V < 0) return false;    // Be careful about wrap-around on 'long's
+      ++V;
+      return !isValueValidForType(getType(), V) || V < 0;
+    }
+    return isAllOnesValue();
   }
 
   /// @returns true if this is the smallest value that may be represented by 
@@ -255,52 +236,19 @@
   /// @see ConstantIntegral
   /// @brief Override implementation
   virtual bool isMinValue() const {
-    int64_t V = getValue();
-    if (V > 0) return false;    // Be careful about wrap-around on 'long's
-    --V;
-    return !isValueValidForType(getType(), V) || V > 0;
+    if (getType()->isSigned()) {
+      int64_t V = getSExtValue();
+      if (V > 0) return false;    // Be careful about wrap-around on 'long's
+      --V;
+      return !isValueValidForType(getType(), V) || V > 0;
+    }
+    return getZExtValue() == 0;
   }
 
-  /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
-  static inline bool classof(const ConstantSInt *) { return true; }
-  static bool classof(const Value *V) {
-    return V->getValueType() == ConstantSIntVal;
-  }
-};
-
-//===----------------------------------------------------------------------===//
-/// A concrete class that represents constant unsigned integer values of type
-/// Type::UByteTy, Type::UShortTy, Type::UIntTy, or Type::ULongTy.
-/// @brief Constant Unsigned Integer Class
-class ConstantUInt : public ConstantInt {
-  ConstantUInt(const ConstantUInt &);      // DO NOT IMPLEMENT
-  friend struct ConstantCreator<ConstantUInt, Type, uint64_t>;
-protected:
-  ConstantUInt(const Type *Ty, uint64_t V);
-public:
-  /// get() - Static factory methods - Return objects of the specified value
-  ///
-  static ConstantUInt *get(const Type *Ty, uint64_t V);
-
-  /// isValueValidForType - return true if Ty is big enough to represent V.
-  ///
-  static bool isValueValidForType(const Type *Ty, uint64_t V);
-
-  /// getValue - return the underlying value of this constant.
-  ///
-  inline uint64_t getValue() const { return Val.Unsigned; }
-
-  /// isMaxValue - Return true if this is the largest value that may be
-  /// represented by this type.
-  ///
-  virtual bool isAllOnesValue() const;
-  virtual bool isMaxValue() const { return isAllOnesValue(); }
-  virtual bool isMinValue() const { return getValue() == 0; }
-
-  /// Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool classof(const ConstantUInt *) { return true; }
+  /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
+  static inline bool classof(const ConstantInt *) { return true; }
   static bool classof(const Value *V) {
-    return V->getValueType() == ConstantUIntVal;
+    return V->getValueType() == ConstantIntVal;
   }
 };
 
@@ -591,8 +539,7 @@
   }
 
   /// getSizeOf constant expr - computes the size of a type in a target
-  /// independent way (Note: the return type is ULong but the object is not
-  /// necessarily a ConstantUInt).
+  /// independent way (Note: the return type is a ULong).
   ///
   static Constant *getSizeOf(const Type *Ty);
 


Index: llvm/include/llvm/Value.h
diff -u llvm/include/llvm/Value.h:1.84 llvm/include/llvm/Value.h:1.84.4.1
--- llvm/include/llvm/Value.h:1.84	Mon Jun  5 11:29:06 2006
+++ llvm/include/llvm/Value.h	Wed Oct 18 22:57:55 2006
@@ -151,8 +151,7 @@
     ConstantExprVal,          // This is an instance of ConstantExpr
     ConstantAggregateZeroVal, // This is an instance of ConstantAggregateNull
     ConstantBoolVal,          // This is an instance of ConstantBool
-    ConstantSIntVal,          // This is an instance of ConstantSInt
-    ConstantUIntVal,          // This is an instance of ConstantUInt
+    ConstantIntVal,           // This is an instance of ConstantInt
     ConstantFPVal,            // This is an instance of ConstantFP
     ConstantArrayVal,         // This is an instance of ConstantArray
     ConstantStructVal,        // This is an instance of ConstantStruct






More information about the llvm-commits mailing list