summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-12-13 00:43:03 +0000
committerChris Lattner <sabre@nondot.org>2001-12-13 00:43:03 +0000
commit9a49b210c1ae2c619ecd969b5ec17a68690928a9 (patch)
treed14ae9d5cecaa497dcd307278357681517c334a4 /lib
parent82d18aa0e42a4858c2cb7c15934cc3e567432490 (diff)
downloadllvm-9a49b210c1ae2c619ecd969b5ec17a68690928a9.tar.gz
llvm-9a49b210c1ae2c619ecd969b5ec17a68690928a9.tar.bz2
llvm-9a49b210c1ae2c619ecd969b5ec17a68690928a9.tar.xz
Swap operands now preserves the semantics of the binary operator by changing
the opcode of the instruction if possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1444 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/iOperators.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/VMCore/iOperators.cpp b/lib/VMCore/iOperators.cpp
index 22b6052d46..cb53d5e034 100644
--- a/lib/VMCore/iOperators.cpp
+++ b/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