[Mlir-commits] [mlir] [mlir][python] automatically bundle builtin dialect with core (PR #72338)

Maksim Levental llvmlistbot at llvm.org
Tue Nov 14 19:39:53 PST 2023


https://github.com/makslevental created https://github.com/llvm/llvm-project/pull/72338

So it turns out there are funny people (CIRCT ahem...) that depend on `MLIRPythonSources.Core` sources but choose not to build/depend any of the upstream dialects. Unfortunately this breaks all of the type casters and such after https://github.com/llvm/llvm-project/pull/70831 because all of the fancy `lookup...` functions will [early exit if `loadDialectModule` fails](https://github.com/llvm/llvm-project/commit/5192e299cf444040025ccf3e75bfad36b4624050#diff-1f295ae31d665f9a778ea210c0816a22c621c34d54bf5b83b21686bf0432a918R126). So let's do these funny people a favor and automatically including the `builtin` dialect for them with `MLIRPythonSources.Core`.

>From 8ae7d2d868c8dbc827f1d996722c564b12b4eaf0 Mon Sep 17 00:00:00 2001
From: max <maksim.levental at gmail.com>
Date: Tue, 14 Nov 2023 21:33:39 -0600
Subject: [PATCH] [mlir][python] automatically bundle builtin dialect with core

---
 mlir/python/CMakeLists.txt | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 971ad2dd214a15f..6be84ec311e23ca 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -44,6 +44,17 @@ declare_mlir_python_sources(MLIRPythonCAPI.HeaderSources
   SOURCES_GLOB "mlir-c/*.h"
 )
 
+# The builtin dialect is special (e.g., type casters and such expect it to be loaded
+# in order to work) so we add it to Core instead of Dialects so that anyone depending on
+# Core will get it automatically.
+declare_mlir_dialect_python_bindings(
+  ADD_TO_PARENT MLIRPythonSources.Core
+  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+  TD_FILE dialects/BuiltinOps.td
+  SOURCES
+    dialects/builtin.py
+  DIALECT_NAME builtin)
+
 ################################################################################
 # Dialect bindings
 ################################################################################
@@ -84,14 +95,6 @@ declare_mlir_dialect_python_bindings(
     "../../include/mlir/Dialect/Bufferization/IR/BufferizationEnums.td"
 )
 
-declare_mlir_dialect_python_bindings(
-  ADD_TO_PARENT MLIRPythonSources.Dialects
-  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
-  TD_FILE dialects/BuiltinOps.td
-  SOURCES
-    dialects/builtin.py
-  DIALECT_NAME builtin)
-
 declare_mlir_dialect_python_bindings(
   ADD_TO_PARENT MLIRPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"



More information about the Mlir-commits mailing list