mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
New isAssociative/isCommutative inspection methods, graciously contributed by
Casey Carter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4459 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4932b31dce
commit
f2da7241f5
@ -74,6 +74,27 @@ public:
|
||||
return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
|
||||
}
|
||||
|
||||
/// isAssociative - Return true if the instruction is associative:
|
||||
///
|
||||
/// Associative operators satisfy: x op (y op z) === (x op y) op z)
|
||||
///
|
||||
/// In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when
|
||||
/// not applied to floating point types.
|
||||
///
|
||||
bool isAssociative() const { return isAssociative(getOpcode(), getType()); }
|
||||
static bool isAssociative(unsigned op, const Type *Ty);
|
||||
|
||||
/// isCommutative - Return true if the instruction is commutative:
|
||||
///
|
||||
/// Commutative operators satistify: (x op y) === (y op x)
|
||||
///
|
||||
/// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
|
||||
/// applied to any type.
|
||||
///
|
||||
bool isCommutative() const { return isCommutative(getOpcode()); }
|
||||
static bool isCommutative(unsigned op);
|
||||
|
||||
|
||||
virtual void print(std::ostream &OS) const;
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
|
@ -97,3 +97,42 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// isAssociative - Return true if the instruction is associative:
|
||||
///
|
||||
/// Associative operators satisfy: x op (y op z) === (x op y) op z)
|
||||
///
|
||||
/// In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when not
|
||||
/// applied to floating point types.
|
||||
///
|
||||
bool Instruction::isAssociative(unsigned Opcode, const Type *Ty) {
|
||||
if (Opcode == Add || Opcode == Mul ||
|
||||
Opcode == And || Opcode == Or || Opcode == Xor) {
|
||||
// Floating point operations do not associate!
|
||||
return !Ty->isFloatingPoint();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// isCommutative - Return true if the instruction is commutative:
|
||||
///
|
||||
/// Commutative operators satistify: (x op y) === (y op x)
|
||||
///
|
||||
/// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
|
||||
/// applied to any type.
|
||||
///
|
||||
bool Instruction::isCommutative(unsigned op) {
|
||||
switch (op) {
|
||||
case Add:
|
||||
case Mul:
|
||||
case And:
|
||||
case Or:
|
||||
case Xor:
|
||||
case SetEQ:
|
||||
case SetNE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user