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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Nov 14 19:40:22 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

<details>
<summary>Changes</summary>

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`.

---
Full diff: https://github.com/llvm/llvm-project/pull/72338.diff


1 Files Affected:

- (modified) mlir/python/CMakeLists.txt (+11-8) 


``````````diff
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"

``````````

</details>


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


More information about the Mlir-commits mailing list