diff options
author | Chris Lattner <sabre@nondot.org> | 2001-12-13 00:43:03 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-12-13 00:43:03 +0000 |
commit | 156344c890f3f8434cf7cfeb6651fd575633e7e9 (patch) | |
tree | eeb5ec84c7d9f189f82ffc241f93aad4d0d86347 /llvm/lib/VMCore/iOperators.cpp | |
parent | 25450e32c096ebfade2d289d1ff2957da4c808b3 (diff) | |
download | bcm5719-llvm-156344c890f3f8434cf7cfeb6651fd575633e7e9.tar.gz bcm5719-llvm-156344c890f3f8434cf7cfeb6651fd575633e7e9.zip |
Swap operands now preserves the semantics of the binary operator by changing
the opcode of the instruction if possible.
llvm-svn: 1444
Diffstat (limited to 'llvm/lib/VMCore/iOperators.cpp')
-rw-r--r-- | llvm/lib/VMCore/iOperators.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/iOperators.cpp b/llvm/lib/VMCore/iOperators.cpp index 22b6052d469..cb53d5e0344 100644 --- a/llvm/lib/VMCore/iOperators.cpp +++ b/llvm/lib/VMCore/iOperators.cpp @@ -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 |