Skip to content

Commit c4afecc

Browse files
[llvm][CMake][TableGen] Add all TableGen files to tablegen_compile_commands.yml (#71686)
This file is a list of files and their required include dirs, used by the TableGen LSP server (https://mlir.llvm.org/docs/Tools/MLIRLSP/#tablegen-lsp-language-server--tblgen-lsp-server). Initialy this only included MLIR TableGen files, so I've expanded that by moving it into llvm so all projects that use the llvm `tablegen` function will be added to the file. You could already do some things in llvm TableGen files without this, but were limited with files that don't include their dependencies using `include`, only with command line arguments. Once those are in the yml file, the language server sees all that and go to definition etc. all works.
1 parent 56daf02 commit c4afecc

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

llvm/cmake/modules/TableGen.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Adds the name of the generated file to TABLEGEN_OUTPUT.
55
include(LLVMDistributionSupport)
66

7+
# Clear out any pre-existing compile_commands file before processing. This
8+
# allows for generating a clean compile_commands on each configure.
9+
file(REMOVE ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml)
10+
711
function(tablegen project ofn)
812
cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN})
913

@@ -91,6 +95,29 @@ function(tablegen project ofn)
9195
# but lets us having smaller and cleaner code here.
9296
get_directory_property(tblgen_includes INCLUDE_DIRECTORIES)
9397
list(APPEND tblgen_includes ${ARG_EXTRA_INCLUDES})
98+
99+
# Get the current set of include paths for this td file.
100+
cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN})
101+
get_directory_property(tblgen_includes INCLUDE_DIRECTORIES)
102+
list(APPEND tblgen_includes ${ARG_EXTRA_INCLUDES})
103+
# Filter out any empty include items.
104+
list(REMOVE_ITEM tblgen_includes "")
105+
106+
# Build the absolute path for the current input file.
107+
if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
108+
set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
109+
else()
110+
set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS})
111+
endif()
112+
113+
# Append this file and its includes to the compile commands file.
114+
# This file is used by the TableGen LSP Language Server (tblgen-lsp-server).
115+
file(APPEND ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml
116+
"--- !FileInfo:\n"
117+
" filepath: \"${LLVM_TARGET_DEFINITIONS_ABSOLUTE}\"\n"
118+
" includes: \"${CMAKE_CURRENT_SOURCE_DIR};${tblgen_includes}\"\n"
119+
)
120+
94121
# Filter out empty items before prepending each entry with -I
95122
list(REMOVE_ITEM tblgen_includes "")
96123
list(TRANSFORM tblgen_includes PREPEND -I)

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
11
include(GNUInstallDirs)
22
include(LLVMDistributionSupport)
33

4-
# Clear out any pre-existing compile_commands file before processing. This
5-
# allows for generating a clean compile_commands on each configure.
6-
file(REMOVE ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml)
7-
84
function(mlir_tablegen ofn)
95
tablegen(MLIR ${ARGV})
106
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
117
PARENT_SCOPE)
12-
13-
# Get the current set of include paths for this td file.
14-
cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN})
15-
get_directory_property(tblgen_includes INCLUDE_DIRECTORIES)
16-
list(APPEND tblgen_includes ${ARG_EXTRA_INCLUDES})
17-
# Filter out any empty include items.
18-
list(REMOVE_ITEM tblgen_includes "")
19-
20-
# Build the absolute path for the current input file.
21-
if (IS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
22-
set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${LLVM_TARGET_DEFINITIONS})
23-
else()
24-
set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS})
25-
endif()
26-
27-
# Append the includes used for this file to the tablegen_compile_commands
28-
# file.
29-
file(APPEND ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml
30-
"--- !FileInfo:\n"
31-
" filepath: \"${LLVM_TARGET_DEFINITIONS_ABSOLUTE}\"\n"
32-
" includes: \"${CMAKE_CURRENT_SOURCE_DIR};${tblgen_includes}\"\n"
33-
)
348
endfunction()
359

3610
# Clear out any pre-existing compile_commands file before processing. This

0 commit comments

Comments
 (0)