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

Reid Spencer reid at x10sys.com
Wed Oct 18 20:59:01 PDT 2006



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.208 -> 1.208.2.1
ConstantFolding.cpp updated: 1.93 -> 1.93.2.1
Constants.cpp updated: 1.163 -> 1.163.2.1
Instructions.cpp updated: 1.42 -> 1.42.2.1
Type.cpp updated: 1.147 -> 1.147.2.1
Verifier.cpp updated: 1.164 -> 1.164.2.1
---
Log message:

For PR950: http://llvm.org/PR950 :
This commit (on SignlessTypes branch) provides the first Iteration for 
moving LLVM away from Signed types. This patch removes the ConstantSInt
and ConstantUInt classes from Type.h and makes all necessary changes in
LLVM to compensate.


---
Diffs of the changes:  (+254 -201)

 AsmWriter.cpp       |    9 -
 ConstantFolding.cpp |  297 ++++++++++++++++++++++++++++------------------------
 Constants.cpp       |  127 ++++++++++++----------
 Instructions.cpp    |   14 +-
 Type.cpp            |    6 -
 Verifier.cpp        |    2 
 6 files changed, 254 insertions(+), 201 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.208 llvm/lib/VMCore/AsmWriter.cpp:1.208.2.1
--- llvm/lib/VMCore/AsmWriter.cpp:1.208	Tue Oct 17 21:21:12 2006
+++ llvm/lib/VMCore/AsmWriter.cpp	Wed Oct 18 22:57:56 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.93.2.1
--- llvm/lib/VMCore/ConstantFolding.cpp:1.93	Fri Oct 13 12:22:21 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp	Wed Oct 18 22:57:56 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->getRawValue() + 
+                    (BuiltinType)V2->getRawValue();
+    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->getRawValue() - 
+                    (BuiltinType)V2->getRawValue();
+    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->getRawValue() * 
+                    (BuiltinType)V2->getRawValue();
+    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->getRawValue() < (BuiltinType)V2->getRawValue();
     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->getRawValue() == (BuiltinType)V2->getRawValue();
     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->getRawValue()); \
   }
 
   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->getRawValue() == -(BuiltinType)V1->getRawValue())
       return 0;
-    BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+    BuiltinType R = 
+      (BuiltinType)V1->getRawValue() / (BuiltinType)V2->getRawValue();
+    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->getRawValue() == -(BuiltinType)V1->getRawValue())
       return 0;
-    BuiltinType R = (BuiltinType)V1->getValue() % (BuiltinType)V2->getValue();
-    return ConstantClass::get(*Ty, R);
+    BuiltinType R = 
+      (BuiltinType)V1->getRawValue() % (BuiltinType)V2->getRawValue();
+    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->getRawValue() & (BuiltinType)V2->getRawValue();
+    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->getRawValue() | (BuiltinType)V2->getRawValue();
+    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->getRawValue() ^ (BuiltinType)V2->getRawValue();
+    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->getRawValue() << (BuiltinType)V2->getRawValue();
+    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->getRawValue() >> (BuiltinType)V2->getRawValue();
+    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.
@@ -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;
@@ -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.163 llvm/lib/VMCore/Constants.cpp:1.163.2.1
--- llvm/lib/VMCore/Constants.cpp:1.163	Thu Sep 28 18:34:27 2006
+++ llvm/lib/VMCore/Constants.cpp	Wed Oct 18 22:57:56 2006
@@ -66,35 +66,35 @@
     return NullBool;
   }
   case Type::SByteTyID: {
-    static Constant *NullSByte = ConstantSInt::get(Type::SByteTy, 0);
+    static Constant *NullSByte = ConstantInt::get(Type::SByteTy, int8_t(0));
     return NullSByte;
   }
   case Type::UByteTyID: {
-    static Constant *NullUByte = ConstantUInt::get(Type::UByteTy, 0);
+    static Constant *NullUByte = ConstantInt::get(Type::UByteTy, uint8_t(0));
     return NullUByte;
   }
   case Type::ShortTyID: {
-    static Constant *NullShort = ConstantSInt::get(Type::ShortTy, 0);
+    static Constant *NullShort = ConstantInt::get(Type::ShortTy, int16_t(0));
     return NullShort;
   }
   case Type::UShortTyID: {
-    static Constant *NullUShort = ConstantUInt::get(Type::UShortTy, 0);
+    static Constant *NullUShort = ConstantInt::get(Type::UShortTy, uint16_t(0));
     return NullUShort;
   }
   case Type::IntTyID: {
-    static Constant *NullInt = ConstantSInt::get(Type::IntTy, 0);
+    static Constant *NullInt = ConstantInt::get(Type::IntTy, int32_t(0));
     return NullInt;
   }
   case Type::UIntTyID: {
-    static Constant *NullUInt = ConstantUInt::get(Type::UIntTy, 0);
+    static Constant *NullUInt = ConstantInt::get(Type::UIntTy, uint32_t(0));
     return NullUInt;
   }
   case Type::LongTyID: {
-    static Constant *NullLong = ConstantSInt::get(Type::LongTy, 0);
+    static Constant *NullLong = ConstantInt::get(Type::LongTy, int64_t(0));
     return NullLong;
   }
   case Type::ULongTyID: {
-    static Constant *NullULong = ConstantUInt::get(Type::ULongTy, 0);
+    static Constant *NullULong = ConstantInt::get(Type::ULongTy, uint64_t(0));
     return NullULong;
   }
 
@@ -133,7 +133,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:
@@ -157,13 +157,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;
   }
@@ -176,7 +176,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, int32_t(-1));
 
   case Type::UByteTyID:
   case Type::UShortTyID:
@@ -186,20 +186,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
 //===----------------------------------------------------------------------===//
@@ -212,26 +204,21 @@
     Val.Unsigned = V;
 }
 
-ConstantBool::ConstantBool(bool V) 
-  : ConstantIntegral(Type::BoolTy, ConstantBoolVal, V) {
+ConstantIntegral::ConstantIntegral(const Type *Ty, ValueTy VT, int64_t V)
+  : Constant(Ty, VT, 0, 0) {
+    Val.Signed = V;
 }
 
-ConstantInt::ConstantInt(const Type *Ty, ValueTy VT, uint64_t V)
-  : ConstantIntegral(Ty, VT, V) {
+ConstantBool::ConstantBool(bool V) 
+  : ConstantIntegral(Type::BoolTy, ConstantBoolVal, uint64_t(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!");
+ConstantInt::ConstantInt(const Type *Ty, uint64_t V)
+  : ConstantIntegral(Ty, ConstantIntVal, 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, int64_t V)
+  : ConstantIntegral(Ty, ConstantIntVal, V) {
 }
 
 ConstantFP::ConstantFP(const Type *Ty, double V)
@@ -584,23 +571,31 @@
 //===----------------------------------------------------------------------===//
 //                      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::UIntTyID:
+    return (Val > 0) && (Val <= UINT32_MAX);
   case Type::LongTyID:
-    return true;          // This is the largest type...
+    return true; // always true, has to fit in largest type
+  case Type::ULongTyID:
+    return (Val >= 0);
   }
 }
 
-bool ConstantUInt::isValueValidForType(const Type *Ty, uint64_t Val) {
+bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) {
   switch (Ty->getTypeID()) {
   default:
     return false;         // These can't be represented as integers!!!
@@ -608,12 +603,20 @@
     // Unsigned types...
   case Type::UByteTyID:
     return (Val <= UINT8_MAX);
+  case Type::SByteTyID:
+    return (Val <= INT8_MAX);
   case Type::UShortTyID:
     return (Val <= UINT16_MAX);
+  case Type::ShortTyID:
+    return (Val <= INT16_MAX);
   case Type::UIntTyID:
     return (Val <= UINT32_MAX);
+  case Type::IntTyID:
+    return (Val <= INT32_MAX);
   case Type::ULongTyID:
     return true;          // This is the largest type...
+  case Type::LongTyID:
+    return (Val <= INT64_MAX);
   }
 }
 
@@ -729,8 +732,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 =
@@ -887,23 +891,40 @@
   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;
+static ManagedStatic<ValueMap<uint64_t, Type, ConstantInt> > IntConstants;
+
+ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
+}
+
+ConstantInt *ConstantInt::get(const Type *Ty, int32_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
+}
+
+ConstantInt *ConstantInt::get(const Type *Ty, int16_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
+}
+
+ConstantInt *ConstantInt::get(const Type *Ty, int8_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
+}
+
+ConstantInt *ConstantInt::get(const Type *Ty, uint64_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
+}
 
-ConstantSInt *ConstantSInt::get(const Type *Ty, int64_t V) {
-  return SIntConstants->getOrCreate(Ty, V);
+ConstantInt *ConstantInt::get(const Type *Ty, uint32_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
 }
 
-ConstantUInt *ConstantUInt::get(const Type *Ty, uint64_t V) {
-  return UIntConstants->getOrCreate(Ty, V);
+ConstantInt *ConstantInt::get(const Type *Ty, uint16_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
 }
 
-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);
+ConstantInt *ConstantInt::get(const Type *Ty, uint8_t V) {
+  return IntConstants->getOrCreate(Ty, uint64_t(V));
 }
 
 //---- ConstantFP::get() implementation...
@@ -1048,11 +1069,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());
@@ -1416,7 +1437,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);
 }


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.42 llvm/lib/VMCore/Instructions.cpp:1.42.2.1
--- llvm/lib/VMCore/Instructions.cpp:1.42	Thu Oct  5 01:24:58 2006
+++ llvm/lib/VMCore/Instructions.cpp	Wed Oct 18 22:57:56 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.147.2.1
--- llvm/lib/VMCore/Type.cpp:1.147	Sun Oct 15 18:21:12 2006
+++ llvm/lib/VMCore/Type.cpp	Wed Oct 18 22:57:56 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.164.2.1
--- llvm/lib/VMCore/Verifier.cpp:1.164	Sun Sep 17 15:25:45 2006
+++ llvm/lib/VMCore/Verifier.cpp	Wed Oct 18 22:57:56 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