Skip to content

Commit 9191ac0

Browse files
authored
[mlir] Consider mlir-linalg-ods-gen as a tablegen tool in build (llvm#75093)
There is a bit of an issue with how `mlir-linalg-ods-yaml-gen` is classified in the MLIR build. Due to it being a tool, it is excluded from the install when using `-DLLVM_BUILD_TOOLS=OFF`. However, it is a necessary component of the build, so it can cause build issues with users of the installed LLVM, and so I think it should not be excluded. It is a tablegen-like tool, so my solution is to reclassify it that way in the build.
1 parent 619a006 commit 9191ac0

File tree

8 files changed

+54
-52
lines changed

8 files changed

+54
-52
lines changed

llvm/cmake/modules/TableGen.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,18 @@ function(add_public_tablegen_target target)
165165
endfunction()
166166

167167
macro(add_tablegen target project)
168-
cmake_parse_arguments(ADD_TABLEGEN "" "DESTINATION;EXPORT" "" ${ARGN})
168+
cmake_parse_arguments(ADD_TABLEGEN "SKIP_COMPONENT_LINK" "DESTINATION;EXPORT" "" ${ARGN})
169169

170-
set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
171-
set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
170+
if(NOT ADD_TABLEGEN_SKIP_COMPONENT_LINK)
171+
set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
172+
set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
173+
endif()
172174

173175
add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB
174176
${ADD_TABLEGEN_UNPARSED_ARGUMENTS})
175-
set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})
177+
if(NOT ADD_TABLEGEN_SKIP_COMPONENT_LINK)
178+
set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})
179+
endif()
176180

177181
set(${project}_TABLEGEN_DEFAULT "${target}")
178182
if (LLVM_NATIVE_TOOL_DIR)

mlir/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ add_subdirectory(tools/mlir-pdll)
184184

185185
set(MLIR_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}" CACHE INTERNAL "")
186186
set(MLIR_TABLEGEN_TARGET "${MLIR_TABLEGEN_TARGET}" CACHE INTERNAL "")
187+
set(MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE "${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE}" CACHE INTERNAL "")
188+
set(MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_TARGET "${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_TARGET}" CACHE INTERNAL "")
187189
set(MLIR_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}" CACHE INTERNAL "")
188190
set(MLIR_PDLL_TABLEGEN_TARGET "${MLIR_PDLL_TABLEGEN_TARGET}" CACHE INTERNAL "")
189191

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ function(add_mlir_pdll_library target inputFile ofn)
136136
add_public_tablegen_target(${target})
137137
endfunction()
138138

139+
# Declare a function to generate ODS with mlir-linalg-ods-yaml-gen
140+
function(add_linalg_ods_yaml_gen yaml_ast_file output_file)
141+
set(YAML_AST_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${yaml_ast_file})
142+
set(GEN_ODS_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.td)
143+
set(GEN_CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.cpp.inc)
144+
set_source_files_properties(
145+
${GEN_ODS_FILE}
146+
PROPERTIES GENERATED TRUE)
147+
set_source_files_properties(
148+
${GEN_CPP_FILE}
149+
PROPERTIES GENERATED TRUE)
150+
add_custom_command(
151+
OUTPUT ${GEN_ODS_FILE} ${GEN_CPP_FILE}
152+
COMMAND ${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE} ${YAML_AST_SOURCE} -o-ods-decl=${GEN_ODS_FILE} -o-impl=${GEN_CPP_FILE}
153+
MAIN_DEPENDENCY
154+
${YAML_AST_SOURCE}
155+
DEPENDS
156+
${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE}
157+
${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_TARGET}
158+
${LLVM_TARGET_DEPENDS})
159+
160+
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${GEN_ODS_FILE} ${GEN_CPP_FILE}
161+
PARENT_SCOPE)
162+
endfunction()
163+
139164
# Declare a dialect in the include directory
140165
function(add_mlir_dialect dialect dialect_namespace)
141166
set(LLVM_TARGET_DEFINITIONS ${dialect}.td)

mlir/cmake/modules/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ set(MLIR_CONFIG_INCLUDE_DIRS
3838
)
3939
# Refer to the best host mlir-tbgen, which might be a host-optimized version
4040
set(MLIR_CONFIG_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}")
41+
set(MLIR_CONFIG_LINALG_ODS_YAML_GEN_TABLEGEN_EXE "${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE}")
4142
set(MLIR_CONFIG_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}")
4243

4344
configure_file(
@@ -76,6 +77,7 @@ set(MLIR_CONFIG_INCLUDE_DIRS
7677
# Ensure that we are using the installed mlir-tblgen. This might not be MLIR_TABLEGEN_EXE
7778
# if we're building with a host-optimized mlir-tblgen (with LLVM_OPTIMIZED_TABLEGEN).
7879
set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)
80+
set(MLIR_CONFIG_LINALG_ODS_YAML_GEN_TABLEGEN_EXE mlir-linalg-ods-yaml-gen)
7981
set(MLIR_CONFIG_PDLL_TABLEGEN_EXE mlir-pdll)
8082

8183
configure_file(

mlir/cmake/modules/MLIRConfig.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(MLIR_EXPORTED_TARGETS "@MLIR_EXPORTS@")
1010
set(MLIR_CMAKE_DIR "@MLIR_CONFIG_CMAKE_DIR@")
1111
set(MLIR_INCLUDE_DIRS "@MLIR_CONFIG_INCLUDE_DIRS@")
1212
set(MLIR_TABLEGEN_EXE "@MLIR_CONFIG_TABLEGEN_EXE@")
13+
set(MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE "@MLIR_CONFIG_LINALG_ODS_YAML_GEN_TABLEGEN_EXE@")
1314
set(MLIR_PDLL_TABLEGEN_EXE "@MLIR_CONFIG_PDLL_TABLEGEN_EXE@")
1415
set(MLIR_INSTALL_AGGREGATE_OBJECTS "@MLIR_INSTALL_AGGREGATE_OBJECTS@")
1516
set(MLIR_ENABLE_BINDINGS_PYTHON "@MLIR_ENABLE_BINDINGS_PYTHON@")

mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,5 @@
1-
# Declare a function to generate ODS with mlir-linalg-ods-yaml-gen
2-
function(add_linalg_ods_yaml_gen yaml_ast_file output_file)
3-
set(YAML_AST_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${yaml_ast_file})
4-
set(GEN_ODS_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.td)
5-
set(GEN_CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.cpp.inc)
6-
set_source_files_properties(
7-
${GEN_ODS_FILE}
8-
PROPERTIES GENERATED TRUE)
9-
set_source_files_properties(
10-
${GEN_CPP_FILE}
11-
PROPERTIES GENERATED TRUE)
12-
add_custom_command(
13-
OUTPUT ${GEN_ODS_FILE} ${GEN_CPP_FILE}
14-
COMMAND ${MLIR_LINALG_ODS_YAML_GEN_EXE} ${YAML_AST_SOURCE} -o-ods-decl=${GEN_ODS_FILE} -o-impl=${GEN_CPP_FILE}
15-
MAIN_DEPENDENCY
16-
${YAML_AST_SOURCE}
17-
DEPENDS
18-
${MLIR_LINALG_ODS_YAML_GEN_EXE}
19-
${MLIR_LINALG_ODS_YAML_GEN_TARGET})
20-
add_custom_target(
21-
MLIR${output_file}YamlIncGen
22-
DEPENDS
23-
${MLIR_LINALG_ODS_YAML_GEN_EXE}
24-
${MLIR_LINALG_ODS_YAML_GEN_TARGET}
25-
${GEN_ODS_FILE} ${GEN_CPP_FILE})
26-
list(APPEND LLVM_TARGET_DEPENDS ${GEN_ODS_FILE})
27-
set(LLVM_TARGET_DEPENDS ${LLVM_TARGET_DEPENDS} PARENT_SCOPE)
28-
endfunction()
29-
30-
# NOTE: LLVM_TARGET_DEPENDS gets picked up by tablegen targets to add file
31-
# level dependencies. This is gross but CMake requires depending on both
32-
# targets and generated files, and it must be done when the custom target is
33-
# declared (there is no way to add after the fact).
34-
set(LLVM_TARGET_DEPENDS "")
351
add_linalg_ods_yaml_gen(LinalgNamedStructuredOps.yaml LinalgNamedStructuredOps)
2+
add_public_tablegen_target(MLIRLinalgNamedStructuredOpsYamlIncGen)
363

374
# Provide a short name for all external dependency that needs to
385
# include Linalg in ODS

mlir/lib/Dialect/Linalg/IR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_mlir_dialect_library(MLIRLinalgDialect
99

1010
DEPENDS
1111
MLIRLinalgInterfacesIncGen
12+
MLIRLinalgNamedStructuredOpsYamlIncGen
1213
MLIRLinalgOpsAttributesIncGen
1314
MLIRLinalgOpsEnumsIncGen
1415
MLIRLinalgOpsIncGen

mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ set(LLVM_LINK_COMPONENTS
33
Support
44
)
55

6-
# New mlir-linalg-ods-yaml-gen.
7-
add_mlir_tool(mlir-linalg-ods-yaml-gen
8-
mlir-linalg-ods-yaml-gen.cpp
9-
)
10-
llvm_update_compile_flags(mlir-linalg-ods-yaml-gen)
11-
target_link_libraries(mlir-linalg-ods-yaml-gen PRIVATE
6+
set(LIBS
127
MLIRIR
138
MLIRSupport
149
MLIRParser
15-
)
10+
)
1611

17-
setup_host_tool(mlir-linalg-ods-yaml-gen MLIR_LINALG_ODS_YAML_GEN MLIR_LINALG_ODS_YAML_GEN_EXE MLIR_LINALG_ODS_YAML_GEN_TARGET)
12+
# New mlir-linalg-ods-yaml-gen.
13+
add_tablegen(mlir-linalg-ods-yaml-gen MLIR_LINALG_ODS_YAML_GEN
14+
DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
15+
EXPORT MLIR
16+
SKIP_COMPONENT_LINK
17+
mlir-linalg-ods-yaml-gen.cpp
1818

19-
if(NOT ${MLIR_LINALG_ODS_YAML_GEN_EXE} STREQUAL "mlir-linalg-ods-yaml-gen")
20-
add_custom_target(mlir-linalg-ods-yaml-gen-host DEPENDS ${MLIR_LINALG_ODS_YAML_GEN_EXE})
19+
DEPENDS
20+
${LIBS}
21+
)
22+
set_target_properties(mlir-linalg-ods-yaml-gen PROPERTIES FOLDER "Tablegenning")
23+
target_link_libraries(mlir-linalg-ods-yaml-gen PRIVATE ${LIBS})
2124

22-
if(NOT LLVM_BUILD_UTILS)
23-
set_target_properties(mlir-linalg-ods-yaml-gen PROPERTIES EXCLUDE_FROM_ALL ON)
24-
endif()
25-
endif()
25+
mlir_check_all_link_libraries(mlir-linalg-ods-yaml-gen)
2626

2727
configure_file(
2828
update_core_linalg_named_ops.sh.in

0 commit comments

Comments
 (0)