add a Constant::getAllOnesValue helper function, which works on integers
authorChris Lattner <sabre@nondot.org>
Fri, 15 Jun 2007 06:10:53 +0000 (06:10 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 15 Jun 2007 06:10:53 +0000 (06:10 +0000)
AND vectors.

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

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

index bfe65a6faa1549278cccd3d71e94c8c04a7041a3..d925fdb618ed96871847dcb0c9473d2dbea03478 100644 (file)
@@ -48,6 +48,11 @@ public:
   ///
   static Constant *getNullValue(const Type *Ty);
 
+  /// Static constructor to get a '-1' constant.  This supports integers and
+  /// vectors.
+  ///
+  static Constant *getAllOnesValue(const Type *Ty);
+  
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const = 0;
index 55e1539b5c1589c2dc4e2f7a6a599b92c603752d..e171011159c972a15727196c5f14d83efae4c25e 100644 (file)
@@ -122,6 +122,11 @@ Constant *Constant::getNullValue(const Type *Ty) {
   }
 }
 
+Constant *Constant::getAllOnesValue(const Type *Ty) {
+  if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
+    return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
+  return ConstantVector::getAllOnesValue(cast<VectorType>(Ty));
+}
 
 // Static constructor to create an integral constant with all bits set
 ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {