Implement a convenience method to construct a ConstantInt directly from an
authorReid Spencer <rspencer@reidspencer.com>
Wed, 28 Feb 2007 19:50:21 +0000 (19:50 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Wed, 28 Feb 2007 19:50:21 +0000 (19:50 +0000)
APInt. The implied type is the integer type that corresponds to the bit
width of the APInt.

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

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

index 6ae7a528710f7b1e2a4ee6ac7032a3c6e00e648f..dd8343d6b3820ec924126511937d029a3d24d8b4 100644 (file)
@@ -97,6 +97,10 @@ public:
   static ConstantInt *get(const Type *Ty, int64_t V);
   static ConstantInt *get(const Type *Ty, const APInt& 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.
+  static ConstantInt *get(const APInt &V);
+
   /// getType - Specialize the getType() method to always return an IntegerType,
   /// which reduces the amount of casting needed in parts of the compiler.
   ///
index 37e0abec988767c5d33bd6804d09c482752e7738..29f096364f49f57ad8d28455aa5bf323dda16c59 100644 (file)
@@ -216,6 +216,10 @@ 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
 //===----------------------------------------------------------------------===//