[Mlir-commits] [mlir] [MLIR][Python] Add a DSL for defining IRDL dialects in Python bindings (PR #169045)

Rolf Morel llvmlistbot at llvm.org
Sun Nov 30 05:20:27 PST 2025


rolfmorel wrote:

> Does this (eventually) imply extending the IRDL dialect to introduce concepts like interfaces and traits? I’m wondering if this overlaps with this issue: https://github.com/llvm/llvm-project/issues/158066.

As @Moxinilian says "traits are simple flag-like constructs [and] should be rather straight-forward." Interfaces have declared methods though. While there might be some hope of expressing _declarations_ of interfaces (i.e. traits with methods) with IRDL, implementing interfaces' methods is out-of-scope for IRDL*. That is, method implementations are to be provided in the host language, so either C++ or Python (or ...). 

So we should try to support traits in IRDL _and_ MLIR's Python op-def DSL. For interfaces, I feel IRDL should just treat them as traits and essentially as promises: when an op has this interface's trait, you _know_ there's going to be an impl of the interface available at runtime (even though IRDL might know nothing about the associated methods). MLIR's Python op-def DSL can go beyond IRDL and have ABC classes for both traits and interfaces, with the latter having methods, which we can subclass and implement on the Op's def. (There's going to be some magic involved though as we need to late-bind the C++ MLIR Traits and Interfaces impls once the IRDL-def of the ops have been registered.) 

*: A future where we can express the entire compiler in IR is an enticing thought though!

https://github.com/llvm/llvm-project/pull/169045


More information about the Mlir-commits mailing list