OSDN Git Service

Clean up the internals of the ConstantInt machinery
authorChris Lattner <sabre@nondot.org>
Tue, 20 Feb 2007 05:55:46 +0000 (05:55 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 20 Feb 2007 05:55:46 +0000 (05:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34441 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 1ee00aa..93c298e 100644 (file)
@@ -44,10 +44,8 @@ protected:
   uint64_t Val;
 protected:
   ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
-  ConstantInt(const Type *Ty, uint64_t V);
-  ConstantInt(const Type *Ty, int64_t V);
-  ConstantInt(bool V);
-  friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
+  ConstantInt(const IntegerType *Ty, uint64_t V);
+  friend struct ConstantCreator<ConstantInt, IntegerType, uint64_t>;
 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.
@@ -77,12 +75,12 @@ public:
   static inline ConstantInt *getTrue() {
     static ConstantInt *T = 0;
     if (T) return T;
-    return T = new ConstantInt(true);
+    return T = new ConstantInt(Type::Int1Ty, 1);
   }
   static inline ConstantInt *getFalse() {
     static ConstantInt *F = 0;
     if (F) return F;
-    return F = new ConstantInt(false);
+    return F = new ConstantInt(Type::Int1Ty, 0);
   }
 
   /// Return a ConstantInt with the specified value for the specified type. The
index 58fe888..0d59531 100644 (file)
@@ -140,12 +140,8 @@ ConstantVector *ConstantVector::getAllOnesValue(const VectorType *Ty) {
 //===----------------------------------------------------------------------===//
 //                             Normal Constructors
 
-ConstantInt::ConstantInt(bool V) 
-  : Constant(Type::Int1Ty, ConstantIntVal, 0, 0), Val(uint64_t(V)) {
-}
-
-ConstantInt::ConstantInt(const Type *Ty, uint64_t V)
-  : Constant(Ty, ConstantIntVal, 0, 0), Val(Ty == Type::Int1Ty ? bool(V) : V) {
+ConstantInt::ConstantInt(const IntegerType *Ty, uint64_t V)
+  : Constant(Ty, ConstantIntVal, 0, 0), Val(V) {
 }
 
 ConstantFP::ConstantFP(const Type *Ty, double V)
@@ -802,7 +798,7 @@ public:
 
 //---- ConstantInt::get() implementations...
 //
-static ManagedStatic<ValueMap<uint64_t, Type, ConstantInt> > IntConstants;
+static ManagedStatic<ValueMap<uint64_t, IntegerType, ConstantInt> >IntConstants;
 
 // Get a ConstantInt from an int64_t. Note here that we canoncialize the value
 // to a uint64_t value that has been zero extended down to the size of the
@@ -810,12 +806,13 @@ 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) {
-  if (Ty == Type::Int1Ty) 
+  const IntegerType *ITy = cast<IntegerType>(Ty);
+  if (Ty == Type::Int1Ty)
     if (V & 1)
       return getTrue();
     else
       return getFalse();
-  return IntConstants->getOrCreate(Ty, V & cast<IntegerType>(Ty)->getBitMask());
+  return IntConstants->getOrCreate(ITy, V & ITy->getBitMask());
 }
 
 //---- ConstantFP::get() implementation...