[Mlir-commits] [llvm] [mlir] [mlir] Fix link issue in mlir-linalg-ods-gen (PR #76843)

Michael Holman llvmlistbot at llvm.org
Wed Jan 3 13:46:45 PST 2024


https://github.com/MikeHolman updated https://github.com/llvm/llvm-project/pull/76843

>From 5f385a57898c3ad86ccce8c2a95454adfdca43bd Mon Sep 17 00:00:00 2001
From: Michael Holman <michhol at microsoft.com>
Date: Wed, 3 Jan 2024 21:40:54 +0000
Subject: [PATCH 1/2] Reapply "[mlir] Consider mlir-linalg-ods-gen as a
 tablegen tool in build (#75093)"

This reverts commit a24c58140fbd73d5b98f8fa88cf9a9dbf0613a41.
---
 llvm/cmake/modules/TableGen.cmake             | 12 ++++---
 mlir/CMakeLists.txt                           |  2 ++
 mlir/cmake/modules/AddMLIR.cmake              | 25 +++++++++++++
 mlir/cmake/modules/CMakeLists.txt             |  2 ++
 mlir/cmake/modules/MLIRConfig.cmake.in        |  1 +
 .../mlir/Dialect/Linalg/IR/CMakeLists.txt     | 35 +------------------
 mlir/lib/Dialect/Linalg/IR/CMakeLists.txt     |  1 +
 mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt | 28 +++++++--------
 8 files changed, 54 insertions(+), 52 deletions(-)

diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
index 1d18fdde2bb98b..359d5217a22cb6 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -165,14 +165,18 @@ function(add_public_tablegen_target target)
 endfunction()
 
 macro(add_tablegen target project)
-  cmake_parse_arguments(ADD_TABLEGEN "" "DESTINATION;EXPORT" "" ${ARGN})
+  cmake_parse_arguments(ADD_TABLEGEN "SKIP_COMPONENT_LINK" "DESTINATION;EXPORT" "" ${ARGN})
 
-  set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
-  set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
+  if(NOT ADD_TABLEGEN_SKIP_COMPONENT_LINK)
+    set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
+    set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
+  endif()
 
   add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB
     ${ADD_TABLEGEN_UNPARSED_ARGUMENTS})
-  set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})
+  if(NOT ADD_TABLEGEN_SKIP_COMPONENT_LINK)
+    set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})
+  endif()
 
   set(${project}_TABLEGEN_DEFAULT "${target}")
   if (LLVM_NATIVE_TOOL_DIR)
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index 16ff950089734b..dcc068e4097c5c 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -184,6 +184,8 @@ add_subdirectory(tools/mlir-pdll)
 
 set(MLIR_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}" CACHE INTERNAL "")
 set(MLIR_TABLEGEN_TARGET "${MLIR_TABLEGEN_TARGET}" CACHE INTERNAL "")
+set(MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE "${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE}" CACHE INTERNAL "")
+set(MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_TARGET "${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_TARGET}" CACHE INTERNAL "")
 set(MLIR_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}" CACHE INTERNAL "")
 set(MLIR_PDLL_TABLEGEN_TARGET "${MLIR_PDLL_TABLEGEN_TARGET}" CACHE INTERNAL "")
 
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index 1d2ed748bc2f13..971ea7eceff4cc 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -136,6 +136,31 @@ function(add_mlir_pdll_library target inputFile ofn)
   add_public_tablegen_target(${target})
 endfunction()
 
+# Declare a function to generate ODS with mlir-linalg-ods-yaml-gen
+function(add_linalg_ods_yaml_gen yaml_ast_file output_file)
+  set(YAML_AST_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${yaml_ast_file})
+  set(GEN_ODS_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.td)
+  set(GEN_CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.cpp.inc)
+  set_source_files_properties(
+    ${GEN_ODS_FILE}
+    PROPERTIES GENERATED TRUE)
+  set_source_files_properties(
+    ${GEN_CPP_FILE}
+    PROPERTIES GENERATED TRUE)
+  add_custom_command(
+    OUTPUT ${GEN_ODS_FILE} ${GEN_CPP_FILE}
+    COMMAND ${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE} ${YAML_AST_SOURCE} -o-ods-decl=${GEN_ODS_FILE} -o-impl=${GEN_CPP_FILE}
+    MAIN_DEPENDENCY
+    ${YAML_AST_SOURCE}
+    DEPENDS
+    ${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE}
+    ${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_TARGET}
+    ${LLVM_TARGET_DEPENDS})
+    
+  set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${GEN_ODS_FILE} ${GEN_CPP_FILE}
+      PARENT_SCOPE)
+endfunction()
+
 # Declare a dialect in the include directory
 function(add_mlir_dialect dialect dialect_namespace)
   set(LLVM_TARGET_DEFINITIONS ${dialect}.td)
diff --git a/mlir/cmake/modules/CMakeLists.txt b/mlir/cmake/modules/CMakeLists.txt
index 8d2904ef46dfe8..2b72beff893853 100644
--- a/mlir/cmake/modules/CMakeLists.txt
+++ b/mlir/cmake/modules/CMakeLists.txt
@@ -38,6 +38,7 @@ set(MLIR_CONFIG_INCLUDE_DIRS
   )
 # Refer to the best host mlir-tbgen, which might be a host-optimized version
 set(MLIR_CONFIG_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}")
+set(MLIR_CONFIG_LINALG_ODS_YAML_GEN_TABLEGEN_EXE "${MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE}")
 set(MLIR_CONFIG_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}")
 
 configure_file(
@@ -76,6 +77,7 @@ set(MLIR_CONFIG_INCLUDE_DIRS
 # Ensure that we are using the installed mlir-tblgen. This might not be MLIR_TABLEGEN_EXE
 # if we're building with a host-optimized mlir-tblgen (with LLVM_OPTIMIZED_TABLEGEN).
 set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)
+set(MLIR_CONFIG_LINALG_ODS_YAML_GEN_TABLEGEN_EXE mlir-linalg-ods-yaml-gen)
 set(MLIR_CONFIG_PDLL_TABLEGEN_EXE mlir-pdll)
 
 configure_file(
diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in
index d4da3cd98cce98..0922b9accea5d4 100644
--- a/mlir/cmake/modules/MLIRConfig.cmake.in
+++ b/mlir/cmake/modules/MLIRConfig.cmake.in
@@ -10,6 +10,7 @@ set(MLIR_EXPORTED_TARGETS "@MLIR_EXPORTS@")
 set(MLIR_CMAKE_DIR "@MLIR_CONFIG_CMAKE_DIR@")
 set(MLIR_INCLUDE_DIRS "@MLIR_CONFIG_INCLUDE_DIRS@")
 set(MLIR_TABLEGEN_EXE "@MLIR_CONFIG_TABLEGEN_EXE@")
+set(MLIR_LINALG_ODS_YAML_GEN_TABLEGEN_EXE "@MLIR_CONFIG_LINALG_ODS_YAML_GEN_TABLEGEN_EXE@")
 set(MLIR_PDLL_TABLEGEN_EXE "@MLIR_CONFIG_PDLL_TABLEGEN_EXE@")
 set(MLIR_INSTALL_AGGREGATE_OBJECTS "@MLIR_INSTALL_AGGREGATE_OBJECTS@")
 set(MLIR_ENABLE_BINDINGS_PYTHON "@MLIR_ENABLE_BINDINGS_PYTHON@")
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
index f5d48b2ebcefe5..c30665d4d118bf 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt
@@ -1,38 +1,5 @@
-# Declare a function to generate ODS with mlir-linalg-ods-yaml-gen
-function(add_linalg_ods_yaml_gen yaml_ast_file output_file)
-  set(YAML_AST_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${yaml_ast_file})
-  set(GEN_ODS_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.td)
-  set(GEN_CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.yamlgen.cpp.inc)
-  set_source_files_properties(
-    ${GEN_ODS_FILE}
-    PROPERTIES GENERATED TRUE)
-  set_source_files_properties(
-    ${GEN_CPP_FILE}
-    PROPERTIES GENERATED TRUE)
-  add_custom_command(
-    OUTPUT ${GEN_ODS_FILE} ${GEN_CPP_FILE}
-    COMMAND ${MLIR_LINALG_ODS_YAML_GEN_EXE} ${YAML_AST_SOURCE} -o-ods-decl=${GEN_ODS_FILE} -o-impl=${GEN_CPP_FILE}
-    MAIN_DEPENDENCY
-    ${YAML_AST_SOURCE}
-    DEPENDS
-    ${MLIR_LINALG_ODS_YAML_GEN_EXE}
-    ${MLIR_LINALG_ODS_YAML_GEN_TARGET})
-  add_custom_target(
-    MLIR${output_file}YamlIncGen
-    DEPENDS
-    ${MLIR_LINALG_ODS_YAML_GEN_EXE}
-    ${MLIR_LINALG_ODS_YAML_GEN_TARGET}
-    ${GEN_ODS_FILE} ${GEN_CPP_FILE})
-  list(APPEND LLVM_TARGET_DEPENDS ${GEN_ODS_FILE})
-  set(LLVM_TARGET_DEPENDS ${LLVM_TARGET_DEPENDS} PARENT_SCOPE)
-endfunction()
-
-# NOTE: LLVM_TARGET_DEPENDS gets picked up by tablegen targets to add file
-# level dependencies. This is gross but CMake requires depending on both
-# targets and generated files, and it must be done when the custom target is
-# declared (there is no way to add after the fact).
-set(LLVM_TARGET_DEPENDS "")
 add_linalg_ods_yaml_gen(LinalgNamedStructuredOps.yaml LinalgNamedStructuredOps)
+add_public_tablegen_target(MLIRLinalgNamedStructuredOpsYamlIncGen)
 
 # Provide a short name for all external dependency that needs to
 # include Linalg in ODS
diff --git a/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt b/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
index f0ac1899bb02ab..65b65014b23cf4 100644
--- a/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
+++ b/mlir/lib/Dialect/Linalg/IR/CMakeLists.txt
@@ -9,6 +9,7 @@ add_mlir_dialect_library(MLIRLinalgDialect
 
   DEPENDS
   MLIRLinalgInterfacesIncGen
+  MLIRLinalgNamedStructuredOpsYamlIncGen
   MLIRLinalgOpsAttributesIncGen
   MLIRLinalgOpsEnumsIncGen
   MLIRLinalgOpsIncGen
diff --git a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
index 787a0bb35d7b1f..2b2024da6409ac 100644
--- a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
+++ b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
@@ -3,26 +3,26 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-# New mlir-linalg-ods-yaml-gen.
-add_mlir_tool(mlir-linalg-ods-yaml-gen
-  mlir-linalg-ods-yaml-gen.cpp
-)
-llvm_update_compile_flags(mlir-linalg-ods-yaml-gen)
-target_link_libraries(mlir-linalg-ods-yaml-gen PRIVATE
+set(LIBS
   MLIRIR
   MLIRSupport
   MLIRParser
-  )
+)
 
-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)
+# New mlir-linalg-ods-yaml-gen.
+add_tablegen(mlir-linalg-ods-yaml-gen MLIR_LINALG_ODS_YAML_GEN
+  DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
+  EXPORT MLIR
+  SKIP_COMPONENT_LINK
+  mlir-linalg-ods-yaml-gen.cpp
 
-if(NOT ${MLIR_LINALG_ODS_YAML_GEN_EXE} STREQUAL "mlir-linalg-ods-yaml-gen")
-  add_custom_target(mlir-linalg-ods-yaml-gen-host DEPENDS ${MLIR_LINALG_ODS_YAML_GEN_EXE})
+  DEPENDS
+  ${LIBS}
+)
+set_target_properties(mlir-linalg-ods-yaml-gen PROPERTIES FOLDER "Tablegenning")
+target_link_libraries(mlir-linalg-ods-yaml-gen PRIVATE ${LIBS})
 
-  if(NOT LLVM_BUILD_UTILS)
-    set_target_properties(mlir-linalg-ods-yaml-gen PROPERTIES EXCLUDE_FROM_ALL ON)
-  endif()
-endif()
+mlir_check_all_link_libraries(mlir-linalg-ods-yaml-gen)
 
 configure_file(
   update_core_linalg_named_ops.sh.in

>From 6af184652ef9534872a2cdeff26867f6b2951f9e Mon Sep 17 00:00:00 2001
From: Michael Holman <michhol at microsoft.com>
Date: Wed, 3 Jan 2024 18:56:30 +0000
Subject: [PATCH 2/2] Fix link issue in mlir-linalg-ods-gen

---
 mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
index 2b2024da6409ac..f698469ebf05bd 100644
--- a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
+++ b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt
@@ -1,8 +1,3 @@
-set(LLVM_LINK_COMPONENTS
-  Core
-  Support
-  )
-
 set(LIBS
   MLIRIR
   MLIRSupport



More information about the Mlir-commits mailing list