Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mlir/include/mlir/Pass/Pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ class Pass {
/// This is useful for generic operation passes to add restrictions on the
/// operations they operate on.
virtual bool canScheduleOn(RegisteredOperationName opName) const = 0;
virtual bool canScheduleOn(Operation *op) const {
std::optional<RegisteredOperationName> registeredInfo =
op->getName().getRegisteredInfo();
if (!registeredInfo)
return false;
return canScheduleOn(*registeredInfo);
}

/// Schedule an arbitrary pass pipeline on the provided operation.
/// This can be invoke any time in a pass to dynamic schedule more passes.
Expand Down Expand Up @@ -436,6 +443,7 @@ class InterfacePass : public OperationPass<> {
/// Indicate if the current pass can be scheduled on the given operation type.
/// For an InterfacePass, this checks if the operation implements the given
/// interface.
bool canScheduleOn(Operation *op) const final { return isa<InterfaceT>(op); }
bool canScheduleOn(RegisteredOperationName opName) const final {
return opName.hasInterface<InterfaceT>();
}
Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Pass/Pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
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";
if (!pass->canScheduleOn(op)) {
return op->emitOpError() << "trying to schedule pass '" << pass->getName()
<< "' on an unsupported operation";
}

// Initialize the pass state with a callback for the pass to dynamically
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Dialect/Transform/test-pass-application.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ module attributes {transform.with_named_sequence} {
// -----

module attributes {transform.with_named_sequence} {
// expected-error @below {{trying to schedule a pass on an unsupported operation}}
// expected-error @below {{trying to schedule pass 'DuplicateFunctionEliminationPass' on an unsupported operation}}
// expected-note @below {{target op}}
func.func @invalid_target_op_type() {
return
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Pass/invalid-unsupported-operation.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: mlir-opt %s -test-print-liveness -split-input-file -verify-diagnostics

// Unnamed modules do not implement SymbolOpInterface.
// expected-error @+1 {{trying to schedule pass '(anonymous namespace)::TestLivenessPass' on an unsupported operation}}
module {}

// -----

// Named modules implement SymbolOpInterface.
module @named_module {}
2 changes: 1 addition & 1 deletion mlir/test/Pass/pipeline-invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ arith.constant 0

// -----

// expected-error@below {{trying to schedule a pass on an unsupported operation}}
// expected-error@below {{trying to schedule pass '(anonymous namespace)::TestFunctionPass' on an unsupported operation}}
module {}