You no longer have to delete constants! They are located in a global
authorChris Lattner <sabre@nondot.org>
Fri, 7 Sep 2001 16:29:18 +0000 (16:29 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 7 Sep 2001 16:29:18 +0000 (16:29 +0000)
constant pool instead of in local ones.

Change bool handling to prevent modification of bool values

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

include/llvm/ConstantHandling.h
lib/VMCore/ConstantFold.h
lib/VMCore/ConstantFolding.h

index 501f726a85b6e87b3437704f09e5c4289a5704d0..453c3e88b186809c9d5b7d0da89d4fce58cedfd8 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 //
-// WARNING: These operators return pointers to newly 'new'd objects.  You MUST
-//          make sure to free them if you don't want them hanging around. Also,
-//          note that these may return a null object if I don't know how to 
-//          perform those operations on the specified constant types.
+// WARNING: These operators may return a null object if I don't know how to 
+//          perform the specified operation on the specified constant types.
 //
 //===----------------------------------------------------------------------===//
 //
 namespace opt {
 
 //===----------------------------------------------------------------------===//
-//  Implement == directly...
+//  Implement == and != directly...
 //===----------------------------------------------------------------------===//
 
 inline ConstPoolBool *operator==(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
   assert(V1.getType() == V2.getType() && "Constant types must be identical!");
-  return new ConstPoolBool(V1.equals(&V2));
+  return ConstPoolBool::get(&V1 == &V2);
+}
+
+inline ConstPoolBool *operator!=(const ConstPoolVal &V1, 
+                                 const ConstPoolVal &V2) {
+  return ConstPoolBool::get(&V1 != &V2);
 }
 
 //===----------------------------------------------------------------------===//
@@ -156,25 +159,14 @@ inline ConstPoolBool *operator>(const ConstPoolVal &V1,
   return V2 < V1;
 }
 
-inline ConstPoolBool *operator!=(const ConstPoolVal &V1, 
-                                 const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 == V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;     // !(V1 == V2)
-}
-
 inline ConstPoolBool *operator>=(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 < V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;      // !(V1 < V2)
+  return (V1 < V2)->inverted();      // !(V1 < V2)
 }
 
 inline ConstPoolBool *operator<=(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 > V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;      // !(V1 > V2)
+  return (V1 > V2)->inverted();      // !(V1 > V2)
 }
 
 
index 501f726a85b6e87b3437704f09e5c4289a5704d0..453c3e88b186809c9d5b7d0da89d4fce58cedfd8 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 //
-// WARNING: These operators return pointers to newly 'new'd objects.  You MUST
-//          make sure to free them if you don't want them hanging around. Also,
-//          note that these may return a null object if I don't know how to 
-//          perform those operations on the specified constant types.
+// WARNING: These operators may return a null object if I don't know how to 
+//          perform the specified operation on the specified constant types.
 //
 //===----------------------------------------------------------------------===//
 //
 namespace opt {
 
 //===----------------------------------------------------------------------===//
-//  Implement == directly...
+//  Implement == and != directly...
 //===----------------------------------------------------------------------===//
 
 inline ConstPoolBool *operator==(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
   assert(V1.getType() == V2.getType() && "Constant types must be identical!");
-  return new ConstPoolBool(V1.equals(&V2));
+  return ConstPoolBool::get(&V1 == &V2);
+}
+
+inline ConstPoolBool *operator!=(const ConstPoolVal &V1, 
+                                 const ConstPoolVal &V2) {
+  return ConstPoolBool::get(&V1 != &V2);
 }
 
 //===----------------------------------------------------------------------===//
@@ -156,25 +159,14 @@ inline ConstPoolBool *operator>(const ConstPoolVal &V1,
   return V2 < V1;
 }
 
-inline ConstPoolBool *operator!=(const ConstPoolVal &V1, 
-                                 const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 == V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;     // !(V1 == V2)
-}
-
 inline ConstPoolBool *operator>=(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 < V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;      // !(V1 < V2)
+  return (V1 < V2)->inverted();      // !(V1 < V2)
 }
 
 inline ConstPoolBool *operator<=(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 > V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;      // !(V1 > V2)
+  return (V1 > V2)->inverted();      // !(V1 > V2)
 }
 
 
index 501f726a85b6e87b3437704f09e5c4289a5704d0..453c3e88b186809c9d5b7d0da89d4fce58cedfd8 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 //
-// WARNING: These operators return pointers to newly 'new'd objects.  You MUST
-//          make sure to free them if you don't want them hanging around. Also,
-//          note that these may return a null object if I don't know how to 
-//          perform those operations on the specified constant types.
+// WARNING: These operators may return a null object if I don't know how to 
+//          perform the specified operation on the specified constant types.
 //
 //===----------------------------------------------------------------------===//
 //
 namespace opt {
 
 //===----------------------------------------------------------------------===//
-//  Implement == directly...
+//  Implement == and != directly...
 //===----------------------------------------------------------------------===//
 
 inline ConstPoolBool *operator==(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
   assert(V1.getType() == V2.getType() && "Constant types must be identical!");
-  return new ConstPoolBool(V1.equals(&V2));
+  return ConstPoolBool::get(&V1 == &V2);
+}
+
+inline ConstPoolBool *operator!=(const ConstPoolVal &V1, 
+                                 const ConstPoolVal &V2) {
+  return ConstPoolBool::get(&V1 != &V2);
 }
 
 //===----------------------------------------------------------------------===//
@@ -156,25 +159,14 @@ inline ConstPoolBool *operator>(const ConstPoolVal &V1,
   return V2 < V1;
 }
 
-inline ConstPoolBool *operator!=(const ConstPoolVal &V1, 
-                                 const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 == V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;     // !(V1 == V2)
-}
-
 inline ConstPoolBool *operator>=(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 < V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;      // !(V1 < V2)
+  return (V1 < V2)->inverted();      // !(V1 < V2)
 }
 
 inline ConstPoolBool *operator<=(const ConstPoolVal &V1, 
                                  const ConstPoolVal &V2) {
-  ConstPoolBool *Result = V1 > V2;
-  Result->setValue(!Result->getValue());     // Invert value
-  return Result;      // !(V1 > V2)
+  return (V1 > V2)->inverted();      // !(V1 > V2)
 }