diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -438,6 +438,9 @@ if (!opInfo->hasTrait()) 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 --- a/mlir/test/Dialect/Transform/test-pass-application.mlir +++ b/mlir/test/Dialect/Transform/test-pass-application.mlir @@ -70,3 +70,22 @@ %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 --- 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@below {{trying to schedule a pass on an operation not marked as 'IsolatedFromAbove'}} arith.constant 0 @@ -7,3 +12,8 @@ // expected-error@below {{trying to schedule a pass on an unregistered operation}} "test.op"() : () -> () + +// ----- + +// expected-error@below {{trying to schedule a pass on an unsupported operation}} +module {}