[all-commits] [llvm/llvm-project] a1d7cd: [MLIR][Python] Impl XOpInterface(s) from Python, w...

Rolf Morel via All-commits all-commits at lists.llvm.org
Thu Feb 12 06:07:34 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a1d7cda1d7ca4983e02727f589952b02626d2dc8
      https://github.com/llvm/llvm-project/commit/a1d7cda1d7ca4983e02727f589952b02626d2dc8
  Author: Rolf Morel <rolf.morel at intel.com>
  Date:   2026-02-12 (Thu, 12 Feb 2026)

  Changed paths:
    M mlir/include/mlir-c/Dialect/Transform.h
    M mlir/include/mlir-c/IR.h
    M mlir/include/mlir-c/Interfaces.h
    M mlir/include/mlir/Bindings/Python/IRCore.h
    A mlir/include/mlir/CAPI/Dialect/Transform.h
    M mlir/include/mlir/CAPI/Interfaces.h
    M mlir/lib/Bindings/Python/DialectTransform.cpp
    M mlir/lib/Bindings/Python/IRCore.cpp
    M mlir/lib/Bindings/Python/IRInterfaces.cpp
    A mlir/lib/Bindings/Python/IRInterfaces.h
    M mlir/lib/Bindings/Python/Rewrite.cpp
    M mlir/lib/Bindings/Python/Rewrite.h
    M mlir/lib/CAPI/Dialect/Transform.cpp
    M mlir/lib/CAPI/IR/IR.cpp
    M mlir/lib/CAPI/Interfaces/Interfaces.cpp
    M mlir/python/CMakeLists.txt
    M mlir/python/mlir/_mlir_libs/__init__.py
    M mlir/python/mlir/dialects/ext.py
    A mlir/test/python/dialects/transform_op_interface.py

  Log Message:
  -----------
  [MLIR][Python] Impl XOpInterface(s) from Python, with X=Transform and X=MemoryEffects (#176920)

Provides the infrastructure for implementing and late-binding
OpInterfaces from Python.

* On the mlir-c API declaration side, each `XOpInterface` has a callback
struct, with a callback for each method and a userdata member (provided
as an arg to each method), and a
`mlirXOpInterfaceAttachFallbackModel(ctx, op_name, callbacks)` func.
* This CAPI is implemented by defining a subclass of
`XOpInterface::FallbackModel` that holds the callback struct and has
each method call the corresponding callback (with userdata as an arg).
Given a callback struct, a new `FallbackModel` is created and attached,
i.e. late bound, to the named op. (MLIR's interface infrastructure is
such that the thus registered `FallbackModel` will be returned in case
the op gets cast to the `XOpInterface`.)
* On the Python side, we expose a stand-in `XOpInterface` base class
which has one (class)method: `XOpInterface.attach(cls, op_name, ctx)`.
Python users subclass this class (`class MyInterfaceImpl(XOpInterface):
...`) and implement the interface's methods (with the right names and
signatures). The user calls `attach` on the subclass
(`MyInterfaceImpl.attach("my_dialect.my_op", ctx)`) which prepares the
callbacks struct _with userdata set to the subclass_ (as we use it to
lookup methods). These callbacks (and userdata) are then registered as
an `XOpInterface::FallbackModel` by
`mlirXOpInterfaceAttachFallbackModel(...)`. From then on the Python
methods will be used to respond to calls to the interface methods
(originating in C++).

This PR enables implementing the TransformOpInterface and the
MemoryEffectsOpInterface, both of which are required for making an op
into a transform op.

Everything besides the above linked code is there to facilitate exposing
the interfaces: the right types for the arguments of the methods are
exposed as are functions/methods for manipulating these arguments (e.g.
specifying side effects on `OpOperand`s and `OpResult`s and being able
to access and set the transform handles associated with args and
results).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list