diff options
author | Chris Lattner <sabre@nondot.org> | 2002-05-06 03:01:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-05-06 03:01:37 +0000 |
commit | 4c1061f58c7149e884c81851b8a8f61483264560 (patch) | |
tree | 848dafe23adefdad36b386f6790678c1e742a327 /include/llvm | |
parent | cf4929fa2751c35889bdc892037c1b49721b6741 (diff) | |
download | external_llvm-4c1061f58c7149e884c81851b8a8f61483264560.zip external_llvm-4c1061f58c7149e884c81851b8a8f61483264560.tar.gz external_llvm-4c1061f58c7149e884c81851b8a8f61483264560.tar.bz2 |
Implement constant propogation of shift instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2471 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/ConstantHandling.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/llvm/ConstantHandling.h b/include/llvm/ConstantHandling.h index ef0a810..2203b97 100644 --- a/include/llvm/ConstantHandling.h +++ b/include/llvm/ConstantHandling.h @@ -72,6 +72,8 @@ public: virtual Constant *mul(const Constant *V1, const Constant *V2) const = 0; virtual Constant *div(const Constant *V1, const Constant *V2) const = 0; virtual Constant *rem(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *shl(const Constant *V1, const Constant *V2) const = 0; + virtual Constant *shr(const Constant *V1, const Constant *V2) const = 0; virtual ConstantBool *lessthan(const Constant *V1, const Constant *V2) const = 0; @@ -155,6 +157,16 @@ inline Constant *operator%(const Constant &V1, const Constant &V2) { return ConstRules::get(V1)->rem(&V1, &V2); } +inline Constant *operator<<(const Constant &V1, const Constant &V2) { + assert(V1.getType()->isIntegral() && V2.getType() == Type::UByteTy); + return ConstRules::get(V1)->shl(&V1, &V2); +} + +inline Constant *operator>>(const Constant &V1, const Constant &V2) { + assert(V1.getType()->isIntegral() && V2.getType() == Type::UByteTy); + return ConstRules::get(V1)->shr(&V1, &V2); +} + inline ConstantBool *operator<(const Constant &V1, const Constant &V2) { assert(V1.getType() == V2.getType() && "Constant types must be identical!"); @@ -219,4 +231,14 @@ inline Constant *ConstantFoldBinaryInstruction(unsigned Opcode, return 0; } +inline Constant *ConstantFoldShiftInstruction(unsigned Opcode, + const Constant *V1, + const Constant *V2) { + switch (Opcode) { + case Instruction::Shl: return *V1 << *V2; + case Instruction::Shr: return *V1 >> *V2; + default: return 0; + } +} + #endif |