[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:08:09 PST 2023
https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/76204
>From 28d1c7df9f028ce73eb41e477b58a82a668d725d 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 1/2] [mlir][python][cmake] add EXTRA_INCLUDES to
declare_mlir_dialect_python_bindings
---
mlir/cmake/modules/AddMLIRPython.cmake | 6 +++---
1 file changed, 3 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()
>From 7685a675353d7cae38f3f9eda1e6c80d0213eb69 Mon Sep 17 00:00:00 2001
From: max <maksim.levental at gmail.com>
Date: Thu, 21 Dec 2023 23:07:59 -0600
Subject: [PATCH 2/2] test on flang
---
mlir/python/CMakeLists.txt | 11 +++++++++++
mlir/python/mlir/dialects/FIRAttrs.td | 14 ++++++++++++++
mlir/python/mlir/dialects/FIROps.td | 14 ++++++++++++++
mlir/python/mlir/dialects/fir.py | 6 ++++++
4 files changed, 45 insertions(+)
create mode 100644 mlir/python/mlir/dialects/FIRAttrs.td
create mode 100644 mlir/python/mlir/dialects/FIROps.td
create mode 100644 mlir/python/mlir/dialects/fir.py
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
diff --git a/mlir/python/mlir/dialects/FIRAttrs.td b/mlir/python/mlir/dialects/FIRAttrs.td
new file mode 100644
index 00000000000000..382a5df03db88e
--- /dev/null
+++ b/mlir/python/mlir/dialects/FIRAttrs.td
@@ -0,0 +1,14 @@
+//===-- ControlFlowOps.td - Python ControlFlowOps bindings -*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---------------------------------------------------------------------===//
+
+#ifndef PYTHON_BINDINGS_FIR_ATTRS
+#define PYTHON_BINDINGS_FIR_ATTRS
+
+include "flang/Optimizer/Dialect/FIRAttr.td"
+
+#endif
diff --git a/mlir/python/mlir/dialects/FIROps.td b/mlir/python/mlir/dialects/FIROps.td
new file mode 100644
index 00000000000000..025b6deb98e355
--- /dev/null
+++ b/mlir/python/mlir/dialects/FIROps.td
@@ -0,0 +1,14 @@
+//===-- ControlFlowOps.td - Python ControlFlowOps bindings -*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---------------------------------------------------------------------===//
+
+#ifndef PYTHON_BINDINGS_FIR_OPS
+#define PYTHON_BINDINGS_FIR_OPS
+
+include "flang/Optimizer/Dialect/FIROps.td"
+
+#endif
diff --git a/mlir/python/mlir/dialects/fir.py b/mlir/python/mlir/dialects/fir.py
new file mode 100644
index 00000000000000..ca09e96a1742c2
--- /dev/null
+++ b/mlir/python/mlir/dialects/fir.py
@@ -0,0 +1,6 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+from ._fir_ops_gen import *
+from ._fir_enum_gen import *
More information about the Mlir-commits
mailing list