[Mlir-commits] [mlir] 18b7249 - [MLIR] Simplify predicate in Matchers.h, NFC

Chris Lattner llvmlistbot at llvm.org
Sun Jan 15 09:31:52 PST 2023


Author: Chris Lattner
Date: 2023-01-15T09:31:42-08:00
New Revision: 18b72494d345ccbdef4ba21e03749e87ec5dd7c3

URL: https://github.com/llvm/llvm-project/commit/18b72494d345ccbdef4ba21e03749e87ec5dd7c3
DIFF: https://github.com/llvm/llvm-project/commit/18b72494d345ccbdef4ba21e03749e87ec5dd7c3.diff

LOG: [MLIR] Simplify predicate in Matchers.h, NFC

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/Matchers.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Matchers.h b/mlir/include/mlir/IR/Matchers.h
index 78e5099358cb1..374f05ab49c5f 100644
--- a/mlir/include/mlir/IR/Matchers.h
+++ b/mlir/include/mlir/IR/Matchers.h
@@ -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.


        


More information about the Mlir-commits mailing list