summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-10-31 04:14:01 +0000
committerChris Lattner <sabre@nondot.org>2002-10-31 04:14:01 +0000
commitf2da7241f590aaae128ecce7732c6094084df2b6 (patch)
tree67f27d04dff4e39531201334e8166c7ad200da19 /include
parent4932b31dce8fc065a91af2852314ee8c4403ee23 (diff)
downloadllvm-f2da7241f590aaae128ecce7732c6094084df2b6.tar.gz
llvm-f2da7241f590aaae128ecce7732c6094084df2b6.tar.bz2
llvm-f2da7241f590aaae128ecce7732c6094084df2b6.tar.xz
New isAssociative/isCommutative inspection methods, graciously contributed by
Casey Carter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4459 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Instruction.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index 89c64098c3..ca01e30fe5 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -74,6 +74,27 @@ public:
return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
}
+ /// 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 isAssociative() const { return isAssociative(getOpcode(), getType()); }
+ static bool isAssociative(unsigned op, const Type *Ty);
+
+ /// 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 isCommutative() const { return isCommutative(getOpcode()); }
+ static bool isCommutative(unsigned op);
+
+
virtual void print(std::ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast: