Implement constant propogation of shift instructions

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2471 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-05-06 03:01:37 +00:00
parent cf4929fa27
commit 4c1061f58c
5 changed files with 108 additions and 7 deletions

View File

@@ -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