forked from OSchip/llvm-project
Swap operands now preserves the semantics of the binary operator by changing
the opcode of the instruction if possible. llvm-svn: 1444
This commit is contained in:
parent
25450e32c0
commit
156344c890
|
@ -127,10 +127,14 @@ public:
|
||||||
|
|
||||||
virtual const char *getOpcodeName() const = 0;
|
virtual const char *getOpcodeName() const = 0;
|
||||||
|
|
||||||
// swapOperands - Exchange the two operands to this instruction
|
// swapOperands - Exchange the two operands to this instruction.
|
||||||
void swapOperands() {
|
// This instruction is safe to use on any binary instruction and
|
||||||
swap(Operands[0], Operands[1]);
|
// does not modify the semantics of the instruction. If the
|
||||||
}
|
// instruction is order dependant (SetLT f.e.) the opcode is
|
||||||
|
// changed. If the instruction cannot be reversed (ie, it's a Div),
|
||||||
|
// then return true.
|
||||||
|
//
|
||||||
|
bool swapOperands();
|
||||||
|
|
||||||
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
static inline bool classof(const BinaryOperator *) { return true; }
|
static inline bool classof(const BinaryOperator *) { return true; }
|
||||||
|
|
|
@ -53,6 +53,32 @@ BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swapOperands - Exchange the two operands to this instruction. This
|
||||||
|
// instruction is safe to use on any binary instruction and does not
|
||||||
|
// modify the semantics of the instruction. If the instruction is
|
||||||
|
// order dependant (SetLT f.e.) the opcode is changed.
|
||||||
|
//
|
||||||
|
bool BinaryOperator::swapOperands() {
|
||||||
|
switch (getOpcode()) {
|
||||||
|
// Instructions that don't need opcode modification
|
||||||
|
case Add: case Mul:
|
||||||
|
case And: case Xor:
|
||||||
|
case Or:
|
||||||
|
case SetEQ: case SetNE:
|
||||||
|
break;
|
||||||
|
// Instructions that need opcode modification
|
||||||
|
case SetGT: iType = SetLT; break;
|
||||||
|
case SetLT: iType = SetGT; break;
|
||||||
|
case SetGE: iType = SetLE; break;
|
||||||
|
case SetLE: iType = SetGE; break;
|
||||||
|
// Error on the side of caution
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
swap(Operands[0], Operands[1]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// GenericBinaryInst Class
|
// GenericBinaryInst Class
|
||||||
|
|
Loading…
Reference in New Issue