Skip to content

Commit 87da4b6

Browse files
[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
1 parent 149f309 commit 87da4b6

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

mlir/lib/Pass/Pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
438438
if (!opInfo->hasTrait<OpTrait::IsIsolatedFromAbove>())
439439
return op->emitOpError() << "trying to schedule a pass on an operation not "
440440
"marked as 'IsolatedFromAbove'";
441+
if (!pass->canScheduleOn(*op->getName().getRegisteredInfo()))
442+
return op->emitOpError()
443+
<< "trying to schedule a pass on an unsupported operation";
441444

442445
// Initialize the pass state with a callback for the pass to dynamically
443446
// execute a pipeline on the currently visited operation.

mlir/test/Dialect/Transform/test-pass-application.mlir

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,22 @@ transform.sequence failures(propagate) {
7070
%1 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
7171
transform.apply_registered_pass "canonicalize" to %1 {options = "top-down=false"} : (!transform.any_op) -> !transform.any_op
7272
}
73+
74+
// -----
75+
76+
module {
77+
// expected-error @below {{trying to schedule a pass on an unsupported operation}}
78+
// expected-note @below {{target op}}
79+
func.func @invalid_target_op_type() {
80+
return
81+
}
82+
83+
transform.sequence failures(propagate) {
84+
^bb1(%arg1: !transform.any_op):
85+
%1 = transform.structured.match ops{["func.func"]} in %arg1 : (!transform.any_op) -> !transform.any_op
86+
87+
// func-bufferize can be applied only to ModuleOps.
88+
// expected-error @below {{pass pipeline failed}}
89+
transform.apply_registered_pass "func-bufferize" to %1 : (!transform.any_op) -> !transform.any_op
90+
}
91+
}

mlir/test/Pass/pipeline-invalid.mlir

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
// RUN: mlir-opt --no-implicit-module --canonicalize --verify-diagnostics --split-input-file %s
1+
// RUN: mlir-opt --no-implicit-module \
2+
// RUN: --pass-pipeline='any(buffer-deallocation)' --verify-diagnostics \
3+
// RUN: --split-input-file %s
4+
5+
// Note: "buffer-deallocation" is a function pass. Any other function pass could
6+
// be used for this test.
27

38
// expected-error@below {{trying to schedule a pass on an operation not marked as 'IsolatedFromAbove'}}
49
arith.constant 0
@@ -7,3 +12,8 @@ arith.constant 0
712

813
// expected-error@below {{trying to schedule a pass on an unregistered operation}}
914
"test.op"() : () -> ()
15+
16+
// -----
17+
18+
// expected-error@below {{trying to schedule a pass on an unsupported operation}}
19+
module {}

0 commit comments

Comments
 (0)