Extend struct and array constants to support isNullValue
authorChris Lattner <sabre@nondot.org>
Thu, 6 Mar 2003 21:02:43 +0000 (21:02 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 6 Mar 2003 21:02:43 +0000 (21:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5719 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constants.h

index ec6345846e334358fb891593d58884d22379547d..6c1b8eb1e6148a7c0f5a2a4c9a34c8f7cdcb9d71 100644 (file)
@@ -289,7 +289,14 @@ public:
 
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
-  virtual bool isNullValue() const { return false; }
+  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; 
+    return true;
+  }
 
   virtual void destroyConstant();
   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);
@@ -328,7 +335,14 @@ public:
 
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
-  virtual bool isNullValue() const { return false; }
+  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; 
+    return true;
+  }
 
   virtual void destroyConstant();
   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To);