Hi, I would like to commit this small patch but thought I should send it out first. This changes ConstantInt to use an APInt object as its value instead of a uint64_t. The interface to ConstantInt still uses uint64_t so the APInt is just being used as a glorified uint64_t as all bit widths are <= 64. This change passes DejaGnu, the MultiSource/Benchmarks test suite, and a few of the SPEC benchmarks that I tried (444.namd, 176.gcc, 473.astar).
Okay to commit? Reid.
Index: include/llvm/Constants.h =================================================================== RCS file: /var/cvs/llvm/llvm/include/llvm/Constants.h,v retrieving revision 1.132 diff -t -d -u -p -5 -r1.132 Constants.h --- include/llvm/Constants.h 20 Feb 2007 07:18:01 -0000 1.132 +++ include/llvm/Constants.h 26 Feb 2007 18:42:27 -0000 @@ -20,10 +20,11 @@ #ifndef LLVM_CONSTANTS_H #define LLVM_CONSTANTS_H #include "llvm/Constant.h" #include "llvm/Type.h" +#include "llvm/ADT/APInt.h" namespace llvm { class ArrayType; class StructType; @@ -41,33 +42,31 @@ struct ConvertConstantType; /// @brief Class for constant integers. class ConstantInt : public Constant { static ConstantInt *TheTrueVal, *TheFalseVal; ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT ConstantInt(const IntegerType *Ty, uint64_t V); - uint64_t Val; + APInt Val; public: /// Return the constant as a 64-bit unsigned integer value after it /// has been zero extended as appropriate for the type of this constant. /// @brief Return the zero extended value. inline uint64_t getZExtValue() const { - return Val; + return Val.getValue(false); } /// Return the constant as a 64-bit integer value after it has been sign /// sign extended as appropriate for the type of this constant. /// @brief Return the sign extended value. inline int64_t getSExtValue() const { - unsigned Size = Value::getType()->getPrimitiveSizeInBits(); - return (int64_t(Val) << (64-Size)) >> (64-Size); + return Val.getValue(true); } + /// 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, /// because this is all that can be represented with all types. /// @brief Determine if this constant's value is same as an unsigned char. - bool equalsInt(unsigned char V) const { - assert(V <= 127 && - "equalsInt: Can only be used with very small positive constants!"); + bool equalsInt(uint64_t V) const { return Val == V; } /// getTrue/getFalse - Return the singleton true/false values. static inline ConstantInt *getTrue() { @@ -116,41 +115,35 @@ public: /// This function will return true iff every bit in this constant is set /// to true. /// @returns true iff this constant's bits are all set to true. /// @brief Determine if the value is all ones. bool isAllOnesValue() const { - return getSExtValue() == -1; + return Val.isAllOnesValue(); } /// This function will return true iff this constant represents the largest /// value that may be represented by the constant's type. /// @returns true iff this is the largest value that may be represented /// by this type. /// @brief Determine if the value is maximal. 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; - return !isValueValidForType(Value::getType(), V) || V < 0; - } - return isAllOnesValue(); + if (isSigned) + return Val.isMaxSignedValue(); + else + return Val.isMaxValue(); } /// This function will return true iff this constant represents the smallest /// value that may be represented by this constant's type. /// @returns true if this is the smallest value that may be represented by /// this type. /// @brief Determine if the value is minimal. 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; - return !isValueValidForType(Value::getType(), V) || V > 0; - } - return getZExtValue() == 0; + if (isSigned) + return Val.isMinSignedValue(); + else + return Val.isMinValue(); } /// @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 Index: lib/VMCore/Constants.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/VMCore/Constants.cpp,v retrieving revision 1.220 diff -t -d -u -p -5 -r1.220 Constants.cpp --- lib/VMCore/Constants.cpp 20 Feb 2007 21:30:56 -0000 1.220 +++ lib/VMCore/Constants.cpp 26 Feb 2007 18:42:29 -0000 @@ -137,11 +137,11 @@ ConstantVector *ConstantVector::getAllOn //===----------------------------------------------------------------------===// // ConstantInt //===----------------------------------------------------------------------===// ConstantInt::ConstantInt(const IntegerType *Ty, uint64_t V) - : Constant(Ty, ConstantIntVal, 0, 0), Val(V) { + : Constant(Ty, ConstantIntVal, 0, 0), Val(Ty->getBitWidth(), V) { } ConstantInt *ConstantInt::TheTrueVal = 0; ConstantInt *ConstantInt::TheFalseVal = 0;
_______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits