[Mlir-commits] [mlir] [mlir][python][cmake] add EXTRA_INCLUDES to `declare_mlir_dialect_python_bindings` (PR #76204)
Maksim Levental
llvmlistbot at llvm.org
Thu Dec 21 21:07:11 PST 2023
https://github.com/makslevental created https://github.com/llvm/llvm-project/pull/76204
This PR adds an `EXTRA_INCLUDES` arg to `declare_mlir_dialect_python_bindings` to be forwarded to `mlir_tablegen`. The use case I think is obvious but my personal need was to experiment generating python bindings for some of flang's dialects. And it worked! How does the adage go? "You can write fortran in any language"? Well now you really can!
Anyway I left the cmake target in here as a demo/test but I don't intend to keep it.
>From 2c19b805c60b8226018ae36b23ea1d8a16e64ae5 Mon Sep 17 00:00:00 2001
From: max <maksim.levental at gmail.com>
Date: Thu, 21 Dec 2023 23:03:00 -0600
Subject: [PATCH] [mlir][python][cmake] add EXTRA_INCLUDES to
declare_mlir_dialect_python_bindings
---
mlir/cmake/modules/AddMLIRPython.cmake | 6 +++---
mlir/python/CMakeLists.txt | 11 +++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 012380603a4c45..052dbff3b4d14a 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -286,7 +286,7 @@ function(declare_mlir_dialect_python_bindings)
cmake_parse_arguments(ARG
"GEN_ENUM_BINDINGS"
"ROOT_DIR;ADD_TO_PARENT;TD_FILE;DIALECT_NAME"
- "SOURCES;SOURCES_GLOB;DEPENDS;GEN_ENUM_BINDINGS_TD_FILE"
+ "SOURCES;SOURCES_GLOB;DEPENDS;GEN_ENUM_BINDINGS_TD_FILE;EXTRA_INCLUDES"
${ARGN})
# Sources.
set(_dialect_target "${ARG_ADD_TO_PARENT}.${ARG_DIALECT_NAME}")
@@ -307,7 +307,7 @@ function(declare_mlir_dialect_python_bindings)
set(LLVM_TARGET_DEFINITIONS ${td_file})
mlir_tablegen("${dialect_filename}"
-gen-python-op-bindings -bind-dialect=${ARG_DIALECT_NAME}
- DEPENDS ${ARG_DEPENDS}
+ DEPENDS ${ARG_DEPENDS} EXTRA_INCLUDES ${ARG_EXTRA_INCLUDES}
)
add_public_tablegen_target(${tblgen_target})
@@ -318,7 +318,7 @@ function(declare_mlir_dialect_python_bindings)
set(LLVM_TARGET_DEFINITIONS ${td_file})
endif()
set(enum_filename "${relative_td_directory}/_${ARG_DIALECT_NAME}_enum_gen.py")
- mlir_tablegen(${enum_filename} -gen-python-enum-bindings)
+ mlir_tablegen(${enum_filename} -gen-python-enum-bindings EXTRA_INCLUDES ${ARG_EXTRA_INCLUDES})
list(APPEND _sources ${enum_filename})
endif()
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 3c9cf304d88a27..28f522b608a3ff 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -403,6 +403,17 @@ declare_mlir_dialect_python_bindings(
GEN_ENUM_BINDINGS_TD_FILE
"dialects/VectorAttributes.td")
+declare_mlir_dialect_python_bindings(
+ ADD_TO_PARENT MLIRPythonSources.Dialects
+ ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+ TD_FILE dialects/FIROps.td
+ SOURCES dialects/fir.py
+ DIALECT_NAME fir
+ GEN_ENUM_BINDINGS_TD_FILE
+ "dialects/FIRAttrs.td"
+ EXTRA_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/mlir/../../../flang/include"
+)
+
################################################################################
# Python extensions.
# The sources for these are all in lib/Bindings/Python, but since they have to
More information about the Mlir-commits
mailing list