Skip to content

Commit 27f3002

Browse files
committed
[llvm-(min-)tblgen] Avoid redundant source compilation (#114494)
All the sources of `llvm-min-tblgen` are also used for `llvm-tblgen`, with identical compilation flags. Reuse the object files of `llvm-min-tblgen` for `llvm-tblgen` by applying the usual source structure of an executable: One file per executable which named after the executable name containing the (in this case trivial) main function, which just calls the tblgen_main in TableGen.cpp. This should also clear up any confusion (including mine) of where each executable's main function is. While this slightly reduces build time, the main motivation is ccache. Using the 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 are shared between all hard-linked files s.t. this will indirectly also update the time stamps for the object files used for `llvm-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-tblgen`... . This is especially annoying for tablegen because it means Ninja will re-run all tablegenning in every build. I am using the hard_link option because it reduces the cost of having multiple build-trees of the LLVM sources and reduces the wear to the SSD they are stored on.
1 parent 3ef7818 commit 27f3002

12 files changed

+71
-18
lines changed

llvm/utils/TableGen/Basic/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ set(LLVM_LINK_COMPONENTS
99
)
1010

1111
add_llvm_library(LLVMTableGenBasic OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
12+
ARMTargetDefEmitter.cpp
13+
Attributes.cpp
1214
CodeGenIntrinsics.cpp
15+
DirectiveEmitter.cpp
16+
IntrinsicEmitter.cpp
17+
RISCVTargetDefEmitter.cpp
1318
SDNodeProperties.cpp
19+
TableGen.cpp
20+
VTEmitter.cpp
1421
)
1522

1623
# Users may include its headers as "Basic/*.h"

llvm/utils/TableGen/IntrinsicEmitter.cpp renamed to llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "Basic/CodeGenIntrinsics.h"
14-
#include "Basic/SequenceToOffsetTable.h"
13+
#include "CodeGenIntrinsics.h"
14+
#include "SequenceToOffsetTable.h"
1515
#include "llvm/ADT/STLExtras.h"
1616
#include "llvm/ADT/SmallVector.h"
1717
#include "llvm/ADT/StringRef.h"

llvm/utils/TableGen/TableGen.cpp renamed to llvm/utils/TableGen/Basic/TableGen.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file contains the main function for LLVM's TableGen.
9+
// This file contains the global defintions (mostly command line parameters)
10+
// shared between llvm-tblgen and llvm-min-tblgen.
1011
//
1112
//===----------------------------------------------------------------------===//
1213

14+
#include "TableGen.h"
1315
#include "llvm/ADT/StringRef.h"
1416
#include "llvm/Support/CommandLine.h"
1517
#include "llvm/Support/InitLLVM.h"
@@ -74,7 +76,7 @@ static TableGen::Emitter::Opt X[] = {
7476
{"print-sets", printSets, "Print expanded sets for testing DAG exprs"},
7577
};
7678

77-
int main(int argc, char **argv) {
79+
int tblgen_main(int argc, char **argv) {
7880
InitLLVM X(argc, argv);
7981
cl::ParseCommandLineOptions(argc, argv);
8082

llvm/utils/TableGen/Basic/TableGen.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===- TableGen.h ---------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Shared entry point for llvm-tblgen and llvm-min-tblgen.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
int tblgen_main(int argc, char **argv);

llvm/utils/TableGen/CMakeLists.txt

+9-14
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ set(LLVM_LINK_COMPONENTS Support)
1111
# build llvm/include. It must not depend on TableGenCommon, as
1212
# TableGenCommon depends on this already to generate things such as
1313
# ValueType definitions.
14+
# Sources included in both, llvm-min-tblgen and llvm-tblgen, must be included
15+
# into LLVMTableGenBasic to avoid redundant compilation and problems with build
16+
# caches.
17+
# At least one source file must be included directly to avoid CMake problems.
18+
# E.g. CMake derives which linker to use from the types of sources added.
1419
add_tablegen(llvm-min-tblgen LLVM_HEADERS
15-
TableGen.cpp
16-
ARMTargetDefEmitter.cpp
17-
Attributes.cpp
18-
DirectiveEmitter.cpp
19-
IntrinsicEmitter.cpp
20-
RISCVTargetDefEmitter.cpp
21-
VTEmitter.cpp
20+
llvm-min-tblgen.cpp
2221
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
2322

2423
PARTIAL_SOURCES_INTENDED
@@ -32,10 +31,8 @@ set(LLVM_LINK_COMPONENTS
3231
add_tablegen(llvm-tblgen LLVM
3332
DESTINATION "${LLVM_TOOLS_INSTALL_DIR}"
3433
EXPORT LLVM
35-
ARMTargetDefEmitter.cpp
3634
AsmMatcherEmitter.cpp
3735
AsmWriterEmitter.cpp
38-
Attributes.cpp
3936
CallingConvEmitter.cpp
4037
CodeEmitterGen.cpp
4138
CodeGenMapTable.cpp
@@ -48,7 +45,6 @@ add_tablegen(llvm-tblgen LLVM
4845
DecoderEmitter.cpp
4946
DFAEmitter.cpp
5047
DFAPacketizerEmitter.cpp
51-
DirectiveEmitter.cpp
5248
DisassemblerEmitter.cpp
5349
DXILEmitter.cpp
5450
ExegesisEmitter.cpp
@@ -57,18 +53,15 @@ add_tablegen(llvm-tblgen LLVM
5753
GlobalISelEmitter.cpp
5854
InstrDocsEmitter.cpp
5955
InstrInfoEmitter.cpp
60-
IntrinsicEmitter.cpp
56+
llvm-tblgen.cpp
6157
MacroFusionPredicatorEmitter.cpp
6258
OptionParserEmitter.cpp
6359
OptionRSTEmitter.cpp
6460
PseudoLoweringEmitter.cpp
6561
RegisterBankEmitter.cpp
6662
RegisterInfoEmitter.cpp
67-
RISCVTargetDefEmitter.cpp
6863
SearchableTableEmitter.cpp
6964
SubtargetEmitter.cpp
70-
TableGen.cpp
71-
VTEmitter.cpp
7265
WebAssemblyDisassemblerEmitter.cpp
7366
X86InstrMappingEmitter.cpp
7467
X86DisassemblerTables.cpp
@@ -79,6 +72,8 @@ add_tablegen(llvm-tblgen LLVM
7972
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
8073
$<TARGET_OBJECTS:obj.LLVMTableGenCommon>
8174

75+
PARTIAL_SOURCES_INTENDED
76+
8277
DEPENDS
8378
intrinsics_gen # via llvm-min-tablegen
8479
)
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===- llvm-min-tblgen.cpp ------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains the main function for LLVM's TableGen.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "Basic/TableGen.h"
14+
15+
/// Command line parameters are shared between llvm-tblgen and llvm-min-tblgen.
16+
/// The indirection to tblgen_main exists to ensure that the static variables
17+
/// for the llvm::cl:: mechanism are linked into both executables.
18+
int main(int argc, char **argv) { return tblgen_main(argc, argv); }

llvm/utils/TableGen/llvm-tblgen.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===- llvm-tblgen.cpp ----------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains the main function for LLVM's TableGen.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "Basic/TableGen.h"
14+
15+
/// Command line parameters are shared between llvm-tblgen and llvm-min-tblgen.
16+
/// The indirection to tblgen_main exists to ensure that the static variables
17+
/// for the llvm::cl:: mechanism are linked into both executables.
18+
int main(int argc, char **argv) { return tblgen_main(argc, argv); }

0 commit comments

Comments
 (0)