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
This commit is contained in:
Chris Lattner 2006-12-01 19:20:02 +00:00
parent f0d6dd6006
commit 68329b2187
2 changed files with 10 additions and 3 deletions

View File

@ -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.

View File

@ -929,9 +929,12 @@ static ManagedStatic<ValueMap<uint64_t, Type, ConstantInt> > 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...