[MLIR] Simplify predicate in Matchers.h, NFC
authorChris Lattner <clattner@nondot.org>
Sun, 15 Jan 2023 06:05:54 +0000 (22:05 -0800)
committerChris Lattner <clattner@nondot.org>
Sun, 15 Jan 2023 17:31:42 +0000 (09:31 -0800)
The ConstantLike trait already static_asserts that operations
implementing it have a single result and zero operands, so we
don't need to redundantly check in Matchers.h

The static assert is in `class ConstantLike` in OpDefinition.h

Differential Revision: https://reviews.llvm.org/D141783

mlir/include/mlir/IR/Matchers.h

index 78e5099..374f05a 100644 (file)
@@ -47,16 +47,9 @@ struct attr_value_binder {
   }
 };
 
-/// Check to see if the specified operation is ConstantLike.  This includes some
-/// quick filters to avoid a semi-expensive test in the common case.
-static bool isConstantLike(Operation *op) {
-  return op->getNumOperands() == 0 && op->getNumResults() == 1 &&
-         op->hasTrait<OpTrait::ConstantLike>();
-}
-
 /// The matcher that matches operations that have the `ConstantLike` trait.
 struct constant_op_matcher {
-  bool match(Operation *op) { return isConstantLike(op); }
+  bool match(Operation *op) { return op->hasTrait<OpTrait::ConstantLike>(); }
 };
 
 /// The matcher that matches operations that have the `ConstantLike` trait, and
@@ -72,7 +65,7 @@ struct constant_op_binder {
   constant_op_binder() : bind_value(nullptr) {}
 
   bool match(Operation *op) {
-    if (!isConstantLike(op))
+    if (!op->hasTrait<OpTrait::ConstantLike>())
       return false;
 
     // Fold the constant to an attribute.