diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-10-20 07:07:24 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-10-20 07:07:24 +0000 |
commit | b83eb6447ba155342598f0fabe1f08f5baa9164a (patch) | |
tree | a5822f5fdac89033b7b16ba8e5aaf1ae10833b1c | |
parent | 6e7dd9db6bf677c9161a6ecc12f90651cf1231e0 (diff) |
For PR950:
This patch implements the first increment for the Signless Types feature.
All changes pertain to removing the ConstantSInt and ConstantUInt classes
in favor of just using ConstantInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31063 91177308-0d34-0410-b5e6-96231b3b80d8
70 files changed, 5035 insertions, 4082 deletions
diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index bd79747626..950c937824 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -2390,8 +2390,8 @@ provide a name for it (probably based on the name of the translation unit).</p> <div class="doc_text"> <p>Constant represents a base class for different types of constants. It -is subclassed by ConstantBool, ConstantInt, ConstantSInt, ConstantUInt, -ConstantArray etc for representing the various types of Constants.</p> +is subclassed by ConstantBool, ConstantInt, ConstantArray etc for representing +the various types of Constants.</p> </div> @@ -2406,17 +2406,12 @@ ConstantArray etc for representing the various types of Constants.</p> <div class="doc_subsubsection">Important Subclasses of Constant </div> <div class="doc_text"> <ul> - <li>ConstantSInt : This subclass of Constant represents a signed integer - constant. + <li>ConstantInt : This subclass of Constant represents an integer constant. <ul> - <li><tt>int64_t getValue() const</tt>: Returns the underlying value of - this constant. </li> - </ul> - </li> - <li>ConstantUInt : This class represents an unsigned integer. - <ul> - <li><tt>uint64_t getValue() const</tt>: Returns the underlying value of - this constant. </li> + <li><tt>int64_t getSExtValue() const</tt>: Returns the underlying value of + this constant as a sign extended signed integer value.</li> + <li><tt>uint64_t getZExtValue() const</tt>: Returns the underlying value + of this constant as a zero extended unsigned integer value.</li> </ul> </li> <li>ConstantFP : This class represents a floating point constant. diff --git a/docs/Stacker.html b/docs/Stacker.html index 7656dc10c0..a49b56de86 100644 --- a/docs/Stacker.html +++ b/docs/Stacker.html @@ -139,7 +139,7 @@ this: </p> Value* expression(BasicBlock* bb, Value* a, Value* b, Value* x, Value* y ) { - ConstantSInt* one = ConstantSInt::get(Type::IntTy, 1); + ConstantInt* one = ConstantInt::get(Type::IntTy, 1); BinaryOperator* or1 = BinaryOperator::createOr(a, b, "", bb); BinaryOperator* add1 = BinaryOperator::createAdd(x, one, "", bb); BinaryOperator* add2 = BinaryOperator::createAdd(y, one, "", bb); @@ -308,7 +308,7 @@ things, this leads to the idiom: </p> <pre> std::vector<Value*> index_vector; -index_vector.push_back( ConstantSInt::get( Type::LongTy, 0 ); +index_vector.push_back( ConstantInt::get( Type::LongTy, 0 ); // ... push other indices ... GetElementPtrInst* gep = new GetElementPtrInst( ptr, index_vector ); </pre> @@ -367,9 +367,9 @@ functions in the LLVM IR that make things easier. Here's what I learned: </p> <ul> <li>Constants are Values like anything else and can be operands of instructions</li> <li>Integer constants, frequently needed, can be created using the static "get" - methods of the ConstantInt, ConstantSInt, and ConstantUInt classes. The nice thing - about these is that you can "get" any kind of integer quickly.</li> - <li>There's a special method on Constant class which allows you to get the null + methods of the ConstantInt class. The nice thing about these is that you can + "get" any kind of integer quickly.</li> + <li>There's a special method on Constant class which allows you to get the null constant for <em>any</em> type. This is really handy for initializing large arrays or structures, etc.</li> </ul> diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index cdc84ca212..6f775515fb 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -45,8 +45,8 @@ static Function *CreateFibFunction(Module *M) { BasicBlock *BB = new BasicBlock("EntryBlock", FibF); // Get pointers to the constants. - Value *One = ConstantSInt::get(Type::IntTy, 1); - Value *Two = ConstantSInt::get(Type::IntTy, 2); + Value *One = ConstantInt::get(Type::IntTy, 1); + Value *Two = ConstantInt::get(Type::IntTy, 2); // Get pointer to the integer argument of the add1 function... Argument *ArgX = FibF->arg_begin(); // Get the arg. diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp index 8fb9e5659d..8023cc7a18 100644 --- a/examples/HowToUseJIT/HowToUseJIT.cpp +++ b/examples/HowToUseJIT/HowToUseJIT.cpp @@ -60,7 +60,7 @@ int main() { BasicBlock *BB = new BasicBlock("EntryBlock", Add1F); // Get pointers to the constant `1'. - Value *One = ConstantSInt::get(Type::IntTy, 1); + Value *One = ConstantInt::get(Type::IntTy, 1); // Get pointers to the integer argument of the add1 function... assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg @@ -84,7 +84,7 @@ int main() { BB = new BasicBlock("EntryBlock", FooF); // Get pointers to the constant `10'. - Value *Ten = ConstantSInt::get(Type::IntTy, 10); + Value *Ten = ConstantInt::get(Type::IntTy, 10); // Pass Ten to the call call: std::vector<Value*> Params; diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp index 04c6a9f95b..2ec5437c36 100644 --- a/examples/ModuleMaker/ModuleMaker.cpp +++ b/examples/ModuleMaker/ModuleMaker.cpp @@ -40,8 +40,8 @@ int main() { BasicBlock *BB = new BasicBlock("EntryBlock", F); // Get pointers to the constant integers... - Value *Two = ConstantSInt::get(Type::IntTy, 2); - Value *Three = ConstantSInt::get(Type::IntTy, 3); + Value *Two = ConstantInt::get(Type::IntTy, 2); + Value *Three = ConstantInt::get(Type::IntTy, 3); // Create the add instruction... does not insert... Instruction *Add = BinaryOperator::create(Instruction::Add, Two, Three, diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp index b70f3db5bb..dfda126378 100644 --- a/examples/ParallelJIT/ParallelJIT.cpp +++ b/examples/ParallelJIT/ParallelJIT.cpp @@ -42,7 +42,7 @@ static Function* createAdd1(Module* M) BasicBlock *BB = new BasicBlock("EntryBlock", Add1F); // Get pointers to the constant `1'. - Value *One = ConstantSInt::get(Type::IntTy, 1); + Value *One = ConstantInt::get(Type::IntTy, 1); // Get pointers to the integer argument of the add1 function... assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg @@ -70,8 +70,8 @@ static Function *CreateFibFunction(Module *M) BasicBlock *BB = new BasicBlock("EntryBlock", FibF); // Get pointers to the constants. - Value *One = ConstantSInt::get(Type::IntTy, 1); - Value *Two = ConstantSInt::get(Type::IntTy, 2); + Value *One = ConstantInt::get(Type::IntTy, 1); + Value *Two = ConstantInt::get(Type::IntTy, 2); // Get pointer to the integer argument of the add1 function... Argument *ArgX = FibF->arg_begin(); // Get the arg. diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 6b8e91958b..bc76248c15 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -41,22 +41,14 @@ struct ConvertConstantType; /// @brief An abstract class for integer constants. class ConstantIntegral : public Constant { protected: - union { - int64_t Signed; - uint64_t Unsigned; - } Val; + uint64_t Val; ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V); public: - - /// @brief Return the raw value of the constant as a 64-bit integer value. - inline uint64_t getRawValue() const { return Val.Unsigned; } - /// 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 { - unsigned Size = getType()->getPrimitiveSizeInBits(); - return Val.Unsigned & (~uint64_t(0UL) >> (64-Size)); + return Val; } /// Return the constant as a 64-bit integer value after it has been sign @@ -64,7 +56,7 @@ public: /// @brief Return the sign extended value. inline int64_t getSExtValue() const { unsigned Size = getType()->getPrimitiveSizeInBits(); - return (Val.Signed << (64-Size)) >> (64-Size); + return (int64_t(Val) << (64-Size)) >> (64-Size); } /// This function is implemented by subclasses and will return true iff this @@ -111,8 +103,7 @@ public: 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; } }; @@ -147,7 +138,7 @@ public: /// @returns the value of this ConstantBool /// @brief return the boolean value of this constant. - inline bool getValue() const { return static_cast<bool>(getRawValue()); } + inline bool getValue() const { return static_cast<bool>(getZExtValue()); } /// @see ConstantIntegral for details /// @brief Implement overrides @@ -165,13 +156,15 @@ public: //===----------------------------------------------------------------------===// -/// 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, @@ -180,48 +173,15 @@ public: bool equalsInt(unsigned char V) const { assert(V <= 127 && "equalsInt: Can only be used with very small positive constants!"); - return Val.Unsigned == V; + return Val == V; } /// 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, 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 @@ -230,24 +190,28 @@ public: /// @brief Determine if the value is in range for the given type. static bool isValueValidForType(const Type *Ty, int64_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 == 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 +219,19 @@ public: /// @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 +522,7 @@ public: } /// 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); |