[Mlir-commits] [mlir] [MLIR][Standalone] don't register everything (PR #157688)
Maksim Levental
llvmlistbot at llvm.org
Tue Sep 9 09:28:33 PDT 2025
https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/157688
>From 0ab91593df8a9ca5df6ccd7b9e25c7f087603cdb Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 10:09:44 -0500
Subject: [PATCH 1/9] [MLIR][Standalone] don't register everything
We only need to register `builtin`.
---
mlir/examples/standalone/python/CMakeLists.txt | 6 ------
1 file changed, 6 deletions(-)
diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt
index cb10518e94e33..33e2640300043 100644
--- a/mlir/examples/standalone/python/CMakeLists.txt
+++ b/mlir/examples/standalone/python/CMakeLists.txt
@@ -54,9 +54,6 @@ add_mlir_python_common_capi_library(StandalonePythonCAPI
RELATIVE_INSTALL_ROOT "../../../.."
DECLARED_SOURCES
StandalonePythonSources
- # TODO: Remove this in favor of showing fine grained registration once
- # available.
- MLIRPythonExtension.RegisterEverything
MLIRPythonSources.Core
MLIRPythonSources.Dialects.builtin
)
@@ -70,9 +67,6 @@ add_mlir_python_modules(StandalonePythonModules
INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"
DECLARED_SOURCES
StandalonePythonSources
- # TODO: Remove this in favor of showing fine grained registration once
- # available.
- MLIRPythonExtension.RegisterEverything
MLIRPythonSources.Core
MLIRPythonSources.Dialects.builtin
COMMON_CAPI_LINK_LIBS
>From ef55a39efe518b05b543cf905c576ef3eeb9e143 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 08:21:19 -0700
Subject: [PATCH 2/9] Update CMakeLists.txt
---
mlir/examples/standalone/python/CMakeLists.txt | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt
index 33e2640300043..2c6a2ffde10b7 100644
--- a/mlir/examples/standalone/python/CMakeLists.txt
+++ b/mlir/examples/standalone/python/CMakeLists.txt
@@ -28,6 +28,7 @@ declare_mlir_python_extension(StandalonePythonSources.Pybind11Extension
StandaloneExtensionPybind11.cpp
EMBED_CAPI_LINK_LIBS
StandaloneCAPI
+ MLIRCAPITransforms
PYTHON_BINDINGS_LIBRARY pybind11
)
@@ -38,6 +39,7 @@ declare_mlir_python_extension(StandalonePythonSources.NanobindExtension
StandaloneExtensionNanobind.cpp
EMBED_CAPI_LINK_LIBS
StandaloneCAPI
+ MLIRCAPITransforms
PYTHON_BINDINGS_LIBRARY nanobind
GENERATE_TYPE_STUBS
)
>From a9af4175818437564c599d1cf201e5e261cb8c69 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 08:58:59 -0700
Subject: [PATCH 3/9] Update StandaloneExtensionNanobind.cpp
---
.../standalone/python/StandaloneExtensionNanobind.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
index 189ebac368bf5..aad44dc7f2137 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
@@ -12,6 +12,7 @@
#include "Standalone-c/Dialects.h"
#include "mlir/Bindings/Python/Nanobind.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"
+#include "mlir-c/Dialect/Arith.h
namespace nb = nanobind;
@@ -22,9 +23,10 @@ NB_MODULE(_standaloneDialectsNanobind, m) {
auto standaloneM = m.def_submodule("standalone");
standaloneM.def(
- "register_dialect",
+ "register_dialects",
[](MlirContext context, bool load) {
- MlirDialectHandle handle = mlirGetDialectHandle__standalone__();
+ MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__();
+ MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__();
mlirDialectHandleRegisterDialect(handle, context);
if (load) {
mlirDialectHandleLoadDialect(handle, context);
>From a039b2807265fbdfd436191cd8944d943135d47b Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 08:59:52 -0700
Subject: [PATCH 4/9] Update StandaloneExtensionPybind11.cpp
---
.../standalone/python/StandaloneExtensionPybind11.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
index 397db4c20e743..02f23d758c44f 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
@@ -10,6 +10,7 @@
//===----------------------------------------------------------------------===//
#include "Standalone-c/Dialects.h"
+#include "mlir-c/Dialect/Arith.h
#include "mlir/Bindings/Python/PybindAdaptors.h"
using namespace mlir::python::adaptors;
@@ -21,10 +22,12 @@ PYBIND11_MODULE(_standaloneDialectsPybind11, m) {
auto standaloneM = m.def_submodule("standalone");
standaloneM.def(
- "register_dialect",
+ "register_dialects",
[](MlirContext context, bool load) {
- MlirDialectHandle handle = mlirGetDialectHandle__standalone__();
- mlirDialectHandleRegisterDialect(handle, context);
+ MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__();
+ MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__();
+ mlirDialectHandleRegisterDialect(standaloneHandle, context);
+ mlirDialectHandleRegisterDialect(arithHandle, context);
if (load) {
mlirDialectHandleLoadDialect(handle, context);
}
>From 7df2c4af60793d2ff77de78aef60333eab25beaf Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 09:00:06 -0700
Subject: [PATCH 5/9] Update StandaloneExtensionNanobind.cpp
---
.../examples/standalone/python/StandaloneExtensionNanobind.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
index aad44dc7f2137..3dc067377f32f 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
@@ -27,7 +27,8 @@ NB_MODULE(_standaloneDialectsNanobind, m) {
[](MlirContext context, bool load) {
MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__();
MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__();
- mlirDialectHandleRegisterDialect(handle, context);
+ mlirDialectHandleRegisterDialect(standaloneHandle, context);
+ mlirDialectHandleRegisterDialect(arithHandle, context);
if (load) {
mlirDialectHandleLoadDialect(handle, context);
}
>From 926dba3b88bc3152c4654ba72d73416a184892f0 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 09:00:20 -0700
Subject: [PATCH 6/9] Update smoketest.py
---
mlir/examples/standalone/test/python/smoketest.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/examples/standalone/test/python/smoketest.py b/mlir/examples/standalone/test/python/smoketest.py
index bd40c65d16164..6d41ecc11c540 100644
--- a/mlir/examples/standalone/test/python/smoketest.py
+++ b/mlir/examples/standalone/test/python/smoketest.py
@@ -14,7 +14,7 @@
with Context():
- standalone_d.register_dialect()
+ standalone_d.register_dialects()
module = Module.parse(
"""
%0 = arith.constant 2 : i32
>From 9f838d06fca63ae6521fe9844d696e3f976fed44 Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 09:06:45 -0700
Subject: [PATCH 7/9] reformat
---
.../standalone/python/StandaloneExtensionNanobind.cpp | 6 ++++--
.../standalone/python/StandaloneExtensionPybind11.cpp | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
index 3dc067377f32f..6b031119945ad 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
@@ -25,12 +25,14 @@ NB_MODULE(_standaloneDialectsNanobind, m) {
standaloneM.def(
"register_dialects",
[](MlirContext context, bool load) {
- MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__();
+ MlirDialectHandle standaloneHandle =
+ mlirGetDialectHandle__standalone__();
MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__();
mlirDialectHandleRegisterDialect(standaloneHandle, context);
mlirDialectHandleRegisterDialect(arithHandle, context);
if (load) {
- mlirDialectHandleLoadDialect(handle, context);
+ mlirDialectHandleLoadDialect(standaloneHandle, context);
+ mlirDialectHandleLoadDialect(arithHandle, context);
}
},
nb::arg("context").none() = nb::none(), nb::arg("load") = true);
diff --git a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
index 02f23d758c44f..a960e8b0f8d54 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
@@ -24,12 +24,14 @@ PYBIND11_MODULE(_standaloneDialectsPybind11, m) {
standaloneM.def(
"register_dialects",
[](MlirContext context, bool load) {
- MlirDialectHandle standaloneHandle = mlirGetDialectHandle__standalone__();
+ MlirDialectHandle standaloneHandle =
+ mlirGetDialectHandle__standalone__();
MlirDialectHandle arithHandle = mlirGetDialectHandle__arith__();
mlirDialectHandleRegisterDialect(standaloneHandle, context);
mlirDialectHandleRegisterDialect(arithHandle, context);
if (load) {
- mlirDialectHandleLoadDialect(handle, context);
+ mlirDialectHandleLoadDialect(standaloneHandle, context);
+ mlirDialectHandleLoadDialect(arithHandle, context);
}
},
py::arg("context") = py::none(), py::arg("load") = true);
>From 63f4dfcc76a3b42f6657355c14beeae664e17312 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 09:27:58 -0700
Subject: [PATCH 8/9] Update StandaloneExtensionNanobind.cpp
---
mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
index 6b031119945ad..7d03bbfa5a6fe 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
@@ -12,7 +12,7 @@
#include "Standalone-c/Dialects.h"
#include "mlir/Bindings/Python/Nanobind.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"
-#include "mlir-c/Dialect/Arith.h
+#include "mlir-c/Dialect/Arith.h"
namespace nb = nanobind;
>From 11a1bdf20067ea7d10dd313dd619bad426596433 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 9 Sep 2025 09:28:22 -0700
Subject: [PATCH 9/9] Update StandaloneExtensionPybind11.cpp
---
mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
index a960e8b0f8d54..88493f4f18f00 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionPybind11.cpp
@@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//
#include "Standalone-c/Dialects.h"
-#include "mlir-c/Dialect/Arith.h
+#include "mlir-c/Dialect/Arith.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"
using namespace mlir::python::adaptors;
More information about the Mlir-commits
mailing list