[Mlir-commits] [mlir] [MLIR][Linalg] Expose linalg.matmul and linalg.contract via Python API (PR #126377)

Rolf Morel llvmlistbot at llvm.org
Sun Feb 9 12:25:49 PST 2025


rolfmorel wrote:

Okay - decided a deep dive _was_ actually a good use of a sunday afternoon.

I have now dealt with the "default values can only be C++ values" issue at the root: it was not possible to access the context within `Attr::defaultValue`. Previously I tried to work around this. Now I have just allowed access to `$_builder` from `defaultValue`. Note partial support for this already existed, see [here](https://github.com/llvm/llvm-project/blob/e9a20f77ee2117b4a6eb40826b7280e29ad29e1e/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp#L2713). I have just extended that support to all cases where `defaultValue` gets dumped into C++. Happy to extract this commit to a separate PR if that's considered necessary.

To me, the above is an elegant solution to the "no builder methoc is invoked when ops are constructed from Python" problem. It is also a general quality of life improvement for others who come across this strange limitation (i.e. Attr's `constBuilderCall` can access the builder/context and `defaultValue` cannot). Let me know if other approaches are still considered preferable.

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


More information about the Mlir-commits mailing list