[llvm-commits] CVS: llvm/include/llvm/Constants.h

Chris Lattner lattner at cs.uiuc.edu
Wed Jan 14 11:07:02 PST 2004


Changes in directory llvm/include/llvm:

Constants.h updated: 1.37 -> 1.38

---
Log message:

Add new ConstantArray::isString(), as the conditions for using getString()
are complex enough to check that it should be a seperate method.

While I'm here, improve ConstantArray::getNullValue a bit, though the
FIXME is still quite valid.


---
Diffs of the changes:  (+13 -6)

Index: llvm/include/llvm/Constants.h
diff -u llvm/include/llvm/Constants.h:1.37 llvm/include/llvm/Constants.h:1.38
--- llvm/include/llvm/Constants.h:1.37	Mon Jan 12 13:37:26 2004
+++ llvm/include/llvm/Constants.h	Wed Jan 14 11:06:21 2004
@@ -304,9 +304,12 @@
     return reinterpret_cast<const ArrayType*>(Value::getType());
   }
 
-  /// getAsString - If the sub-element type of this array is either sbyte or
-  /// ubyte, then this method converts the array to an std::string and returns
-  /// it.  Otherwise, it asserts out.
+  /// isString - This method returns true if the array is an array of sbyte or
+  /// ubyte, and if the elements of the array are all ConstantInt's.
+  bool isString() const;
+
+  /// getAsString - If this array is isString(), then this method converts the
+  /// array to an std::string and returns it.  Otherwise, it asserts out.
   ///
   std::string getAsString() const;
 
@@ -319,9 +322,13 @@
   virtual bool isNullValue() const {
     // FIXME: This should be made to be MUCH faster.  Just check against well
     // known null value!
-    for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
-      if (!cast<Constant>(getOperand(i))->isNullValue())
-        return false; 
+    if (getNumOperands()) {
+      const Constant *First = cast<Constant>(getOperand(0));
+      if (!First->isNullValue()) return false;
+      for (unsigned i = 1, e = getNumOperands(); i != e; ++i)
+        if (cast<Constant>(getOperand(i)) != First)
+          return false; 
+    }
     return true;
   }
 





More information about the llvm-commits mailing list