[llvm] [llvm-exegesis] Only link/initialize supported targets (NFC) (PR #95421)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 08:17:19 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/95421.diff


2 Files Affected:

- (modified) llvm/tools/llvm-exegesis/CMakeLists.txt (+12-8) 
- (modified) llvm/tools/llvm-exegesis/llvm-exegesis.cpp (+13-7) 


``````````diff
diff --git a/llvm/tools/llvm-exegesis/CMakeLists.txt b/llvm/tools/llvm-exegesis/CMakeLists.txt
index ec418a7d51ecc..c3c4058cf6525 100644
--- a/llvm/tools/llvm-exegesis/CMakeLists.txt
+++ b/llvm/tools/llvm-exegesis/CMakeLists.txt
@@ -1,9 +1,7 @@
+# Has side effect of defining LLVM_EXEGESIS_TARGETS
+add_subdirectory(lib)
+
 set(LLVM_LINK_COMPONENTS
-  AllTargetsAsmParsers
-  AllTargetsCodeGens
-  AllTargetsDescs
-  AllTargetsDisassemblers
-  AllTargetsInfos
   CodeGenTypes
   MC
   MCParser
@@ -11,6 +9,15 @@ set(LLVM_LINK_COMPONENTS
   TargetParser
   )
 
+foreach(t ${LLVM_EXEGESIS_TARGETS})
+  string(STRIP ${t} t)
+  list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}AsmParser")
+  list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}CodeGen")
+  list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}Desc")
+  list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}Disassembler")
+  list(APPEND LLVM_LINK_COMPONTENTS "LLVM${t}Info")
+endforeach()
+
 add_llvm_tool(llvm-exegesis
   DISABLE_LLVM_LINK_LLVM_DYLIB
   llvm-exegesis.cpp
@@ -19,9 +26,6 @@ add_llvm_tool(llvm-exegesis
   intrinsics_gen
   )
 
-# Has side effect of defining LLVM_EXEGESIS_TARGETS
-add_subdirectory(lib)
-
 # Link all enabled exegesis targets
 set(libs)
 foreach(t ${LLVM_EXEGESIS_TARGETS})
diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index 06e1c7f3c1bbe..584b0608b635f 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -470,9 +470,11 @@ void benchmarkMain() {
 #endif
   }
 
-  InitializeAllAsmPrinters();
-  InitializeAllAsmParsers();
   InitializeAllExegesisTargets();
+#define LLVM_EXEGESIS(TargetName) \
+  LLVMInitialize##TargetName##AsmPrinter(); \
+  LLVMInitialize##TargetName##AsmParser();
+#include "llvm/Config/TargetExegesis.def"
 
   const LLVMState State =
       ExitOnErr(LLVMState::Create(TripleName, MCPU, "", UseDummyPerfCounters));
@@ -621,9 +623,11 @@ static void analysisMain() {
         "and --analysis-inconsistencies-output-file must be specified");
   }
 
-  InitializeAllAsmPrinters();
-  InitializeAllDisassemblers();
   InitializeAllExegesisTargets();
+#define LLVM_EXEGESIS(TargetName) \
+  LLVMInitialize##TargetName##AsmPrinter(); \
+  LLVMInitialize##TargetName##Disassembler();
+#include "llvm/Config/TargetExegesis.def"
 
   auto MemoryBuffer = ExitOnFileError(
       BenchmarkFile,
@@ -690,9 +694,11 @@ int main(int Argc, char **Argv) {
   InitLLVM X(Argc, Argv);
 
   // Initialize targets so we can print them when flag --version is specified.
-  InitializeAllTargetInfos();
-  InitializeAllTargets();
-  InitializeAllTargetMCs();
+#define LLVM_EXEGESIS(TargetName) \
+  LLVMInitialize##TargetName##Target(); \
+  LLVMInitialize##TargetName##TargetInfo(); \
+  LLVMInitialize##TargetName##TargetMC();
+#include "llvm/Config/TargetExegesis.def"
 
   // Register the Target and CPU printer for --version.
   cl::AddExtraVersionPrinter(sys::printDefaultTargetAndDetectedCPU);

``````````

</details>


https://github.com/llvm/llvm-project/pull/95421


More information about the llvm-commits mailing list