Drop the ConstantInt(const Type&, const APInt&) constructor. It is
authorReid Spencer <rspencer@reidspencer.com>
Thu, 1 Mar 2007 19:30:34 +0000 (19:30 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Thu, 1 Mar 2007 19:30:34 +0000 (19:30 +0000)
redundant and more verbose than the ConstantInt(const APInt&) constructor.

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

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

index dd8343d6b3820ec924126511937d029a3d24d8b4..21d9dca7a7e808d3e99dcfc077bb547563a715c0 100644 (file)
@@ -90,12 +90,11 @@ public:
   }
 
   /// Return a ConstantInt with the specified value for the specified type. The
-  /// value V will be canonicalized to a uint64_t but accessing it with either
-  /// getSExtValue() or getZExtValue() (ConstantInt) will yield the correct
-  /// sized/signed value for the type Ty.
+  /// value V will be canonicalized to a an unsigned APInt. Accessing it with
+  /// either getSExtValue() or getZExtValue() will yield a correctly sized and
+  /// signed value for the type Ty.
   /// @brief Get a ConstantInt for a specific value.
-  static ConstantInt *get(const Type *Ty, int64_t V);
-  static ConstantInt *get(const Type *Ty, const APInt& V);
+  static ConstantInt *get(const Type *Ty, uint64_t V);
 
   /// Return a ConstantInt with the specified value and an implied Type. The
   /// type is the integer type that corresponds to the bit width of the value.
index 29f096364f49f57ad8d28455aa5bf323dda16c59..9d9cc5a2ec0348c0c5550ab179dee3104aac7bad 100644 (file)
@@ -115,7 +115,7 @@ Constant *Constant::getNullValue(const Type *Ty) {
 // 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 @@ typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
                  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 @@ ConstantInt *ConstantInt::get(const Type *Ty, const APInt& V) {
   return Slot = new ConstantInt(ITy, V);
 }
 
-ConstantInt *ConstantInt::get(const APInt &V) {
-  return ConstantInt::get(IntegerType::get(V.getBitWidth()), V);
-}
-
 //===----------------------------------------------------------------------===//
 //                                ConstantFP
 //===----------------------------------------------------------------------===//