[Mlir-commits] [mlir] 87da4b6 - [mlir][Pass] Check supported op types before running a pass

Matthias Springer llvmlistbot at llvm.org
Tue Jun 20 05:46:03 PDT 2023


Author: Matthias Springer
Date: 2023-06-20T14:40:11+02:00
New Revision: 87da4b6fa6ead0a0bb823536625c596c75516f2c

URL: https://github.com/llvm/llvm-project/commit/87da4b6fa6ead0a0bb823536625c596c75516f2c
DIFF: https://github.com/llvm/llvm-project/commit/87da4b6fa6ead0a0bb823536625c596c75516f2c.diff

LOG: [mlir][Pass] Check supported op types before running a pass

Add extra error checking to prevent passes from being run on unsupported ops through the pass manager infrastructure.

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

Added: 
    

Modified: 
    mlir/lib/Pass/Pass.cpp
    mlir/test/Dialect/Transform/test-pass-application.mlir
    mlir/test/Pass/pipeline-invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index e496a29e9fbe5..c7738a2248a10 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -438,6 +438,9 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
   if (!opInfo->hasTrait<OpTrait::IsIsolatedFromAbove>())
     return op->emitOpError() << "trying to schedule a pass on an operation not "
                                 "marked as 'IsolatedFromAbove'";
+  if (!pass->canScheduleOn(*op->getName().getRegisteredInfo()))
+    return op->emitOpError()
+           << "trying to schedule a pass on an unsupported operation";
 
   // Initialize the pass state with a callback for the pass to dynamically
   // execute a pipeline on the currently visited operation.

diff  --git a/mlir/test/Dialect/Transform/test-pass-application.mlir b/mlir/test/Dialect/Transform/test-pass-application.mlir
index 720f1eb79a1a0..6342657b61280 100644
--- a/mlir/test/Dialect/Transform/test-pass-application.mlir
+++ b/mlir/test/Dialect/Transform/test-pass-application.mlir
@@ -70,3 +70,22 @@ transform.sequence failures(propagate) {
   %1 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
   transform.apply_registered_pass "canonicalize" to %1 {options = "top-down=false"} : (!transform.any_op) -> !transform.any_op
 }
+
+// -----
+
+module {
+  // expected-error @below {{trying to schedule a pass on an unsupported operation}}
+  // expected-note @below {{target op}}
+  func.func @invalid_target_op_type() {
+    return
+  }
+
+  transform.sequence failures(propagate) {
+  ^bb1(%arg1: !transform.any_op):
+    %1 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
+
+    // func-bufferize can be applied only to ModuleOps.
+    // expected-error @below {{pass pipeline failed}}
+    transform.apply_registered_pass "func-bufferize" to %1 : (!transform.any_op) -> !transform.any_op
+  }
+}

diff  --git a/mlir/test/Pass/pipeline-invalid.mlir b/mlir/test/Pass/pipeline-invalid.mlir
index dcc4f0a20c9dc..f9dd4c29dd7f0 100644
--- a/mlir/test/Pass/pipeline-invalid.mlir
+++ b/mlir/test/Pass/pipeline-invalid.mlir
@@ -1,4 +1,9 @@
-// RUN: mlir-opt --no-implicit-module --canonicalize --verify-diagnostics --split-input-file %s
+// RUN: mlir-opt --no-implicit-module \
+// RUN:     --pass-pipeline='any(buffer-deallocation)' --verify-diagnostics \
+// RUN:     --split-input-file %s
+
+// Note: "buffer-deallocation" is a function pass. Any other function pass could
+// be used for this test.
 
 // expected-error at below {{trying to schedule a pass on an operation not marked as 'IsolatedFromAbove'}}
 arith.constant 0
@@ -7,3 +12,8 @@ arith.constant 0
 
 // expected-error at below {{trying to schedule a pass on an unregistered operation}}
 "test.op"() : () -> ()
+
+// -----
+
+// expected-error at below {{trying to schedule a pass on an unsupported operation}}
+module {}


        


More information about the Mlir-commits mailing list