From: Chris Lattner Date: Fri, 1 Dec 2006 19:20:02 +0000 (+0000) Subject: add a new ConstantIntegral::get method. Simplify the implementation of X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=68329b21874921be062fe77cc9268ac10da56389;p=oota-llvm.git add a new ConstantIntegral::get method. Simplify the implementation of ConstantInt::get git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32080 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index f78ace36f83..a0ad89fac4f 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -44,6 +44,10 @@ protected: uint64_t Val; ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V); public: + + /// ConstantIntegral::get - Return a bool or integer constant. + static ConstantIntegral *get(const Type *Ty, int64_t V); + /// 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. diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 06dcbb38a7b..c36fea94869 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -929,9 +929,12 @@ static ManagedStatic > IntConstants; // just return the stored value while getSExtValue has to convert back to sign // extended. getZExtValue is more common in LLVM than getSExtValue(). ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) { - unsigned Size = Ty->getPrimitiveSizeInBits(); - uint64_t ZeroExtendedCanonicalization = V & (~uint64_t(0UL) >> (64-Size)); - return IntConstants->getOrCreate(Ty, ZeroExtendedCanonicalization ); + return IntConstants->getOrCreate(Ty, V & Ty->getIntegralTypeMask()); +} + +ConstantIntegral *ConstantIntegral::get(const Type *Ty, int64_t V) { + if (Ty == Type::BoolTy) return ConstantBool::get(V&1); + return IntConstants->getOrCreate(Ty, V & Ty->getIntegralTypeMask()); } //---- ConstantFP::get() implementation...