Skip to content

Commit

Permalink
[mlir] fix add_tablegen() macro to allow installing mlir-pdll
Browse files Browse the repository at this point in the history
Prior to this patch, the `add_tablegen()` macro in
llvm/cmake/modules/TableGen.cmake added the install rule only if
`project` matched `LLVM` or `MLIR`.  This patch adds an optional
`DESTINATION` argument, which, if non-empty, decides whether (and where)
to install the tablegen tool, thus eliminating the need for
project-specific overrides.  This patch also updates all other
invocations of the `add_tablegen()` macro.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D131282
  • Loading branch information
ashay committed Aug 7, 2022
1 parent 10de551 commit d1bb301
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion clang/utils/TableGen/CMakeLists.txt
@@ -1,6 +1,6 @@
set(LLVM_LINK_COMPONENTS Support)

add_tablegen(clang-tblgen CLANG
add_tablegen(clang-tblgen CLANG DESTINATION "${CLANG_TOOLS_INSTALL_DIR}"
ASTTableGen.cpp
ClangASTNodesEmitter.cpp
ClangASTPropertiesEmitter.cpp
Expand Down
9 changes: 6 additions & 3 deletions llvm/cmake/modules/TableGen.cmake
Expand Up @@ -140,6 +140,8 @@ function(add_public_tablegen_target target)
endfunction()

macro(add_tablegen target project)
cmake_parse_arguments(ADD_TABLEGEN "" "DESTINATION" "" ${ARGN})

set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)

Expand All @@ -149,7 +151,8 @@ macro(add_tablegen target project)
set(LLVM_ENABLE_OBJLIB ON)
endif()

add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
add_llvm_executable(${target} DISABLE_LLVM_LINK_LLVM_DYLIB
${ADD_TABLEGEN_UNPARSED_ARGUMENTS})
set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS})

set(${project}_TABLEGEN "${target}" CACHE
Expand Down Expand Up @@ -186,7 +189,7 @@ macro(add_tablegen target project)
endif()
endif()

if ((${project} STREQUAL LLVM OR ${project} STREQUAL MLIR) AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_BUILD_UTILS)
if (ADD_TABLEGEN_DESTINATION AND NOT LLVM_INSTALL_TOOLCHAIN_ONLY AND LLVM_BUILD_UTILS)
set(export_to_llvmexports)
if(${target} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
NOT LLVM_DISTRIBUTION_COMPONENTS)
Expand All @@ -196,7 +199,7 @@ macro(add_tablegen target project)
install(TARGETS ${target}
${export_to_llvmexports}
COMPONENT ${target}
RUNTIME DESTINATION "${${project}_TOOLS_INSTALL_DIR}")
RUNTIME DESTINATION "${ADD_TABLEGEN_DESTINATION}")
if(NOT LLVM_ENABLE_IDE)
add_llvm_install_targets("install-${target}"
DEPENDS ${target}
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/CMakeLists.txt
Expand Up @@ -2,7 +2,7 @@ add_subdirectory(GlobalISel)

set(LLVM_LINK_COMPONENTS Support)

add_tablegen(llvm-tblgen LLVM
add_tablegen(llvm-tblgen LLVM DESTINATION "${LLVM_TOOLS_INSTALL_DIR}"
AsmMatcherEmitter.cpp
AsmWriterEmitter.cpp
AsmWriterInst.cpp
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-pdll/CMakeLists.txt
Expand Up @@ -12,7 +12,7 @@ set(LIBS
MLIRPDLLParser
)

add_tablegen(mlir-pdll MLIR_PDLL
add_tablegen(mlir-pdll MLIR_PDLL DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
mlir-pdll.cpp

DEPENDS
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-tblgen/CMakeLists.txt
Expand Up @@ -4,7 +4,7 @@ set(LLVM_LINK_COMPONENTS
TableGen
)

add_tablegen(mlir-tblgen MLIR
add_tablegen(mlir-tblgen MLIR DESTINATION "${MLIR_TOOLS_INSTALL_DIR}"
AttrOrTypeDefGen.cpp
AttrOrTypeFormatGen.cpp
CodeGenHelpers.cpp
Expand Down

0 comments on commit d1bb301

Please sign in to comment.