OpInterfaces are a great mechanism for MLIR extensibility, they allow for passes and analyses to query an Operation for some behaviors.
One limitation at the moment is that it requires every possible operation to be registered by a dialect ahead of time (on dialect loading).
The proposal here is to allow a dialect to act as fallback for operations that are in the dialect but not registered. It can enable implementers of a dialect to provide more extensibility (for example one could have a dialect allowing to define operations in Python and rely on the Python definition to provide metadata allowing to answer side-effects queries).
A concrete use-case for us is the TensorFlow dialect, which is open and dependent on another existing registration system for its operations. This fallback will allow to lookup this registry and still answer the queries for the OpInterfaces on behalf of all the operations in the dialect.
Here is the implementation: ⚙ D93085 Add a mechanism for Dialects to provide a fallback for OpInterface
Most of the code is in OpDefinition.h for the fallback, and Dialect.h for the new virtual method (getRegisteredInterfaceForOp
) available for Dialects to override. Otherwise the rest of the patch is the TableGen support and the testing.
As an example, the TestOpEffectInterfaceFallback
in TestDialect.cpp
is used in the overridden TestDialect::getRegisteredInterfaceForOp
to implement the interface for an unregistered operation.