[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp

Reid Spencer reid at x10sys.com
Thu Mar 1 11:30:51 PST 2007



Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.225 -> 1.226
---
Log message:

Drop the ConstantInt(const Type&, const APInt&) constructor. It is
redundant and more verbose than the ConstantInt(const APInt&) constructor.


---
Diffs of the changes:  (+9 -14)

 Constants.cpp |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.225 llvm/lib/VMCore/Constants.cpp:1.226
--- llvm/lib/VMCore/Constants.cpp:1.225	Wed Feb 28 13:50:21 2007
+++ llvm/lib/VMCore/Constants.cpp	Thu Mar  1 13:30:34 2007
@@ -115,7 +115,7 @@
 // Static constructor to create an integral constant with all bits set
 ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {
   if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
-    return ConstantInt::get(Ty, APInt::getAllOnesValue(ITy->getBitWidth()));
+    return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
   return 0;
 }
 
@@ -192,22 +192,21 @@
                  DenseMapAPIntKeyInfo> IntMapTy;
 static ManagedStatic<IntMapTy> IntConstants;
 
-ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) {
+ConstantInt *ConstantInt::get(const Type *Ty, uint64_t V) {
   const IntegerType *ITy = cast<IntegerType>(Ty);
-  APInt Tmp(ITy->getBitWidth(), V);
-  return get(Ty, Tmp);
+  return get(APInt(ITy->getBitWidth(), V));
 }
 
-// Get a ConstantInt from a Type and APInt. Note that the value stored in 
-// the DenseMap as the key is a DensMapAPIntKeyInfo::KeyTy which has provided
+// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap 
+// as the key, is a DensMapAPIntKeyInfo::KeyTy which has provided the
 // operator== and operator!= to ensure that the DenseMap doesn't attempt to
 // compare APInt's of different widths, which would violate an APInt class
 // invariant which generates an assertion.
-ConstantInt *ConstantInt::get(const Type *Ty, const APInt& V) {
-  const IntegerType *ITy = cast<IntegerType>(Ty);
-  assert(ITy->getBitWidth() == V.getBitWidth() && "Invalid type for constant");
+ConstantInt *ConstantInt::get(const APInt& V) {
+  // Get the corresponding integer type for the bit width of the value.
+  const IntegerType *ITy = IntegerType::get(V.getBitWidth());
   // get an existing value or the insertion position
-  DenseMapAPIntKeyInfo::KeyTy Key(V, Ty);
+  DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
   ConstantInt *&Slot = (*IntConstants)[Key]; 
   // if it exists, return it.
   if (Slot)
@@ -216,10 +215,6 @@
   return Slot = new ConstantInt(ITy, V);
 }
 
-ConstantInt *ConstantInt::get(const APInt &V) {
-  return ConstantInt::get(IntegerType::get(V.getBitWidth()), V);
-}
-
 //===----------------------------------------------------------------------===//
 //                                ConstantFP
 //===----------------------------------------------------------------------===//






More information about the llvm-commits mailing list