Skip to content

Commit 9f3f6d7

Browse files
Move MLIR python sources to mlir/python.
* NFC but has some fixes for CMake glitches discovered along the way (things not cleaning properly, co-mingled depends). * Includes previously unsubmitted fix in D98681 and a TODO to fix it more appropriately in a smaller followup. Differential Revision: https://reviews.llvm.org/D101493
1 parent 49e7be2 commit 9f3f6d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+137
-120
lines changed

mlir/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ endif()
146146
# Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so.
147147
add_subdirectory(tools)
148148

149+
if(MLIR_BINDINGS_PYTHON_ENABLED)
150+
# Python sources: built extensions come in via lib/Bindings/Python
151+
add_subdirectory(python)
152+
endif()
153+
149154
if( LLVM_INCLUDE_EXAMPLES )
150155
add_subdirectory(examples)
151156
endif()

mlir/cmake/modules/AddMLIRPythonExtension.cmake renamed to mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function(add_mlir_dialect_python_bindings tblgen_target)
156156
add_custom_command(
157157
TARGET ${tblgen_target} POST_BUILD
158158
COMMENT "Copying generated python source \"dialects/${dialect_filename}\""
159+
BYPRODUCTS "${PROJECT_BINARY_DIR}/python/mlir/dialects/${dialect_filename}"
159160
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
160161
"${CMAKE_CURRENT_BINARY_DIR}/${dialect_filename}"
161162
"${PROJECT_BINARY_DIR}/python/mlir/dialects/${dialect_filename}")

mlir/cmake/modules/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
8181
install(FILES
8282
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
8383
${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
84-
${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPythonExtension.cmake
84+
${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
8585
${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
8686
DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
8787
COMPONENT mlir-cmake-exports)

mlir/docs/Bindings/Python.md

Lines changed: 2 additions & 2 deletions

mlir/lib/Bindings/Python/CMakeLists.txt

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,6 @@
1-
include(AddMLIRPythonExtension)
1+
include(AddMLIRPython)
22
add_custom_target(MLIRBindingsPythonExtension)
33

4-
################################################################################
5-
# Copy python source tree.
6-
################################################################################
7-
8-
file(GLOB_RECURSE PY_SRC_FILES
9-
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
10-
"${CMAKE_CURRENT_SOURCE_DIR}/mlir/*.py")
11-
12-
add_custom_target(MLIRBindingsPythonSources ALL
13-
DEPENDS ${PY_SRC_FILES}
14-
)
15-
add_dependencies(MLIRBindingsPythonExtension MLIRBindingsPythonSources)
16-
17-
foreach(PY_SRC_FILE ${PY_SRC_FILES})
18-
set(PY_DEST_FILE "${PROJECT_BINARY_DIR}/python/${PY_SRC_FILE}")
19-
get_filename_component(PY_DEST_DIR "${PY_DEST_FILE}" DIRECTORY)
20-
file(MAKE_DIRECTORY "${PY_DEST_DIR}")
21-
add_custom_command(
22-
TARGET MLIRBindingsPythonSources PRE_BUILD
23-
COMMENT "Copying python source ${PY_SRC_FILE} -> ${PY_DEST_FILE}"
24-
DEPENDS "${PY_SRC_FILE}"
25-
COMMAND "${CMAKE_COMMAND}" -E create_symlink
26-
"${CMAKE_CURRENT_SOURCE_DIR}/${PY_SRC_FILE}" "${PY_DEST_FILE}"
27-
)
28-
endforeach()
29-
30-
################################################################################
31-
# Generate dialect-specific bindings.
32-
################################################################################
33-
34-
add_mlir_dialect_python_bindings(MLIRBindingsPythonAsyncOps
35-
TD_FILE AsyncOps.td
36-
DIALECT_NAME async_dialect)
37-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonAsyncOps)
38-
39-
add_mlir_dialect_python_bindings(MLIRBindingsPythonBuiltinOps
40-
TD_FILE BuiltinOps.td
41-
DIALECT_NAME builtin)
42-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonBuiltinOps)
43-
44-
add_mlir_dialect_python_bindings(MLIRBindingsPythonGPUOps
45-
TD_FILE GPUOps.td
46-
DIALECT_NAME gpu)
47-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonGPUOps)
48-
49-
add_mlir_dialect_python_bindings(MLIRBindingsPythonLinalgOps
50-
TD_FILE LinalgOps.td
51-
DIALECT_NAME linalg
52-
DEPENDS LinalgOdsGen)
53-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonLinalgOps)
54-
55-
add_mlir_dialect_python_bindings(MLIRBindingsPythonMemRefOps
56-
TD_FILE MemRefOps.td
57-
DIALECT_NAME memref)
58-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonMemRefOps)
59-
60-
add_mlir_dialect_python_bindings(MLIRBindingsPythonShapeOps
61-
TD_FILE ShapeOps.td
62-
DIALECT_NAME shape)
63-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonShapeOps)
64-
65-
add_mlir_dialect_python_bindings(MLIRBindingsPythonStandardOps
66-
TD_FILE StandardOps.td
67-
DIALECT_NAME std)
68-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonStandardOps)
69-
70-
add_mlir_dialect_python_bindings(MLIRBindingsPythonTensorOps
71-
TD_FILE TensorOps.td
72-
DIALECT_NAME tensor)
73-
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonTensorOps)
74-
754
################################################################################
765
# Build core python extension
776
################################################################################
@@ -92,42 +21,6 @@ add_mlir_python_extension(MLIRCoreBindingsPythonExtension _mlir
9221
)
9322
add_dependencies(MLIRBindingsPythonExtension MLIRCoreBindingsPythonExtension)
9423

95-
# Note that we copy from the source tree just like for headers because
96-
# it will not be polluted with py_cache runtime artifacts (from testing and
97-
# such).
98-
install(
99-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mlir
100-
DESTINATION python
101-
COMPONENT MLIRBindingsPythonSources
102-
FILES_MATCHING PATTERN "*.py"
103-
)
104-
105-
if (NOT LLVM_ENABLE_IDE)
106-
add_llvm_install_targets(
107-
install-MLIRBindingsPythonSources
108-
DEPENDS MLIRBindingsPythonSources
109-
COMPONENT MLIRBindingsPythonSources)
110-
endif()
111-
112-
# Dialect sources are generated. Install separately.
113-
# Note that __pycache__ directories may have been left by tests and other
114-
# executions. And __init__.py is handled as a regular source file.
115-
install(
116-
DIRECTORY ${PROJECT_BINARY_DIR}/python/mlir/dialects
117-
DESTINATION python/mlir
118-
COMPONENT MLIRBindingsPythonDialects
119-
FILES_MATCHING PATTERN "*.py"
120-
PATTERN "__pycache__" EXCLUDE
121-
PATTERN "__init__.py" EXCLUDE
122-
)
123-
124-
if (NOT LLVM_ENABLE_IDE)
125-
add_llvm_install_targets(
126-
install-MLIRBindingsPythonDialects
127-
DEPENDS MLIRBindingsPythonSources
128-
COMPONENT MLIRBindingsPythonDialects)
129-
endif()
130-
13124
add_subdirectory(Transforms)
13225
add_subdirectory(Conversions)
13326

File renamed without changes.

mlir/python/CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
################################################################################
2+
# Copy python source tree.
3+
################################################################################
4+
5+
file(GLOB_RECURSE PY_SRC_FILES
6+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
7+
"${CMAKE_CURRENT_SOURCE_DIR}/mlir/*.py")
8+
9+
add_custom_target(MLIRBindingsPythonSources ALL
10+
DEPENDS
11+
${PY_SRC_FILES}
12+
)
13+
14+
foreach(PY_SRC_FILE ${PY_SRC_FILES})
15+
set(PY_DEST_FILE "${PROJECT_BINARY_DIR}/python/${PY_SRC_FILE}")
16+
get_filename_component(PY_DEST_DIR "${PY_DEST_FILE}" DIRECTORY)
17+
file(MAKE_DIRECTORY "${PY_DEST_DIR}")
18+
add_custom_command(
19+
TARGET MLIRBindingsPythonSources PRE_BUILD
20+
COMMENT "Copying python source ${PY_SRC_FILE} -> ${PY_DEST_FILE}"
21+
DEPENDS "${PY_SRC_FILE}"
22+
BYPRODUCTS "${PY_DEST_FILE}"
23+
COMMAND "${CMAKE_COMMAND}" -E create_symlink
24+
"${CMAKE_CURRENT_SOURCE_DIR}/${PY_SRC_FILE}" "${PY_DEST_FILE}"
25+
)
26+
endforeach()
27+
28+
# Note that we copy from the source tree just like for headers because
29+
# it will not be polluted with py_cache runtime artifacts (from testing and
30+
# such).
31+
install(
32+
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mlir
33+
DESTINATION python
34+
COMPONENT MLIRBindingsPythonSources
35+
FILES_MATCHING PATTERN "*.py"
36+
)
37+
38+
if (NOT LLVM_ENABLE_IDE)
39+
add_llvm_install_targets(
40+
install-MLIRBindingsPythonSources
41+
DEPENDS MLIRBindingsPythonSources
42+
COMPONENT MLIRBindingsPythonSources)
43+
endif()
44+
45+
################################################################################
46+
# Generated sources.
47+
################################################################################
48+
49+
add_subdirectory(mlir/dialects)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
include(AddMLIRPython)
2+
3+
################################################################################
4+
# Generate dialect-specific bindings.
5+
################################################################################
6+
7+
add_mlir_dialect_python_bindings(MLIRBindingsPythonAsyncOps
8+
TD_FILE AsyncOps.td
9+
DIALECT_NAME async_dialect)
10+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonAsyncOps)
11+
12+
add_mlir_dialect_python_bindings(MLIRBindingsPythonBuiltinOps
13+
TD_FILE BuiltinOps.td
14+
DIALECT_NAME builtin)
15+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonBuiltinOps)
16+
17+
add_mlir_dialect_python_bindings(MLIRBindingsPythonGPUOps
18+
TD_FILE GPUOps.td
19+
DIALECT_NAME gpu)
20+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonGPUOps)
21+
22+
add_mlir_dialect_python_bindings(MLIRBindingsPythonLinalgOps
23+
TD_FILE LinalgOps.td
24+
DIALECT_NAME linalg
25+
DEPENDS LinalgOdsGen)
26+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonLinalgOps)
27+
28+
add_mlir_dialect_python_bindings(MLIRBindingsPythonMemRefOps
29+
TD_FILE MemRefOps.td
30+
DIALECT_NAME memref)
31+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonMemRefOps)
32+
33+
add_mlir_dialect_python_bindings(MLIRBindingsPythonShapeOps
34+
TD_FILE ShapeOps.td
35+
DIALECT_NAME shape)
36+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonShapeOps)
37+
38+
add_mlir_dialect_python_bindings(MLIRBindingsPythonStandardOps
39+
TD_FILE StandardOps.td
40+
DIALECT_NAME std)
41+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonStandardOps)
42+
43+
add_mlir_dialect_python_bindings(MLIRBindingsPythonTensorOps
44+
TD_FILE TensorOps.td
45+
DIALECT_NAME tensor)
46+
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonTensorOps)
47+
48+
################################################################################
49+
# Installation.
50+
################################################################################
51+
52+
# Dialect sources are generated. Install separately.
53+
# Note that __pycache__ directories may have been left by tests and other
54+
# executions. And __init__.py is handled as a regular source file.
55+
# TODO: Eliminate this glob install, instead adding INSTALL_COMPONENT to
56+
# add_mlir_dialect_python_bindings and installing the precise file there.
57+
install(
58+
DIRECTORY ${PROJECT_BINARY_DIR}/python/mlir/dialects
59+
DESTINATION python/mlir
60+
COMPONENT MLIRBindingsPythonDialects
61+
FILES_MATCHING PATTERN "_*_gen.py"
62+
PATTERN "__pycache__" EXCLUDE
63+
PATTERN "__init__.py" EXCLUDE
64+
)
65+
66+
if (NOT LLVM_ENABLE_IDE)
67+
add_llvm_install_targets(
68+
install-MLIRBindingsPythonDialects
69+
DEPENDS MLIRBindingsPythonSources
70+
COMPONENT MLIRBindingsPythonDialects)
71+
endif()
File renamed without changes.

mlir/test/Bindings/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

mlir/test/Bindings/Python/.style.yapf

Lines changed: 0 additions & 4 deletions
This file was deleted.

mlir/test/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
add_subdirectory(Bindings)
21
add_subdirectory(CAPI)
32
add_subdirectory(EDSC)
43
add_subdirectory(SDBM)
54
add_subdirectory(lib)
65

6+
if(MLIR_BINDINGS_PYTHON_ENABLED)
7+
add_subdirectory(python)
8+
endif()
9+
710
llvm_canonicalize_cmake_booleans(
811
MLIR_BINDINGS_PYTHON_ENABLED
912
LLVM_BUILD_EXAMPLES
@@ -111,6 +114,7 @@ endif()
111114
if(MLIR_BINDINGS_PYTHON_ENABLED)
112115
list(APPEND MLIR_TEST_DEPENDS
113116
MLIRBindingsPythonExtension
117+
MLIRBindingsPythonSources
114118
MLIRBindingsPythonTestOps
115119
MLIRTransformsBindingsPythonExtension
116120
MLIRConversionsBindingsPythonExtension
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
include(AddMLIRPythonExtension)
1+
include(AddMLIRPython)
2+
23
add_mlir_dialect_python_bindings(MLIRBindingsPythonTestOps
34
TD_FILE python_test_ops.td
45
DIALECT_NAME python_test)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)