Skip to content

Conversation

@zero9178
Copy link
Member

@zero9178 zero9178 commented Jul 8, 2025

Depending on the order of CMake includes the tablegen_compile_commands.yml was previously missing entries due to being deleted after a tablegen commands.

This PR fixes this by 1) making sure AddMLIR includes TableGen such that new compile commands are added to a fresh YML file and 2) using an include guard to ensure the file is cleared exactly once

Depending on the order of CMake includes the `tablegen_compile_commands.yml` was previously missing entries due to being deleted after a `tablegen` commands.

This PR fixes this by 1) making sure `AddMLIR` includes `TableGen` such that new compile commands are added to a fresh YML file and 2) using an include guard to ensure the file is cleared exactly once
@llvmbot llvmbot added cmake Build system in general and CMake in particular mlir labels Jul 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2025

@llvm/pr-subscribers-mlir

Author: Markus Böck (zero9178)

Changes

Depending on the order of CMake includes the tablegen_compile_commands.yml was previously missing entries due to being deleted after a tablegen commands.

This PR fixes this by 1) making sure AddMLIR includes TableGen such that new compile commands are added to a fresh YML file and 2) using an include guard to ensure the file is cleared exactly once


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

2 Files Affected:

  • (modified) llvm/cmake/modules/TableGen.cmake (+8-4)
  • (modified) mlir/cmake/modules/AddMLIR.cmake (+1)
diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
index 67a628d4953c3..9a2e73a1e3718 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -4,10 +4,6 @@
 # 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})
 
@@ -250,3 +246,11 @@ macro(add_tablegen target project)
     set_property(GLOBAL APPEND PROPERTY ${export_upper}_EXPORTS ${target})
   endif()
 endmacro()
+
+# Make sure 'tablegen_compile_commands.yml' is only deleted once the very
+# first time this file is included.
+include_guard(GLOBAL)
+
+# 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)
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index 353e64b3d013e..ff4269ed7acd2 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -1,3 +1,4 @@
+include(TableGen)
 include(GNUInstallDirs)
 include(LLVMDistributionSupport)
 

Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks (not sure if there is easy way to test this)

@zero9178 zero9178 merged commit 136558b into llvm:main Jul 11, 2025
12 checks passed
@zero9178 zero9178 deleted the tablegen-compile-commands branch July 11, 2025 20:25
@River707
Copy link
Contributor

Thanks for this!

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.

4 participants