[Mlir-commits] [mlir] [MLIR][Python] Add bindings for PDL native rewrite function registering (PR #159926)
Maksim Levental
llvmlistbot at llvm.org
Sat Sep 20 10:57:50 PDT 2025
================
@@ -76,10 +118,27 @@ class PyFrozenRewritePatternSet {
/// Create the `mlir.rewrite` here.
void mlir::python::populateRewriteSubmodule(nb::module_ &m) {
+ nb::class_<MlirPatternRewriter>(m, "PatternRewriter");
//----------------------------------------------------------------------------
- // Mapping of the top-level PassManager
+ // Mapping of the PDLResultList and PDLModule
//----------------------------------------------------------------------------
#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
+ nb::class_<MlirPDLResultList>(m, "PDLResultList")
+ .def("push_back",
+ [](MlirPDLResultList results, const PyValue &value) {
+ mlirPDLResultListPushBackValue(results, value);
+ })
+ .def("push_back",
+ [](MlirPDLResultList results, const PyOperation &op) {
+ mlirPDLResultListPushBackOperation(results, op);
+ })
+ .def("push_back",
+ [](MlirPDLResultList results, const PyType &type) {
+ mlirPDLResultListPushBackType(results, type);
+ })
+ .def("push_back", [](MlirPDLResultList results, const PyAttribute &attr) {
+ mlirPDLResultListPushBackAttribute(results, attr);
+ });
----------------
makslevental wrote:
since https://github.com/llvm/llvm-project/pull/157930 is about to land, can you add `nb::sig` here. E.g.,
```c++
nb::sig("def push_back(self, " MAKE_MLIR_PYTHON_QUALNAME("ir.Attribute") ")")
```
https://github.com/llvm/llvm-project/pull/159926
More information about the Mlir-commits
mailing list