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

Chris Lattner lattner at cs.uiuc.edu
Mon Nov 17 14:20:04 PST 2003


Changes in directory llvm/include/llvm:

ConstantHandling.h updated: 1.34 -> 1.35

---
Log message:

Implement == and != correctly.  Before they would incorrectly return != 
for some constant exprs when they could really be the same value


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

Index: llvm/include/llvm/ConstantHandling.h
diff -u llvm/include/llvm/ConstantHandling.h:1.34 llvm/include/llvm/ConstantHandling.h:1.35
--- llvm/include/llvm/ConstantHandling.h:1.34	Mon Nov 17 13:05:03 2003
+++ llvm/include/llvm/ConstantHandling.h	Mon Nov 17 14:19:26 2003
@@ -48,19 +48,6 @@
 class PointerType;
 
 //===----------------------------------------------------------------------===//
-//  Implement == and != directly...
-//===----------------------------------------------------------------------===//
-
-inline ConstantBool *operator==(const Constant &V1, const Constant &V2) {
-  assert(V1.getType() == V2.getType() && "Constant types must be identical!");
-  return ConstantBool::get(&V1 == &V2);
-}
-
-inline ConstantBool *operator!=(const Constant &V1, const Constant &V2) {
-  return ConstantBool::get(&V1 != &V2);
-}
-
-//===----------------------------------------------------------------------===//
 //  Implement all other operators indirectly through TypeRules system
 //===----------------------------------------------------------------------===//
 
@@ -81,6 +68,8 @@
 
   virtual ConstantBool *lessthan(const Constant *V1, 
                                  const Constant *V2) const = 0;
+  virtual ConstantBool *equalto(const Constant *V1, 
+                                const Constant *V2) const = 0;
 
   // Casting operators.  ick
   virtual ConstantBool *castToBool  (const Constant *V) const = 0;
@@ -195,10 +184,20 @@
   return ConstRules::get(V1, V2).lessthan(&V1, &V2);
 }
 
+inline ConstantBool *operator==(const Constant &V1, const Constant &V2) {
+  assert(V1.getType() == V2.getType() && "Constant types must be identical!");
+  return ConstRules::get(V1, V2).equalto(&V1, &V2);
+}
 
 //===----------------------------------------------------------------------===//
 //  Implement 'derived' operators based on what we already have...
 //===----------------------------------------------------------------------===//
+
+inline ConstantBool *operator!=(const Constant &V1, const Constant &V2) {
+  if (ConstantBool *V = (V1 == V2))
+    return V->inverted();                // !(V1 == V2)
+  return 0;
+}
 
 inline ConstantBool *operator>(const Constant &V1, 
                                const Constant &V2) {





More information about the llvm-commits mailing list