///
/// Commutative operators satisfy: (x op y) === (y op x)
///
- /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
+ /// In LLVM, these are the commutative operators, plus SetEQ and SetNE, when
/// applied to any type.
///
bool isCommutative() const { return isCommutative(getOpcode()); }
- static bool isCommutative(unsigned op);
+ static bool isCommutative(unsigned Opcode) {
+ switch (Opcode) {
+ case Add: case FAdd:
+ case Mul: case FMul:
+ case And: case Or: case Xor:
+ return true;
+ default:
+ return false;
+ }
+ }
/// Return true if the instruction is idempotent:
///
/// In LLVM, the And and Or operators are idempotent.
///
bool isIdempotent() const { return isIdempotent(getOpcode()); }
- static bool isIdempotent(unsigned op);
+ static bool isIdempotent(unsigned Opcode) {
+ return Opcode == And || Opcode == Or;
+ }
/// Return true if the instruction is nilpotent:
///
/// In LLVM, the Xor operator is nilpotent.
///
bool isNilpotent() const { return isNilpotent(getOpcode()); }
- static bool isNilpotent(unsigned op);
+ static bool isNilpotent(unsigned Opcode) {
+ return Opcode == Xor;
+ }
/// Return true if this instruction may modify memory.
bool mayWriteToMemory() const;
}
}
-/// Return true if the instruction is commutative:
-///
-/// Commutative operators satisfy: (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 FAdd:
- case Mul:
- case FMul:
- case And:
- case Or:
- case Xor:
- return true;
- default:
- return false;
- }
-}
-
-/// Return true if the instruction is idempotent:
-///
-/// Idempotent operators satisfy: x op x === x
-///
-/// In LLVM, the And and Or operators are idempotent.
-///
-bool Instruction::isIdempotent(unsigned Opcode) {
- return Opcode == And || Opcode == Or;
-}
-
-/// Return true if the instruction is nilpotent:
-///
-/// Nilpotent operators satisfy: x op x === Id,
-///
-/// where Id is the identity for the operator, i.e. a constant such that
-/// x op Id === x and Id op x === x for all x.
-///
-/// In LLVM, the Xor operator is nilpotent.
-///
-bool Instruction::isNilpotent(unsigned Opcode) {
- return Opcode == Xor;
-}
-
Instruction *Instruction::cloneImpl() const {
llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
}