Skip to content

[llvm-(min-)tblgen] Avoid redundant source compilation #114494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 2, 2025
7 changes: 7 additions & 0 deletions llvm/utils/TableGen/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest TableGen.cpp may be individual. IIRC, some cmake generators don't like add_executable w/o any source files.

Copy link
Member Author

@Meinersbur Meinersbur Dec 16, 2024

Choose a reason for hiding this comment

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

CMake has a problem to identify which linker to use (C or C++) when there is no .c/.cpp file in the list. A strategy used elsewhere also in LLVM adds an empty dummy.cpp into the list.

Keeping TableGen.cpp (or using the same dummy.cpp) in both executables would defeat the entire purpose of this patch: The same timestamp issue still occurs with even just a single file which causes all .td files to be processed again in a no-change build (see summary).

I instead applied 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.

VTEmitter.cpp
)

# Users may include its headers as "Basic/*.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions llvm/utils/TableGen/Basic/TableGen.h
Original file line number Diff line number Diff line change
@@ -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);
25 changes: 9 additions & 16 deletions llvm/utils/TableGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Meant, one TableGen.cpp for multiple instances. I don't think we need to create copied files.

PARTIAL_SOURCES_INTENDED will accept duplicates.

Copy link
Member Author

@Meinersbur Meinersbur Dec 16, 2024

Choose a reason for hiding this comment

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

Please read #114494 (comment) for why not. The duplicate is the exactly the problem this PR intends to solve, even if PARTIAL_SOURCES_INTENDED accepts it.

$<TARGET_OBJECTS:obj.LLVMTableGenBasic>

PARTIAL_SOURCES_INTENDED
Expand All @@ -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
Expand All @@ -48,7 +43,6 @@ add_tablegen(llvm-tblgen LLVM
DecoderEmitter.cpp
DFAEmitter.cpp
DFAPacketizerEmitter.cpp
DirectiveEmitter.cpp
DisassemblerEmitter.cpp
DXILEmitter.cpp
ExegesisEmitter.cpp
Expand All @@ -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
Expand All @@ -79,6 +70,8 @@ add_tablegen(llvm-tblgen LLVM
$<TARGET_OBJECTS:obj.LLVMTableGenBasic>
$<TARGET_OBJECTS:obj.LLVMTableGenCommon>

PARTIAL_SOURCES_INTENDED
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be pruned.


DEPENDS
intrinsics_gen # via llvm-min-tablegen
)
18 changes: 18 additions & 0 deletions llvm/utils/TableGen/llvm-min-tblgen.cpp
Original file line number Diff line number Diff line change
@@ -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); }
18 changes: 18 additions & 0 deletions llvm/utils/TableGen/llvm-tblgen.cpp
Original file line number Diff line number Diff line change
@@ -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); }
Loading