Add support for ~ operator on constants
authorChris Lattner <sabre@nondot.org>
Wed, 23 Jul 2003 17:21:17 +0000 (17:21 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 23 Jul 2003 17:21:17 +0000 (17:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7258 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2401ad7596b2b5ff7c7e7531bb03a69083844a89..66719cda8e5687294eb87f9e8f171373c432d5e4 100644 (file)
@@ -125,6 +125,12 @@ private:
   ConstRules &operator=(const ConstRules &);  // Do not implement
 };
 
+// Unary operators...
+inline Constant *operator~(const Constant &V) {
+  assert(V.getType()->isIntegral() && "Cannot invert non-intergral constant!");
+  return ConstRules::get(V, V)->op_xor(&V,
+                                    ConstantInt::getAllOnesValue(V.getType()));
+}
 
 // Standard binary operators...
 inline Constant *operator+(const Constant &V1, const Constant &V2) {
index 2401ad7596b2b5ff7c7e7531bb03a69083844a89..66719cda8e5687294eb87f9e8f171373c432d5e4 100644 (file)
@@ -125,6 +125,12 @@ private:
   ConstRules &operator=(const ConstRules &);  // Do not implement
 };
 
+// Unary operators...
+inline Constant *operator~(const Constant &V) {
+  assert(V.getType()->isIntegral() && "Cannot invert non-intergral constant!");
+  return ConstRules::get(V, V)->op_xor(&V,
+                                    ConstantInt::getAllOnesValue(V.getType()));
+}
 
 // Standard binary operators...
 inline Constant *operator+(const Constant &V1, const Constant &V2) {
index 2401ad7596b2b5ff7c7e7531bb03a69083844a89..66719cda8e5687294eb87f9e8f171373c432d5e4 100644 (file)
@@ -125,6 +125,12 @@ private:
   ConstRules &operator=(const ConstRules &);  // Do not implement
 };
 
+// Unary operators...
+inline Constant *operator~(const Constant &V) {
+  assert(V.getType()->isIntegral() && "Cannot invert non-intergral constant!");
+  return ConstRules::get(V, V)->op_xor(&V,
+                                    ConstantInt::getAllOnesValue(V.getType()));
+}
 
 // Standard binary operators...
 inline Constant *operator+(const Constant &V1, const Constant &V2) {