add a new ConstantIntegral::get method. Simplify the implementation of
authorChris Lattner <sabre@nondot.org>
Fri, 1 Dec 2006 19:20:02 +0000 (19:20 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 1 Dec 2006 19:20:02 +0000 (19:20 +0000)
ConstantInt::get

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32080 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constants.h
lib/VMCore/Constants.cpp

index f78ace36f832f7fc2c055e23b38381a05cf9423e..a0ad89fac4f9ae841a0847f741a72d085fc72fa5 100644 (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.
index 06dcbb38a7bf7f84a68d92f4222ee53eb804a8bb..c36fea94869f38f46c40b9494a67aa979c5c9ebc 100644 (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...