[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp ConstantFolding.cpp Constants.cpp Instructions.cpp Type.cpp Verifier.cpp

Reid Spencer reid at x10sys.com
Fri Oct 20 00:08:35 PDT 2006



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.208 -> 1.209
ConstantFolding.cpp updated: 1.93 -> 1.94
Constants.cpp updated: 1.164 -> 1.165
Instructions.cpp updated: 1.42 -> 1.43
Type.cpp updated: 1.147 -> 1.148
Verifier.cpp updated: 1.164 -> 1.165
---
Log message:

For PR950: http://llvm.org/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.


---
Diffs of the changes:  (+229 -233)

 AsmWriter.cpp       |    9 -
 ConstantFolding.cpp |  309 ++++++++++++++++++++++++++++------------------------
 Constants.cpp       |  122 +++++++-------------
 Instructions.cpp    |   14 +-
 Type.cpp            |    6 -
 Verifier.cpp        |    2 
 6 files changed, 229 insertions(+), 233 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.208 llvm/lib/VMCore/AsmWriter.cpp:1.209
--- llvm/lib/VMCore/AsmWriter.cpp:1.208	Tue Oct 17 21:21:12 2006
+++ llvm/lib/VMCore/AsmWriter.cpp	Fri Oct 20 02:07:24 2006
@@ -422,10 +422,11 @@
   static std::string Indent = "\n";
   if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
     Out << (CB->getValue() ? "true" : "false");
-  } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV)) {
-    Out << CI->getValue();
-  } else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV)) {
-    Out << CI->getValue();
+  } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
+    if (CI->getType()->isSigned())
+      Out << CI->getSExtValue();
+    else
+      Out << CI->getZExtValue();
   } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
     // We would like to output the FP constant value in exponential notation,
     // but we cannot do this if doing so will lose precision.  Check here to


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.93 llvm/lib/VMCore/ConstantFolding.cpp:1.94
--- llvm/lib/VMCore/ConstantFolding.cpp:1.93	Fri Oct 13 12:22:21 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp	Fri Oct 20 02:07:24 2006
@@ -271,14 +271,14 @@
   }
 
   DEF_CAST(Bool  , ConstantBool, bool)
-  DEF_CAST(SByte , ConstantSInt, signed char)
-  DEF_CAST(UByte , ConstantUInt, unsigned char)
-  DEF_CAST(Short , ConstantSInt, signed short)
-  DEF_CAST(UShort, ConstantUInt, unsigned short)
-  DEF_CAST(Int   , ConstantSInt, signed int)
-  DEF_CAST(UInt  , ConstantUInt, unsigned int)
-  DEF_CAST(Long  , ConstantSInt, int64_t)
-  DEF_CAST(ULong , ConstantUInt, uint64_t)
+  DEF_CAST(SByte , ConstantInt, signed char)
+  DEF_CAST(UByte , ConstantInt, unsigned char)
+  DEF_CAST(Short , ConstantInt, signed short)
+  DEF_CAST(UShort, ConstantInt, unsigned short)
+  DEF_CAST(Int   , ConstantInt, signed int)
+  DEF_CAST(UInt  , ConstantInt, unsigned int)
+  DEF_CAST(Long  , ConstantInt, int64_t)
+  DEF_CAST(ULong , ConstantInt, uint64_t)
   DEF_CAST(Float , ConstantFP  , float)
   DEF_CAST(Double, ConstantFP  , double)
 #undef DEF_CAST
@@ -303,28 +303,28 @@
     return ConstantBool::getFalse();
   }
   static Constant *CastToSByte (const Constant *V) {
-    return ConstantSInt::get(Type::SByteTy, 0);
+    return ConstantInt::get(Type::SByteTy, 0);
   }
   static Constant *CastToUByte (const Constant *V) {
-    return ConstantUInt::get(Type::UByteTy, 0);
+    return ConstantInt::get(Type::UByteTy, 0);
   }
   static Constant *CastToShort (const Constant *V) {
-    return ConstantSInt::get(Type::ShortTy, 0);
+    return ConstantInt::get(Type::ShortTy, 0);
   }
   static Constant *CastToUShort(const Constant *V) {
-    return ConstantUInt::get(Type::UShortTy, 0);
+    return ConstantInt::get(Type::UShortTy, 0);
   }
   static Constant *CastToInt   (const Constant *V) {
-    return ConstantSInt::get(Type::IntTy, 0);
+    return ConstantInt::get(Type::IntTy, 0);
   }
   static Constant *CastToUInt  (const Constant *V) {
-    return ConstantUInt::get(Type::UIntTy, 0);
+    return ConstantInt::get(Type::UIntTy, 0);
   }
   static Constant *CastToLong  (const Constant *V) {
-    return ConstantSInt::get(Type::LongTy, 0);
+    return ConstantInt::get(Type::LongTy, 0);
   }
   static Constant *CastToULong (const Constant *V) {
-    return ConstantUInt::get(Type::ULongTy, 0);
+    return ConstantInt::get(Type::ULongTy, 0);
   }
   static Constant *CastToFloat (const Constant *V) {
     return ConstantFP::get(Type::FloatTy, 0);
@@ -428,49 +428,46 @@
 
 
 //===----------------------------------------------------------------------===//
-//                             DirectRules Class
+//                           DirectIntRules Class
 //===----------------------------------------------------------------------===//
 //
-// DirectRules provides a concrete base classes of ConstRules for a variety of
-// different types.  This allows the C++ compiler to automatically generate our
-// constant handling operations in a typesafe and accurate manner.
+// DirectIntRules provides implementations of functions that are valid on
+// integer types, but not all types in general.
 //
 namespace {
-template<class ConstantClass, class BuiltinType, Type **Ty, class SuperClass>
-struct VISIBILITY_HIDDEN DirectRules
-  : public TemplateRules<ConstantClass, SuperClass> {
-  static Constant *Add(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() + (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
-  }
+template <class BuiltinType, Type **Ty>
+struct VISIBILITY_HIDDEN DirectIntRules
+  : public TemplateRules<ConstantInt, DirectIntRules<BuiltinType, Ty> > {
 
-  static Constant *Sub(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() - (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *Add(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = (BuiltinType)V1->getZExtValue() + 
+                    (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *Mul(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() * (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *Sub(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = (BuiltinType)V1->getZExtValue() - 
+                    (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
-    if (V2->isNullValue()) return 0;
-    BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *Mul(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = (BuiltinType)V1->getZExtValue() * 
+                    (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *LessThan(const ConstantClass *V1, const ConstantClass *V2) {
-    bool R = (BuiltinType)V1->getValue() < (BuiltinType)V2->getValue();
+  static Constant *LessThan(const ConstantInt *V1, const ConstantInt *V2) {
+    bool R = (BuiltinType)V1->getZExtValue() < (BuiltinType)V2->getZExtValue();
     return ConstantBool::get(R);
   }
 
-  static Constant *EqualTo(const ConstantClass *V1, const ConstantClass *V2) {
-    bool R = (BuiltinType)V1->getValue() == (BuiltinType)V2->getValue();
+  static Constant *EqualTo(const ConstantInt *V1, const ConstantInt *V2) {
+    bool R = (BuiltinType)V1->getZExtValue() == (BuiltinType)V2->getZExtValue();
     return ConstantBool::get(R);
   }
 
-  static Constant *CastToPointer(const ConstantClass *V,
+  static Constant *CastToPointer(const ConstantInt *V,
                                  const PointerType *PTy) {
     if (V->isNullValue())    // Is it a FP or Integral null value?
       return ConstantPointerNull::get(PTy);
@@ -479,79 +476,70 @@
 
   // Casting operators.  ick
 #define DEF_CAST(TYPE, CLASS, CTYPE) \
-  static Constant *CastTo##TYPE  (const ConstantClass *V) {    \
-    return CLASS::get(Type::TYPE##Ty, (CTYPE)(BuiltinType)V->getValue()); \
+  static Constant *CastTo##TYPE  (const ConstantInt *V) {    \
+    return CLASS::get(Type::TYPE##Ty, (CTYPE)(BuiltinType)V->getZExtValue()); \
   }
 
   DEF_CAST(Bool  , ConstantBool, bool)
-  DEF_CAST(SByte , ConstantSInt, signed char)
-  DEF_CAST(UByte , ConstantUInt, unsigned char)
-  DEF_CAST(Short , ConstantSInt, signed short)
-  DEF_CAST(UShort, ConstantUInt, unsigned short)
-  DEF_CAST(Int   , ConstantSInt, signed int)
-  DEF_CAST(UInt  , ConstantUInt, unsigned int)
-  DEF_CAST(Long  , ConstantSInt, int64_t)
-  DEF_CAST(ULong , ConstantUInt, uint64_t)
-  DEF_CAST(Float , ConstantFP  , float)
-  DEF_CAST(Double, ConstantFP  , double)
+  DEF_CAST(SByte , ConstantInt, signed char)
+  DEF_CAST(UByte , ConstantInt, unsigned char)
+  DEF_CAST(Short , ConstantInt, signed short)
+  DEF_CAST(UShort, ConstantInt, unsigned short)
+  DEF_CAST(Int   , ConstantInt, signed int)
+  DEF_CAST(UInt  , ConstantInt, unsigned int)
+  DEF_CAST(Long  , ConstantInt, int64_t)
+  DEF_CAST(ULong , ConstantInt, uint64_t)
+  DEF_CAST(Float , ConstantFP , float)
+  DEF_CAST(Double, ConstantFP , double)
 #undef DEF_CAST
-};
-}  // end anonymous namespace
-
 
-//===----------------------------------------------------------------------===//
-//                           DirectIntRules Class
-//===----------------------------------------------------------------------===//
-//
-// DirectIntRules provides implementations of functions that are valid on
-// integer types, but not all types in general.
-//
-namespace {
-template <class ConstantClass, class BuiltinType, Type **Ty>
-struct VISIBILITY_HIDDEN DirectIntRules
-  : public DirectRules<ConstantClass, BuiltinType, Ty,
-                       DirectIntRules<ConstantClass, BuiltinType, Ty> > {
-
-  static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
+  static Constant *Div(const ConstantInt *V1, const ConstantInt *V2) {
     if (V2->isNullValue()) return 0;
     if (V2->isAllOnesValue() &&              // MIN_INT / -1
-        (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
+        (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue())
       return 0;
-    BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+    BuiltinType R = 
+      (BuiltinType)V1->getZExtValue() / (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *Rem(const ConstantClass *V1,
-                       const ConstantClass *V2) {
+  static Constant *Rem(const ConstantInt *V1,
+                        const ConstantInt *V2) {
     if (V2->isNullValue()) return 0;         // X / 0
     if (V2->isAllOnesValue() &&              // MIN_INT / -1
-        (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
+        (BuiltinType)V1->getZExtValue() == -(BuiltinType)V1->getZExtValue())
       return 0;
-    BuiltinType R = (BuiltinType)V1->getValue() % (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+    BuiltinType R = 
+      (BuiltinType)V1->getZExtValue() % (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *And(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() & (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *And(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = 
+      (BuiltinType)V1->getZExtValue() & (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
-  static Constant *Or(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() | (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *Or(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = 
+      (BuiltinType)V1->getZExtValue() | (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
-  static Constant *Xor(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() ^ (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *Xor(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = 
+      (BuiltinType)V1->getZExtValue() ^ (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *Shl(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() << (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *Shl(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = 
+      (BuiltinType)V1->getZExtValue() << (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 
-  static Constant *Shr(const ConstantClass *V1, const ConstantClass *V2) {
-    BuiltinType R = (BuiltinType)V1->getValue() >> (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+  static Constant *Shr(const ConstantInt *V1, const ConstantInt *V2) {
+    BuiltinType R = 
+      (BuiltinType)V1->getZExtValue() >> (BuiltinType)V2->getZExtValue();
+    return ConstantInt::get(*Ty, R);
   }
 };
 }  // end anonymous namespace
@@ -565,22 +553,74 @@
 /// floating point types, but not all types in general.
 ///
 namespace {
-template <class ConstantClass, class BuiltinType, Type **Ty>
+template <class BuiltinType, Type **Ty>
 struct VISIBILITY_HIDDEN DirectFPRules
-  : public DirectRules<ConstantClass, BuiltinType, Ty,
-                       DirectFPRules<ConstantClass, BuiltinType, Ty> > {
-  static Constant *Rem(const ConstantClass *V1, const ConstantClass *V2) {
+  : public TemplateRules<ConstantFP, DirectFPRules<BuiltinType, Ty> > {
+
+  static Constant *Add(const ConstantFP *V1, const ConstantFP *V2) {
+    BuiltinType R = (BuiltinType)V1->getValue() + 
+                    (BuiltinType)V2->getValue();
+    return ConstantFP::get(*Ty, R);
+  }
+
+  static Constant *Sub(const ConstantFP *V1, const ConstantFP *V2) {
+    BuiltinType R = (BuiltinType)V1->getValue() - (BuiltinType)V2->getValue();
+    return ConstantFP::get(*Ty, R);
+  }
+
+  static Constant *Mul(const ConstantFP *V1, const ConstantFP *V2) {
+    BuiltinType R = (BuiltinType)V1->getValue() * (BuiltinType)V2->getValue();
+    return ConstantFP::get(*Ty, R);
+  }
+
+  static Constant *LessThan(const ConstantFP *V1, const ConstantFP *V2) {
+    bool R = (BuiltinType)V1->getValue() < (BuiltinType)V2->getValue();
+    return ConstantBool::get(R);
+  }
+
+  static Constant *EqualTo(const ConstantFP *V1, const ConstantFP *V2) {
+    bool R = (BuiltinType)V1->getValue() == (BuiltinType)V2->getValue();
+    return ConstantBool::get(R);
+  }
+
+  static Constant *CastToPointer(const ConstantFP *V,
+                                 const PointerType *PTy) {
+    if (V->isNullValue())    // Is it a FP or Integral null value?
+      return ConstantPointerNull::get(PTy);
+    return 0;  // Can't const prop other types of pointers
+  }
+
+  // Casting operators.  ick
+#define DEF_CAST(TYPE, CLASS, CTYPE) \
+  static Constant *CastTo##TYPE  (const ConstantFP *V) {    \
+    return CLASS::get(Type::TYPE##Ty, (CTYPE)(BuiltinType)V->getValue()); \
+  }
+
+  DEF_CAST(Bool  , ConstantBool, bool)
+  DEF_CAST(SByte , ConstantInt, signed char)
+  DEF_CAST(UByte , ConstantInt, unsigned char)
+  DEF_CAST(Short , ConstantInt, signed short)
+  DEF_CAST(UShort, ConstantInt, unsigned short)
+  DEF_CAST(Int   , ConstantInt, signed int)
+  DEF_CAST(UInt  , ConstantInt, unsigned int)
+  DEF_CAST(Long  , ConstantInt, int64_t)
+  DEF_CAST(ULong , ConstantInt, uint64_t)
+  DEF_CAST(Float , ConstantFP , float)
+  DEF_CAST(Double, ConstantFP , double)
+#undef DEF_CAST
+
+  static Constant *Rem(const ConstantFP *V1, const ConstantFP *V2) {
     if (V2->isNullValue()) return 0;
     BuiltinType Result = std::fmod((BuiltinType)V1->getValue(),
                                    (BuiltinType)V2->getValue());
-    return ConstantClass::get(*Ty, Result);
+    return ConstantFP::get(*Ty, Result);
   }
-  static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
+  static Constant *Div(const ConstantFP *V1, const ConstantFP *V2) {
     BuiltinType inf = std::numeric_limits<BuiltinType>::infinity();
-    if (V2->isExactlyValue(0.0)) return ConstantClass::get(*Ty, inf);
-    if (V2->isExactlyValue(-0.0)) return ConstantClass::get(*Ty, -inf);
+    if (V2->isExactlyValue(0.0)) return ConstantFP::get(*Ty, inf);
+    if (V2->isExactlyValue(-0.0)) return ConstantFP::get(*Ty, -inf);
     BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+    return ConstantFP::get(*Ty, R);
   }
 };
 }  // end anonymous namespace
@@ -590,26 +630,16 @@
 static ManagedStatic<NullPointerRules> NullPointerR;
 static ManagedStatic<ConstantPackedRules> ConstantPackedR;
 static ManagedStatic<GeneralPackedRules> GeneralPackedR;
-static ManagedStatic<DirectIntRules<ConstantSInt,   signed char ,
-                                    &Type::SByteTy> > SByteR;
-static ManagedStatic<DirectIntRules<ConstantUInt, unsigned char ,
-                                    &Type::UByteTy> > UByteR;
-static ManagedStatic<DirectIntRules<ConstantSInt,   signed short,
-                                    &Type::ShortTy> > ShortR;
-static ManagedStatic<DirectIntRules<ConstantUInt, unsigned short,
-                                    &Type::UShortTy> > UShortR;
-static ManagedStatic<DirectIntRules<ConstantSInt,   signed int  ,
-                                    &Type::IntTy> >   IntR;
-static ManagedStatic<DirectIntRules<ConstantUInt, unsigned int  ,
-                                    &Type::UIntTy> >  UIntR;
-static ManagedStatic<DirectIntRules<ConstantSInt,  int64_t      ,
-                                    &Type::LongTy> >  LongR;
-static ManagedStatic<DirectIntRules<ConstantUInt, uint64_t      ,
-                                    &Type::ULongTy> > ULongR;
-static ManagedStatic<DirectFPRules <ConstantFP  , float         ,
-                                    &Type::FloatTy> > FloatR;
-static ManagedStatic<DirectFPRules <ConstantFP  , double        ,
-                                    &Type::DoubleTy> > DoubleR;
+static ManagedStatic<DirectIntRules<signed char   , &Type::SByteTy> > SByteR;
+static ManagedStatic<DirectIntRules<unsigned char , &Type::UByteTy> > UByteR;
+static ManagedStatic<DirectIntRules<signed short  , &Type::ShortTy> > ShortR;
+static ManagedStatic<DirectIntRules<unsigned short, &Type::UShortTy> > UShortR;
+static ManagedStatic<DirectIntRules<signed int    , &Type::IntTy> >   IntR;
+static ManagedStatic<DirectIntRules<unsigned int  , &Type::UIntTy> >  UIntR;
+static ManagedStatic<DirectIntRules<int64_t       , &Type::LongTy> >  LongR;
+static ManagedStatic<DirectIntRules<uint64_t      , &Type::ULongTy> > ULongR;
+static ManagedStatic<DirectFPRules <float         , &Type::FloatTy> > FloatR;
+static ManagedStatic<DirectFPRules <double        , &Type::DoubleTy> > DoubleR;
 
 /// ConstRules::get - This method returns the constant rules implementation that
 /// implements the semantics of the two specified constants.
@@ -684,7 +714,7 @@
       if (DstEltTy->getTypeID() == Type::DoubleTyID) {
         for (unsigned i = 0; i != SrcNumElts; ++i) {
           double V =
-            BitsToDouble(cast<ConstantInt>(CP->getOperand(i))->getRawValue());
+            BitsToDouble(cast<ConstantInt>(CP->getOperand(i))->getZExtValue());
           Result.push_back(ConstantFP::get(Type::DoubleTy, V));
         }
         return ConstantPacked::get(Result);
@@ -692,7 +722,7 @@
       assert(DstEltTy == Type::FloatTy && "Unknown fp type!");
       for (unsigned i = 0; i != SrcNumElts; ++i) {
         float V =
-        BitsToFloat(cast<ConstantInt>(CP->getOperand(i))->getRawValue());
+        BitsToFloat(cast<ConstantInt>(CP->getOperand(i))->getZExtValue());
         Result.push_back(ConstantFP::get(Type::FloatTy, V));
       }
       return ConstantPacked::get(Result);
@@ -705,7 +735,7 @@
       for (unsigned i = 0; i != SrcNumElts; ++i) {
         uint64_t V =
           DoubleToBits(cast<ConstantFP>(CP->getOperand(i))->getValue());
-        Constant *C = ConstantUInt::get(Type::ULongTy, V);
+        Constant *C = ConstantInt::get(Type::ULongTy, V);
         Result.push_back(ConstantExpr::getCast(C, DstEltTy));
       }
       return ConstantPacked::get(Result);
@@ -713,8 +743,8 @@
 
     assert(SrcEltTy->getTypeID() == Type::FloatTyID);
     for (unsigned i = 0; i != SrcNumElts; ++i) {
-      unsigned V = FloatToBits(cast<ConstantFP>(CP->getOperand(i))->getValue());
-      Constant *C = ConstantUInt::get(Type::UIntTy, V);
+      uint32_t V = FloatToBits(cast<ConstantFP>(CP->getOperand(i))->getValue());
+      Constant *C = ConstantInt::get(Type::UIntTy, V);
       Result.push_back(ConstantExpr::getCast(C, DstEltTy));
     }
     return ConstantPacked::get(Result);
@@ -871,8 +901,8 @@
                           cast<PackedType>(Val->getType())->getElementType());
   
   if (const ConstantPacked *CVal = dyn_cast<ConstantPacked>(Val)) {
-    if (const ConstantUInt *CIdx = dyn_cast<ConstantUInt>(Idx)) {
-      return const_cast<Constant*>(CVal->getOperand(CIdx->getValue()));
+    if (const ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
+      return const_cast<Constant*>(CVal->getOperand(CIdx->getZExtValue()));
     } else if (isa<UndefValue>(Idx)) {
       // ee({w,x,y,z}, undef) -> w (an arbitrary value).
       return const_cast<Constant*>(CVal->getOperand(0));
@@ -884,9 +914,9 @@
 Constant *llvm::ConstantFoldInsertElementInstruction(const Constant *Val,
                                                      const Constant *Elt,
                                                      const Constant *Idx) {
-  const ConstantUInt *CIdx = dyn_cast<ConstantUInt>(Idx);
+  const ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx);
   if (!CIdx) return 0;
-  unsigned idxVal = CIdx->getValue();
+  uint64_t idxVal = CIdx->getZExtValue();
   if (const UndefValue *UVal = dyn_cast<UndefValue>(Val)) {
     // Insertion of scalar constant into packed undef
     // Optimize away insertion of undef
@@ -991,7 +1021,8 @@
 
   // If they are really different, now that they are the same type, then we
   // found a difference!
-  if (cast<ConstantSInt>(C1)->getValue() < cast<ConstantSInt>(C2)->getValue())
+  if (cast<ConstantInt>(C1)->getSExtValue() < 
+      cast<ConstantInt>(C2)->getSExtValue())
     return -1;
   else
     return 1;
@@ -1324,17 +1355,17 @@
       case Instruction::Mul:
         if (V2->isNullValue()) return const_cast<Constant*>(V2);  // X * 0 == 0
         if (const ConstantInt *CI = dyn_cast<ConstantInt>(V2))
-          if (CI->getRawValue() == 1)
+          if (CI->getZExtValue() == 1)
             return const_cast<Constant*>(V1);                     // X * 1 == X
         break;
       case Instruction::Div:
         if (const ConstantInt *CI = dyn_cast<ConstantInt>(V2))
-          if (CI->getRawValue() == 1)
+          if (CI->getZExtValue() == 1)
             return const_cast<Constant*>(V1);                     // X / 1 == X
         break;
       case Instruction::Rem:
         if (const ConstantInt *CI = dyn_cast<ConstantInt>(V2))
-          if (CI->getRawValue() == 1)
+          if (CI->getZExtValue() == 1)
             return Constant::getNullValue(CI->getType()); // X % 1 == 0
         break;
       case Instruction::And:
@@ -1348,7 +1379,7 @@
           // Functions are at least 4-byte aligned.  If and'ing the address of a
           // function with a constant < 4, fold it to zero.
           if (const ConstantInt *CI = dyn_cast<ConstantInt>(V2))
-            if (CI->getRawValue() < 4 && isa<Function>(CPR))
+            if (CI->getZExtValue() < 4 && isa<Function>(CPR))
               return Constant::getNullValue(CI->getType());
         }
         break;
@@ -1427,10 +1458,10 @@
 
     if (IdxList.size() == 1) {
       const Type *ElTy = cast<PointerType>(C->getType())->getElementType();
-      if (unsigned ElSize = ElTy->getPrimitiveSize()) {
+      if (uint32_t ElSize = ElTy->getPrimitiveSize()) {
         // gep null, C is equal to C*sizeof(nullty).  If nullty is a known llvm
         // type, we can statically fold this.
-        Constant *R = ConstantUInt::get(Type::UIntTy, ElSize);
+        Constant *R = ConstantInt::get(Type::UIntTy, ElSize);
         R = ConstantExpr::getCast(R, Idx0->getType());
         R = ConstantExpr::getMul(R, Idx0);
         return ConstantExpr::getCast(R, C->getType());


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.164 llvm/lib/VMCore/Constants.cpp:1.165
--- llvm/lib/VMCore/Constants.cpp:1.164	Thu Oct 19 19:27:06 2006
+++ llvm/lib/VMCore/Constants.cpp	Fri Oct 20 02:07:24 2006
@@ -93,35 +93,35 @@
     return NullBool;
   }
   case Type::SByteTyID: {
-    static Constant *NullSByte = ConstantSInt::get(Type::SByteTy, 0);
+    static Constant *NullSByte = ConstantInt::get(Type::SByteTy, 0);
     return NullSByte;
   }
   case Type::UByteTyID: {
-    static Constant *NullUByte = ConstantUInt::get(Type::UByteTy, 0);
+    static Constant *NullUByte = ConstantInt::get(Type::UByteTy, 0);
     return NullUByte;
   }
   case Type::ShortTyID: {
-    static Constant *NullShort = ConstantSInt::get(Type::ShortTy, 0);
+    static Constant *NullShort = ConstantInt::get(Type::ShortTy, 0);
     return NullShort;
   }
   case Type::UShortTyID: {
-    static Constant *NullUShort = ConstantUInt::get(Type::UShortTy, 0);
+    static Constant *NullUShort = ConstantInt::get(Type::UShortTy, 0);
     return NullUShort;
   }
   case Type::IntTyID: {
-    static Constant *NullInt = ConstantSInt::get(Type::IntTy, 0);
+    static Constant *NullInt = ConstantInt::get(Type::IntTy, 0);
     return NullInt;
   }
   case Type::UIntTyID: {
-    static Constant *NullUInt = ConstantUInt::get(Type::UIntTy, 0);
+    static Constant *NullUInt = ConstantInt::get(Type::UIntTy, 0);
     return NullUInt;
   }
   case Type::LongTyID: {
-    static Constant *NullLong = ConstantSInt::get(Type::LongTy, 0);
+    static Constant *NullLong = ConstantInt::get(Type::LongTy, 0);
     return NullLong;
   }
   case Type::ULongTyID: {
-    static Constant *NullULong = ConstantUInt::get(Type::ULongTy, 0);
+    static Constant *NullULong = ConstantInt::get(Type::ULongTy, 0);
     return NullULong;
   }
 
@@ -160,7 +160,7 @@
     unsigned TypeBits = Ty->getPrimitiveSize()*8;
     int64_t Val = INT64_MAX;             // All ones
     Val >>= 64-TypeBits;                 // Shift out unwanted 1 bits...
-    return ConstantSInt::get(Ty, Val);
+    return ConstantInt::get(Ty, Val);
   }
 
   case Type::UByteTyID:
@@ -184,13 +184,13 @@
      unsigned TypeBits = Ty->getPrimitiveSize()*8;
      int64_t Val = -1;                    // All ones
      Val <<= TypeBits-1;                  // Shift over to the right spot
-     return ConstantSInt::get(Ty, Val);
+     return ConstantInt::get(Ty, Val);
   }
 
   case Type::UByteTyID:
   case Type::UShortTyID:
   case Type::UIntTyID:
-  case Type::ULongTyID:  return ConstantUInt::get(Ty, 0);
+  case Type::ULongTyID:  return ConstantInt::get(Ty, 0);
 
   default: return 0;
   }
@@ -203,7 +203,7 @@
   case Type::SByteTyID:
   case Type::ShortTyID:
   case Type::IntTyID:
-  case Type::LongTyID:   return ConstantSInt::get(Ty, -1);
+  case Type::LongTyID:   return ConstantInt::get(Ty, -1);
 
   case Type::UByteTyID:
   case Type::UShortTyID:
@@ -213,20 +213,12 @@
     unsigned TypeBits = Ty->getPrimitiveSize()*8;
     uint64_t Val = ~0ULL;                // All ones
     Val >>= 64-TypeBits;                 // Shift out unwanted 1 bits...
-    return ConstantUInt::get(Ty, Val);
+    return ConstantInt::get(Ty, Val);
   }
   default: return 0;
   }
 }
 
-bool ConstantUInt::isAllOnesValue() const {
-  unsigned TypeBits = getType()->getPrimitiveSize()*8;
-  uint64_t Val = ~0ULL;                // All ones
-  Val >>= 64-TypeBits;                 // Shift out inappropriate bits
-  return getValue() == Val;
-}
-
-
 //===----------------------------------------------------------------------===//
 //                            ConstantXXX Classes
 //===----------------------------------------------------------------------===//
@@ -235,30 +227,15 @@
 //                             Normal Constructors
 
 ConstantIntegral::ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V)
-  : Constant(Ty, VT, 0, 0) {
-    Val.Unsigned = V;
+  : Constant(Ty, VT, 0, 0), Val(V) {
 }
 
 ConstantBool::ConstantBool(bool V) 
-  : ConstantIntegral(Type::BoolTy, ConstantBoolVal, V) {
-}
-
-ConstantInt::ConstantInt(const Type *Ty, ValueTy VT, uint64_t V)
-  : ConstantIntegral(Ty, VT, V) {
-}
-
-ConstantSInt::ConstantSInt(const Type *Ty, int64_t V)
-  : ConstantInt(Ty, ConstantSIntVal, V) {
-  assert(Ty->isInteger() && Ty->isSigned() &&
-         "Illegal type for signed integer constant!");
-  assert(isValueValidForType(Ty, V) && "Value too large for type!");
+  : ConstantIntegral(Type::BoolTy, ConstantBoolVal, uint64_t(V)) {
 }
 
-ConstantUInt::ConstantUInt(const Type *Ty, uint64_t V)
-  : ConstantInt(Ty, ConstantUIntVal, V) {
-  assert(Ty->isInteger() && Ty->isUnsigned() &&
-         "Illegal type for unsigned integer constant!");
-  assert(isValueValidForType(Ty, V) && "Value too large for type!");
+ConstantInt::ConstantInt(const Type *Ty, uint64_t V)
+  : ConstantIntegral(Ty, ConstantIntVal, V) {
 }
 
 ConstantFP::ConstantFP(const Type *Ty, double V)
@@ -611,36 +588,26 @@
 //===----------------------------------------------------------------------===//
 //                      isValueValidForType implementations
 
-bool ConstantSInt::isValueValidForType(const Type *Ty, int64_t Val) {
+bool ConstantInt::isValueValidForType(const Type *Ty, int64_t Val) {
   switch (Ty->getTypeID()) {
   default:
     return false;         // These can't be represented as integers!!!
     // Signed types...
   case Type::SByteTyID:
     return (Val <= INT8_MAX && Val >= INT8_MIN);
+  case Type::UByteTyID:
+    return (Val >= 0) && (Val <= UINT8_MAX);
   case Type::ShortTyID:
     return (Val <= INT16_MAX && Val >= INT16_MIN);
+  case Type::UShortTyID:
+    return (Val >= 0) && (Val <= UINT16_MAX);
   case Type::IntTyID:
     return (Val <= int(INT32_MAX) && Val >= int(INT32_MIN));
-  case Type::LongTyID:
-    return true;          // This is the largest type...
-  }
-}
-
-bool ConstantUInt::isValueValidForType(const Type *Ty, uint64_t Val) {
-  switch (Ty->getTypeID()) {
-  default:
-    return false;         // These can't be represented as integers!!!
-
-    // Unsigned types...
-  case Type::UByteTyID:
-    return (Val <= UINT8_MAX);
-  case Type::UShortTyID:
-    return (Val <= UINT16_MAX);
   case Type::UIntTyID:
-    return (Val <= UINT32_MAX);
+    return (Val >= 0) && (Val <= UINT32_MAX);
+  case Type::LongTyID:
   case Type::ULongTyID:
-    return true;          // This is the largest type...
+    return true; // always true, has to fit in largest type
   }
 }
 
@@ -756,8 +723,9 @@
     ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
       MapKey Lookup(Ty, V);
       typename MapTy::iterator I = Map.lower_bound(Lookup);
+      // Is it in the map?      
       if (I != Map.end() && I->first == Lookup)
-        return static_cast<ConstantClass *>(I->second);  // Is it in the map?
+        return static_cast<ConstantClass *>(I->second);  
 
       // If no preexisting value, create one now...
       ConstantClass *Result =
@@ -914,23 +882,19 @@
   return F = new ConstantBool(false);
 }
 
-//---- ConstantUInt::get() and ConstantSInt::get() implementations...
+//---- ConstantInt::get() implementations...
 //
-static ManagedStatic<ValueMap< int64_t, Type, ConstantSInt> > SIntConstants;
-static ManagedStatic<ValueMap<uint64_t, Type, ConstantUInt> > UIntConstants;
-
-ConstantSInt *ConstantSInt::get(const Type *Ty, int64_t V) {
-  return SIntConstants->getOrCreate(Ty, V);
-}
-
-ConstantUInt *ConstantUInt::get(const Type *Ty, uint64_t V) {
-  return UIntConstants->getOrCreate(Ty, V);
-}
+static ManagedStatic<ValueMap<uint64_t, Type, ConstantInt> > IntConstants;
 
-ConstantInt *ConstantInt::get(const Type *Ty, unsigned char V) {
-  assert(V <= 127 && "Can only be used with very small positive constants!");
-  if (Ty->isSigned()) return ConstantSInt::get(Ty, V);
-  return ConstantUInt::get(Ty, V);
+// 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
+// integer type of the ConstantInt. This allows the getZExtValue method to 
+// 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 );
 }
 
 //---- ConstantFP::get() implementation...
@@ -1075,11 +1039,11 @@
 Constant *ConstantArray::get(const std::string &Str, bool AddNull) {
   std::vector<Constant*> ElementVals;
   for (unsigned i = 0; i < Str.length(); ++i)
-    ElementVals.push_back(ConstantSInt::get(Type::SByteTy, Str[i]));
+    ElementVals.push_back(ConstantInt::get(Type::SByteTy, Str[i]));
 
   // Add a null terminator to the string...
   if (AddNull) {
-    ElementVals.push_back(ConstantSInt::get(Type::SByteTy, 0));
+    ElementVals.push_back(ConstantInt::get(Type::SByteTy, 0));
   }
 
   ArrayType *ATy = ArrayType::get(Type::SByteTy, ElementVals.size());
@@ -1109,7 +1073,7 @@
   assert(isString() && "Not a string!");
   std::string Result;
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
-    Result += (char)cast<ConstantInt>(getOperand(i))->getRawValue();
+    Result += (char)cast<ConstantInt>(getOperand(i))->getZExtValue();
   return Result;
 }
 
@@ -1443,7 +1407,7 @@
 
 Constant *ConstantExpr::getPtrPtrFromArrayPtr(Constant *C) {
   // pointer from array is implemented as: getelementptr arr ptr, 0, 0
-  static std::vector<Constant*> Indices(2, ConstantUInt::get(Type::UIntTy, 0));
+  static std::vector<Constant*> Indices(2, ConstantInt::get(Type::UIntTy, 0));
 
   return ConstantExpr::getGetElementPtr(C, Indices);
 }
@@ -1920,7 +1884,7 @@
         if (CE->getNumOperands() == 3 &&
             cast<Constant>(CE->getOperand(1))->isNullValue() &&
             isa<ConstantInt>(CE->getOperand(2))) {
-          Offset += cast<ConstantInt>(CE->getOperand(2))->getRawValue();
+          Offset += cast<ConstantInt>(CE->getOperand(2))->getZExtValue();
           return CE->getOperand(0)->getStringValue(Chop, Offset);
         }
       }


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.42 llvm/lib/VMCore/Instructions.cpp:1.43
--- llvm/lib/VMCore/Instructions.cpp:1.42	Thu Oct  5 01:24:58 2006
+++ llvm/lib/VMCore/Instructions.cpp	Fri Oct 20 02:07:24 2006
@@ -513,7 +513,7 @@
 
 static Value *getAISize(Value *Amt) {
   if (!Amt)
-    Amt = ConstantUInt::get(Type::UIntTy, 1);
+    Amt = ConstantInt::get(Type::UIntTy, 1);
   else {
     assert(!isa<BasicBlock>(Amt) &&
            "Passed basic block into allocation size parameter!  Ue other ctor");
@@ -546,8 +546,8 @@
 }
 
 bool AllocationInst::isArrayAllocation() const {
-  if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(getOperand(0)))
-    return CUI->getValue() != 1;
+  if (ConstantInt *CUI = dyn_cast<ConstantInt>(getOperand(0)))
+    return CUI->getZExtValue() != 1;
   return true;
 }
 
@@ -849,7 +849,7 @@
                                        Instruction *InsertBef)
   : Instruction(cast<PackedType>(Val->getType())->getElementType(),
                 ExtractElement, Ops, 2, Name, InsertBef) {
-  Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV);
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
   assert(isValidOperands(Val, Index) &&
          "Invalid extractelement instruction operands!");
   Ops[0].init(Val, this);
@@ -874,7 +874,7 @@
                                        BasicBlock *InsertAE)
   : Instruction(cast<PackedType>(Val->getType())->getElementType(),
                 ExtractElement, Ops, 2, Name, InsertAE) {
-  Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV);
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
   assert(isValidOperands(Val, Index) &&
          "Invalid extractelement instruction operands!");
   
@@ -915,7 +915,7 @@
                                      const std::string &Name,
                                      Instruction *InsertBef)
   : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) {
-  Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV);
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
   assert(isValidOperands(Vec, Elt, Index) &&
          "Invalid insertelement instruction operands!");
   Ops[0].init(Vec, this);
@@ -940,7 +940,7 @@
                                      const std::string &Name,
                                      BasicBlock *InsertAE)
 : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) {
-  Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV);
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
   assert(isValidOperands(Vec, Elt, Index) &&
          "Invalid insertelement instruction operands!");
   


Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.147 llvm/lib/VMCore/Type.cpp:1.148
--- llvm/lib/VMCore/Type.cpp:1.147	Sun Oct 15 18:21:12 2006
+++ llvm/lib/VMCore/Type.cpp	Fri Oct 20 02:07:24 2006
@@ -366,8 +366,8 @@
 bool StructType::indexValid(const Value *V) const {
   // Structure indexes require unsigned integer constants.
   if (V->getType() == Type::UIntTy)
-    if (const ConstantUInt *CU = dyn_cast<ConstantUInt>(V))
-      return CU->getValue() < ContainedTys.size();
+    if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
+      return CU->getZExtValue() < ContainedTys.size();
   return false;
 }
 
@@ -376,7 +376,7 @@
 //
 const Type *StructType::getTypeAtIndex(const Value *V) const {
   assert(indexValid(V) && "Invalid structure index!");
-  unsigned Idx = (unsigned)cast<ConstantUInt>(V)->getValue();
+  unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
   return ContainedTys[Idx];
 }
 


Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.164 llvm/lib/VMCore/Verifier.cpp:1.165
--- llvm/lib/VMCore/Verifier.cpp:1.164	Sun Sep 17 15:25:45 2006
+++ llvm/lib/VMCore/Verifier.cpp	Fri Oct 20 02:07:24 2006
@@ -586,7 +586,7 @@
   // Check to see if Mask is valid.
   if (const ConstantPacked *MV = dyn_cast<ConstantPacked>(SV.getOperand(2))) {
     for (unsigned i = 0, e = MV->getNumOperands(); i != e; ++i) {
-      Assert1(isa<ConstantUInt>(MV->getOperand(i)) ||
+      Assert1(isa<ConstantInt>(MV->getOperand(i)) ||
               isa<UndefValue>(MV->getOperand(i)),
               "Invalid shufflevector shuffle mask!", &SV);
     }






More information about the llvm-commits mailing list