[Mlir-commits] [mlir] [MLIR][Python] Support dialect conversion in python bindings (PR #177782)

Maksim Levental llvmlistbot at llvm.org
Sun Jan 25 15:21:18 PST 2026


================
@@ -539,7 +811,37 @@ void populateRewriteSubmodule(nb::module_ &m) {
           },
           "op"_a, "set"_a,
           "Applies the given patterns to the given op by a fast walk-based "
-          "driver.");
+          "driver.")
+      .def(
+          "apply_partial_conversion",
+          [](PyOperationBase &op, PyConversionTarget &target,
+             PyFrozenRewritePatternSet &set,
+             std::optional<PyConversionConfig> config) {
+            if (!config) {
+              config.emplace(PyConversionConfig());
+            }
+            auto status = mlirApplyPartialConversion(
+                op.getOperation(), target.get(), set.get(), config->get());
+            if (mlirLogicalResultIsFailure(status))
+              throw std::runtime_error("partial conversion failed");
+          },
+          "op"_a, "target"_a, "set"_a, "config"_a = nb::none(),
+          "Applies a partial conversion on the given operation.")
+      .def(
+          "apply_full_conversion",
+          [](PyOperationBase &op, PyConversionTarget &target,
+             PyFrozenRewritePatternSet &set,
+             std::optional<PyConversionConfig> config) {
+            if (!config) {
+              config.emplace(PyConversionConfig());
+            }
+            auto status = mlirApplyFullConversion(
----------------
makslevental wrote:

```suggestion
            if (!config)
              config.emplace(PyConversionConfig());
            MlirLogicalResult status = mlirApplyFullConversion(
```

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


More information about the Mlir-commits mailing list