From: Chris Lattner Date: Wed, 23 Jul 2003 17:21:17 +0000 (+0000) Subject: Add support for ~ operator on constants X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=30780ccf15fd098afe5c47ae8e013dd832ed2dde;p=oota-llvm.git Add support for ~ operator on constants git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7258 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ConstantHandling.h b/include/llvm/ConstantHandling.h index 2401ad7596b..66719cda8e5 100644 --- a/include/llvm/ConstantHandling.h +++ b/include/llvm/ConstantHandling.h @@ -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) { diff --git a/lib/VMCore/ConstantFold.h b/lib/VMCore/ConstantFold.h index 2401ad7596b..66719cda8e5 100644 --- a/lib/VMCore/ConstantFold.h +++ b/lib/VMCore/ConstantFold.h @@ -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) { diff --git a/lib/VMCore/ConstantFolding.h b/lib/VMCore/ConstantFolding.h index 2401ad7596b..66719cda8e5 100644 --- a/lib/VMCore/ConstantFolding.h +++ b/lib/VMCore/ConstantFolding.h @@ -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) {