Skip to content

Commit 4942e78

Browse files
authored
[llvm-exegesis] Only link/initialize supported targets (NFC) (#95421)
llvm-exegesis currently links and initializes all targets, even though most of them are not supported by llvm-exegesis. This is particularly unfortunate because llvm-exegesis does not support the LLVM dylib, so llvm-exegesis essentially ends up doing a complete relink of all of LLVM, which is not fun if you use LTO. Instead, only link and initialize the targets that are part of LLVM_EXEGESIS_TARGETS.
1 parent c947709 commit 4942e78

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

llvm/tools/llvm-exegesis/CMakeLists.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
# Has side effect of defining LLVM_EXEGESIS_TARGETS
2+
add_subdirectory(lib)
3+
14
set(LLVM_LINK_COMPONENTS
2-
AllTargetsAsmParsers
3-
AllTargetsCodeGens
4-
AllTargetsDescs
5-
AllTargetsDisassemblers
6-
AllTargetsInfos
75
CodeGenTypes
86
MC
97
MCParser
108
Support
119
TargetParser
1210
)
1311

12+
foreach(t ${LLVM_EXEGESIS_TARGETS})
13+
string(STRIP ${t} t)
14+
list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}AsmParser")
15+
list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}CodeGen")
16+
list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}Desc")
17+
list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}Disassembler")
18+
list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}Info")
19+
endforeach()
20+
1421
add_llvm_tool(llvm-exegesis
1522
DISABLE_LLVM_LINK_LLVM_DYLIB
1623
llvm-exegesis.cpp
@@ -19,9 +26,6 @@ add_llvm_tool(llvm-exegesis
1926
intrinsics_gen
2027
)
2128

22-
# Has side effect of defining LLVM_EXEGESIS_TARGETS
23-
add_subdirectory(lib)
24-
2529
# Link all enabled exegesis targets
2630
set(libs)
2731
foreach(t ${LLVM_EXEGESIS_TARGETS})

llvm/tools/llvm-exegesis/llvm-exegesis.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,11 @@ void benchmarkMain() {
470470
#endif
471471
}
472472

473-
InitializeAllAsmPrinters();
474-
InitializeAllAsmParsers();
475473
InitializeAllExegesisTargets();
474+
#define LLVM_EXEGESIS(TargetName) \
475+
LLVMInitialize##TargetName##AsmPrinter(); \
476+
LLVMInitialize##TargetName##AsmParser();
477+
#include "llvm/Config/TargetExegesis.def"
476478

477479
const LLVMState State =
478480
ExitOnErr(LLVMState::Create(TripleName, MCPU, "", UseDummyPerfCounters));
@@ -621,9 +623,11 @@ static void analysisMain() {
621623
"and --analysis-inconsistencies-output-file must be specified");
622624
}
623625

624-
InitializeAllAsmPrinters();
625-
InitializeAllDisassemblers();
626626
InitializeAllExegesisTargets();
627+
#define LLVM_EXEGESIS(TargetName) \
628+
LLVMInitialize##TargetName##AsmPrinter(); \
629+
LLVMInitialize##TargetName##Disassembler();
630+
#include "llvm/Config/TargetExegesis.def"
627631

628632
auto MemoryBuffer = ExitOnFileError(
629633
BenchmarkFile,
@@ -690,9 +694,11 @@ int main(int Argc, char **Argv) {
690694
InitLLVM X(Argc, Argv);
691695

692696
// Initialize targets so we can print them when flag --version is specified.
693-
InitializeAllTargetInfos();
694-
InitializeAllTargets();
695-
InitializeAllTargetMCs();
697+
#define LLVM_EXEGESIS(TargetName) \
698+
LLVMInitialize##TargetName##Target(); \
699+
LLVMInitialize##TargetName##TargetInfo(); \
700+
LLVMInitialize##TargetName##TargetMC();
701+
#include "llvm/Config/TargetExegesis.def"
696702

697703
// Register the Target and CPU printer for --version.
698704
cl::AddExtraVersionPrinter(sys::printDefaultTargetAndDetectedCPU);

0 commit comments

Comments
 (0)