[llvm-commits] CVS: llvm/lib/VMCore/Instruction.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Oct 30 22:15:06 PST 2002
Changes in directory llvm/lib/VMCore:
Instruction.cpp updated: 1.19 -> 1.20
---
Log message:
New isAssociative/isCommutative inspection methods, graciously contributed by
Casey Carter.
---
Diffs of the changes:
Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.19 llvm/lib/VMCore/Instruction.cpp:1.20
--- llvm/lib/VMCore/Instruction.cpp:1.19 Tue Sep 10 10:45:53 2002
+++ llvm/lib/VMCore/Instruction.cpp Wed Oct 30 22:14:01 2002
@@ -97,3 +97,42 @@
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;
+ }
+}
More information about the llvm-commits
mailing list