[llvm] f6cb569 - [llvm-(min-)tblgen] Avoid redundant source compilation (#114494)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 2 14:22:23 PST 2025
Author: Michael Kruse
Date: 2025-01-02T23:22:20+01:00
New Revision: f6cb56902c6dcafede21eb6662910b6ff661fc0f
URL: https://github.com/llvm/llvm-project/commit/f6cb56902c6dcafede21eb6662910b6ff661fc0f
DIFF: https://github.com/llvm/llvm-project/commit/f6cb56902c6dcafede21eb6662910b6ff661fc0f.diff
LOG: [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.
Added:
llvm/utils/TableGen/Basic/ARMTargetDefEmitter.cpp
llvm/utils/TableGen/Basic/Attributes.cpp
llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
llvm/utils/TableGen/Basic/RISCVTargetDefEmitter.cpp
llvm/utils/TableGen/Basic/TableGen.cpp
llvm/utils/TableGen/Basic/TableGen.h
llvm/utils/TableGen/Basic/VTEmitter.cpp
llvm/utils/TableGen/llvm-min-tblgen.cpp
llvm/utils/TableGen/llvm-tblgen.cpp
Modified:
llvm/utils/TableGen/Basic/CMakeLists.txt
llvm/utils/TableGen/CMakeLists.txt
Removed:
llvm/utils/TableGen/ARMTargetDefEmitter.cpp
llvm/utils/TableGen/Attributes.cpp
llvm/utils/TableGen/DirectiveEmitter.cpp
llvm/utils/TableGen/IntrinsicEmitter.cpp
llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
llvm/utils/TableGen/TableGen.cpp
llvm/utils/TableGen/VTEmitter.cpp
################################################################################
diff --git a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp b/llvm/utils/TableGen/Basic/ARMTargetDefEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/ARMTargetDefEmitter.cpp
rename to llvm/utils/TableGen/Basic/ARMTargetDefEmitter.cpp
diff --git a/llvm/utils/TableGen/Attributes.cpp b/llvm/utils/TableGen/Basic/Attributes.cpp
similarity index 100%
rename from llvm/utils/TableGen/Attributes.cpp
rename to llvm/utils/TableGen/Basic/Attributes.cpp
diff --git a/llvm/utils/TableGen/Basic/CMakeLists.txt b/llvm/utils/TableGen/Basic/CMakeLists.txt
index 41d737e8d418e2..b058fba78eb05a 100644
--- a/llvm/utils/TableGen/Basic/CMakeLists.txt
+++ b/llvm/utils/TableGen/Basic/CMakeLists.txt
@@ -9,8 +9,15 @@ set(LLVM_LINK_COMPONENTS
)
add_llvm_library(LLVMTableGenBasic OBJECT EXCLUDE_FROM_ALL DISABLE_LLVM_LINK_LLVM_DYLIB
+ ARMTargetDefEmitter.cpp
+ Attributes.cpp
CodeGenIntrinsics.cpp
+ DirectiveEmitter.cpp
+ IntrinsicEmitter.cpp
+ RISCVTargetDefEmitter.cpp
SDNodeProperties.cpp
+ TableGen.cpp
+ VTEmitter.cpp
)
# Users may include its headers as "Basic/*.h"
diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/DirectiveEmitter.cpp
rename to llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
similarity index 99%
rename from llvm/utils/TableGen/IntrinsicEmitter.cpp
rename to llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
index 093602c3da8045..fc2b8908a35b84 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
@@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
-#include "Basic/CodeGenIntrinsics.h"
-#include "Basic/SequenceToOffsetTable.h"
+#include "CodeGenIntrinsics.h"
+#include "SequenceToOffsetTable.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp b/llvm/utils/TableGen/Basic/RISCVTargetDefEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
rename to llvm/utils/TableGen/Basic/RISCVTargetDefEmitter.cpp
diff --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/Basic/TableGen.cpp
similarity index 94%
rename from llvm/utils/TableGen/TableGen.cpp
rename to llvm/utils/TableGen/Basic/TableGen.cpp
index bea2a2e735dbe2..80ac93f2b54fb6 100644
--- a/llvm/utils/TableGen/TableGen.cpp
+++ b/llvm/utils/TableGen/Basic/TableGen.cpp
@@ -6,10 +6,12 @@
//
//===----------------------------------------------------------------------===//
//
-// This file contains the main function for LLVM's TableGen.
+// This file contains the global defintions (mostly command line parameters)
+// shared between llvm-tblgen and llvm-min-tblgen.
//
//===----------------------------------------------------------------------===//
+#include "TableGen.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
@@ -74,7 +76,7 @@ static TableGen::Emitter::Opt X[] = {
{"print-sets", printSets, "Print expanded sets for testing DAG exprs"},
};
-int main(int argc, char **argv) {
+int tblgen_main(int argc, char **argv) {
InitLLVM X(argc, argv);
cl::ParseCommandLineOptions(argc, argv);
diff --git a/llvm/utils/TableGen/Basic/TableGen.h b/llvm/utils/TableGen/Basic/TableGen.h
new file mode 100644
index 00000000000000..630aea62fcf902
--- /dev/null
+++ b/llvm/utils/TableGen/Basic/TableGen.h
@@ -0,0 +1,13 @@
+//===- TableGen.h ---------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Shared entry point for llvm-tblgen and llvm-min-tblgen.
+//
+//===----------------------------------------------------------------------===//
+
+int tblgen_main(int argc, char **argv);
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/Basic/VTEmitter.cpp
similarity index 100%
rename from llvm/utils/TableGen/VTEmitter.cpp
rename to llvm/utils/TableGen/Basic/VTEmitter.cpp
diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt
index ba1e4aa01b48d6..e4b686803c9769 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -5,20 +5,17 @@ add_subdirectory(Basic)
# code needed by the backends.
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.
+# Sources included in both, llvm-min-tblgen and llvm-tblgen, must be included
+# into LLVMTableGenBasic to avoid redundant compilation and problems with build
+# caches.
+# At least one source file must be included directly to avoid CMake problems.
+# E.g. CMake derives which linker to use from the types of sources added.
add_tablegen(llvm-min-tblgen LLVM_HEADERS
- TableGen.cpp
- ARMTargetDefEmitter.cpp
- Attributes.cpp
- DirectiveEmitter.cpp
- IntrinsicEmitter.cpp
- RISCVTargetDefEmitter.cpp
- VTEmitter.cpp
+ llvm-min-tblgen.cpp
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
PARTIAL_SOURCES_INTENDED
@@ -32,10 +29,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 +43,6 @@ add_tablegen(llvm-tblgen LLVM
DecoderEmitter.cpp
DFAEmitter.cpp
DFAPacketizerEmitter.cpp
- DirectiveEmitter.cpp
DisassemblerEmitter.cpp
DXILEmitter.cpp
ExegesisEmitter.cpp
@@ -57,18 +51,15 @@ add_tablegen(llvm-tblgen LLVM
GlobalISelEmitter.cpp
InstrDocsEmitter.cpp
InstrInfoEmitter.cpp
- IntrinsicEmitter.cpp
+ llvm-tblgen.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
@@ -79,6 +70,8 @@ add_tablegen(llvm-tblgen LLVM
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
$<TARGET_OBJECTS:obj.LLVMTableGenCommon>
+ PARTIAL_SOURCES_INTENDED
+
DEPENDS
intrinsics_gen # via llvm-min-tablegen
)
diff --git a/llvm/utils/TableGen/llvm-min-tblgen.cpp b/llvm/utils/TableGen/llvm-min-tblgen.cpp
new file mode 100644
index 00000000000000..79fce5c555f6e1
--- /dev/null
+++ b/llvm/utils/TableGen/llvm-min-tblgen.cpp
@@ -0,0 +1,18 @@
+//===- llvm-min-tblgen.cpp ------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the main function for LLVM's TableGen.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Basic/TableGen.h"
+
+/// Command line parameters are shared between llvm-tblgen and llvm-min-tblgen.
+/// The indirection to tblgen_main exists to ensure that the static variables
+/// for the llvm::cl:: mechanism are linked into both executables.
+int main(int argc, char **argv) { return tblgen_main(argc, argv); }
diff --git a/llvm/utils/TableGen/llvm-tblgen.cpp b/llvm/utils/TableGen/llvm-tblgen.cpp
new file mode 100644
index 00000000000000..a38382472a992b
--- /dev/null
+++ b/llvm/utils/TableGen/llvm-tblgen.cpp
@@ -0,0 +1,18 @@
+//===- llvm-tblgen.cpp ----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains the main function for LLVM's TableGen.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Basic/TableGen.h"
+
+/// Command line parameters are shared between llvm-tblgen and llvm-min-tblgen.
+/// The indirection to tblgen_main exists to ensure that the static variables
+/// for the llvm::cl:: mechanism are linked into both executables.
+int main(int argc, char **argv) { return tblgen_main(argc, argv); }
More information about the llvm-commits
mailing list