[llvm] [llvm-(min-)tblgen] Avoid redundant source compilation (PR #114494)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 17:57:43 PDT 2024
https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/114494
All the sources of `llvm-min-tblgen` are also used for `llvm-tblgen`, with identical compilation flags. Use a CMake object library to avoid building these files twice.
While this slightly reduces build time, the main motivation is ccache. Using the [hard_link](https://ccache.dev/manual/latest.html#config_hard_link) option, building the object files for `llvm-tblgen` will result in a hard link to the same object file already used for `llvm-min-tblgen`. To signal the build system that the file is new, ccache will update the file's time stamp. Unfortunately, time stamps a shared between all hard-linked file s.t. this will also update the time stamps for the object files used for `llvm-min-tblgen`. At the next run, Ninja will recognize this time stamp discrepancy to the expected stamp recorded in `.ninja.log` and rebuild those object files for `llvm-min-tblgen`, which again will also update the stamp for the `llvm-min-tblgen`... . This is especially annoying for `llvm-(min)-tablegen` because it means Ninja will rerun all tablegenning in every build.
I am using the hard_link option because it reduces the cost of having multiple build-trees of the same LLVM source tree and reduces the wear to the SSD they are stored on.
>From 94dd647c3c405f5622243aab4447cdcb0194f63d Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 1 Nov 2024 01:40:07 +0100
Subject: [PATCH] [llvm-(min-)tblgen] Avoid redundant source compilation
---
llvm/utils/TableGen/CMakeLists.txt | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index ba1e4aa01b48d6..5a460034bd9fd7 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -7,11 +7,8 @@ add_subdirectory(Common)
set(LLVM_LINK_COMPONENTS Support)
-# llvm-min-tablegen only contains a subset of backends necessary to
-# build llvm/include. It must not depend on TableGenCommon, as
-# TableGenCommon depends on this already to generate things such as
-# ValueType definitions.
-add_tablegen(llvm-min-tblgen LLVM_HEADERS
+# Sources included in llvm-min-tblgen and llvm-tblgen.
+add_llvm_library(LLVMTableGenBoth OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
TableGen.cpp
ARMTargetDefEmitter.cpp
Attributes.cpp
@@ -19,6 +16,16 @@ add_tablegen(llvm-min-tblgen LLVM_HEADERS
IntrinsicEmitter.cpp
RISCVTargetDefEmitter.cpp
VTEmitter.cpp
+
+ PARTIAL_SOURCES_INTENDED
+ )
+
+# llvm-min-tablegen only contains a subset of backends necessary to
+# build llvm/include. It must not depend on TableGenCommon, as
+# TableGenCommon depends on this already to generate things such as
+# ValueType definitions.
+add_tablegen(llvm-min-tblgen LLVM_HEADERS
+ $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
PARTIAL_SOURCES_INTENDED
@@ -32,10 +39,8 @@ set(LLVM_LINK_COMPONENTS
add_tablegen(llvm-tblgen LLVM
DESTINATION "${LLVM_TOOLS_INSTALL_DIR}"
EXPORT LLVM
- ARMTargetDefEmitter.cpp
AsmMatcherEmitter.cpp
AsmWriterEmitter.cpp
- Attributes.cpp
CallingConvEmitter.cpp
CodeEmitterGen.cpp
CodeGenMapTable.cpp
@@ -48,7 +53,6 @@ add_tablegen(llvm-tblgen LLVM
DecoderEmitter.cpp
DFAEmitter.cpp
DFAPacketizerEmitter.cpp
- DirectiveEmitter.cpp
DisassemblerEmitter.cpp
DXILEmitter.cpp
ExegesisEmitter.cpp
@@ -57,18 +61,14 @@ add_tablegen(llvm-tblgen LLVM
GlobalISelEmitter.cpp
InstrDocsEmitter.cpp
InstrInfoEmitter.cpp
- IntrinsicEmitter.cpp
MacroFusionPredicatorEmitter.cpp
OptionParserEmitter.cpp
OptionRSTEmitter.cpp
PseudoLoweringEmitter.cpp
RegisterBankEmitter.cpp
RegisterInfoEmitter.cpp
- RISCVTargetDefEmitter.cpp
SearchableTableEmitter.cpp
SubtargetEmitter.cpp
- TableGen.cpp
- VTEmitter.cpp
WebAssemblyDisassemblerEmitter.cpp
X86InstrMappingEmitter.cpp
X86DisassemblerTables.cpp
@@ -76,6 +76,8 @@ add_tablegen(llvm-tblgen LLVM
X86MnemonicTables.cpp
X86ModRMFilters.cpp
X86RecognizableInstr.cpp
+
+ $<TARGET_OBJECTS:obj.LLVMTableGenBoth>
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
$<TARGET_OBJECTS:obj.LLVMTableGenCommon>
More information about the llvm-commits
mailing list