Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm][CMake][TableGen] Add all TableGen files to tablegen_compile_commands.yml #71686

Merged
merged 3 commits into from
Nov 16, 2023

Conversation

DavidSpickett
Copy link
Collaborator

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.

…mmands.yml

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.
@llvmbot llvmbot added cmake Build system in general and CMake in particular mlir labels Nov 8, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 8, 2023

@llvm/pr-subscribers-mlir

Author: David Spickett (DavidSpickett)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/71686.diff

2 Files Affected:

  • (modified) llvm/cmake/modules/TableGen.cmake (+13)
  • (modified) mlir/cmake/modules/AddMLIR.cmake (-12)
diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
index 7fd6628ef55d33a..b495bd9a01e0193 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -4,6 +4,10 @@
 # Adds the name of the generated file to TABLEGEN_OUTPUT.
 include(LLVMDistributionSupport)
 
+# Clear out any pre-existing compile_commands file before processing. This
+# allows for generating a clean compile_commands on each configure.
+file(REMOVE ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml)
+
 function(tablegen project ofn)
   cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN})
 
@@ -91,6 +95,15 @@ function(tablegen project ofn)
   # but lets us having smaller and cleaner code here.
   get_directory_property(tblgen_includes INCLUDE_DIRECTORIES)
   list(APPEND tblgen_includes ${ARG_EXTRA_INCLUDES})
+
+  # Append the includes used for this file to the tablegen_compile_commands
+  # file.
+  file(APPEND ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml
+      "--- !FileInfo:\n"
+      "  filepath: \"${LLVM_TARGET_DEFINITIONS_ABSOLUTE}\"\n"
+      "  includes: \"${CMAKE_CURRENT_SOURCE_DIR};${tblgen_includes}\"\n"
+  )
+
   # Filter out empty items before prepending each entry with -I
   list(REMOVE_ITEM tblgen_includes "")
   list(TRANSFORM tblgen_includes PREPEND -I)
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index 544abe43688820e..2a77a73eefe7bf1 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -1,10 +1,6 @@
 include(GNUInstallDirs)
 include(LLVMDistributionSupport)
 
-# Clear out any pre-existing compile_commands file before processing. This
-# allows for generating a clean compile_commands on each configure.
-file(REMOVE ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml)
-
 function(mlir_tablegen ofn)
   tablegen(MLIR ${ARGV})
   set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
@@ -23,14 +19,6 @@ function(mlir_tablegen ofn)
   else()
     set(LLVM_TARGET_DEFINITIONS_ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS})
   endif()
-
-  # Append the includes used for this file to the tablegen_compile_commands
-  # file.
-  file(APPEND ${CMAKE_BINARY_DIR}/tablegen_compile_commands.yml
-      "--- !FileInfo:\n"
-      "  filepath: \"${LLVM_TARGET_DEFINITIONS_ABSOLUTE}\"\n"
-      "  includes: \"${CMAKE_CURRENT_SOURCE_DIR};${tblgen_includes}\"\n"
-  )
 endfunction()
 
 # Clear out any pre-existing compile_commands file before processing. This

@DavidSpickett
Copy link
Collaborator Author

ping!

llvm/cmake/modules/TableGen.cmake Outdated Show resolved Hide resolved
@DavidSpickett DavidSpickett merged commit c4afecc into llvm:main Nov 16, 2023
2 of 3 checks passed
sr-tream pushed a commit to sr-tream/llvm-project that referenced this pull request Nov 20, 2023
…mmands.yml (llvm#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.
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
…mmands.yml (llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants