Skip to content

Commit f6cb569

Browse files
authored
[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 f03b100 commit f6cb569

12 files changed

+71
-20
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-16
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ add_subdirectory(Basic)
55
# code needed by the backends.
66
add_subdirectory(Common)
77

8-
set(LLVM_LINK_COMPONENTS Support)
9-
108
# llvm-min-tablegen only contains a subset of backends necessary to
119
# build llvm/include. It must not depend on TableGenCommon, as
1210
# TableGenCommon depends on this already to generate things such as
1311
# ValueType definitions.
12+
# Sources included in both, llvm-min-tblgen and llvm-tblgen, must be included
13+
# into LLVMTableGenBasic to avoid redundant compilation and problems with build
14+
# caches.
15+
# At least one source file must be included directly to avoid CMake problems.
16+
# E.g. CMake derives which linker to use from the types of sources added.
1417
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
18+
llvm-min-tblgen.cpp
2219
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
2320

2421
PARTIAL_SOURCES_INTENDED
@@ -32,10 +29,8 @@ set(LLVM_LINK_COMPONENTS
3229
add_tablegen(llvm-tblgen LLVM
3330
DESTINATION "${LLVM_TOOLS_INSTALL_DIR}"
3431
EXPORT LLVM
35-
ARMTargetDefEmitter.cpp
3632
AsmMatcherEmitter.cpp
3733
AsmWriterEmitter.cpp
38-
Attributes.cpp
3934
CallingConvEmitter.cpp
4035
CodeEmitterGen.cpp
4136
CodeGenMapTable.cpp
@@ -48,7 +43,6 @@ add_tablegen(llvm-tblgen LLVM
4843
DecoderEmitter.cpp
4944
DFAEmitter.cpp
5045
DFAPacketizerEmitter.cpp
51-
DirectiveEmitter.cpp
5246
DisassemblerEmitter.cpp
5347
DXILEmitter.cpp
5448
ExegesisEmitter.cpp
@@ -57,18 +51,15 @@ add_tablegen(llvm-tblgen LLVM
5751
GlobalISelEmitter.cpp
5852
InstrDocsEmitter.cpp
5953
InstrInfoEmitter.cpp
60-
IntrinsicEmitter.cpp
54+
llvm-tblgen.cpp
6155
MacroFusionPredicatorEmitter.cpp
6256
OptionParserEmitter.cpp
6357
OptionRSTEmitter.cpp
6458
PseudoLoweringEmitter.cpp
6559
RegisterBankEmitter.cpp
6660
RegisterInfoEmitter.cpp
67-
RISCVTargetDefEmitter.cpp
6861
SearchableTableEmitter.cpp
6962
SubtargetEmitter.cpp
70-
TableGen.cpp
71-
VTEmitter.cpp
7263
WebAssemblyDisassemblerEmitter.cpp
7364
X86InstrMappingEmitter.cpp
7465
X86DisassemblerTables.cpp
@@ -79,6 +70,8 @@ add_tablegen(llvm-tblgen LLVM
7970
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
8071
$<TARGET_OBJECTS:obj.LLVMTableGenCommon>
8172

73+
PARTIAL_SOURCES_INTENDED
74+
8275
DEPENDS
8376
intrinsics_gen # via llvm-min-tablegen
8477
)
+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)