Skip to content

Commit 25a8fb6

Browse files
[mlir][Pass] Fix crash when applying a pass to an optional interface
1 parent 35a95fe commit 25a8fb6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

mlir/include/mlir/Pass/Pass.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ class Pass {
193193
/// This is useful for generic operation passes to add restrictions on the
194194
/// operations they operate on.
195195
virtual bool canScheduleOn(RegisteredOperationName opName) const = 0;
196+
virtual bool canScheduleOn(Operation *op) const {
197+
std::optional<RegisteredOperationName> registeredInfo =
198+
op->getName().getRegisteredInfo();
199+
if (!registeredInfo)
200+
return false;
201+
return canScheduleOn(*registeredInfo);
202+
}
196203

197204
/// Schedule an arbitrary pass pipeline on the provided operation.
198205
/// This can be invoke any time in a pass to dynamic schedule more passes.
@@ -436,6 +443,7 @@ class InterfacePass : public OperationPass<> {
436443
/// Indicate if the current pass can be scheduled on the given operation type.
437444
/// For an InterfacePass, this checks if the operation implements the given
438445
/// interface.
446+
bool canScheduleOn(Operation *op) const final { return isa<InterfaceT>(op); }
439447
bool canScheduleOn(RegisteredOperationName opName) const final {
440448
return opName.hasInterface<InterfaceT>();
441449
}

mlir/lib/Pass/Pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
559559
return op->emitOpError() << "trying to schedule a pass on an operation not "
560560
"marked as 'IsolatedFromAbove'";
561561
}
562-
if (!pass->canScheduleOn(*op->getName().getRegisteredInfo())) {
562+
if (!pass->canScheduleOn(op)) {
563563
return op->emitOpError()
564564
<< "trying to schedule a pass on an unsupported operation";
565565
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
// RUN: mlir-opt %s -test-print-liveness -split-input-file -verify-diagnostics
3+
4+
// Unnamed modules do not implement SymbolOpInterface.
5+
// expected-error @+1 {{trying to schedule a pass on an unsupported operation}}
6+
module {}
7+
8+
// -----
9+
10+
// Named modules implement SymbolOpInterface.
11+
module @named_module {}

0 commit comments

Comments
 (0)