mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user