Skip to content

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

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 2 commits into from
Jun 14, 2024

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jun 13, 2024

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2024

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

Author: Nikita Popov (nikic)

Changes

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 --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);

Copy link

github-actions bot commented Jun 13, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

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

Seems reasonable enough to me.

@nikic nikic merged commit 4942e78 into llvm:main Jun 14, 2024
7 checks passed
@nikic nikic deleted the llvm-exegesis-targets branch June 14, 2024 07:39
@luporl
Copy link
Contributor

luporl commented Jun 14, 2024

Some buildbots, such as https://lab.llvm.org/buildbot/#/builders/130/builds/35, started failing after this change.
Can you please take a look? Let me know if you need any help to reproduce the failure.

Comment on lines +14 to +18
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")
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a typo here: LLVM_LINK_COMPONTENTS.
Maybe that's what is causing the link failure in some bots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I've pushed 8ab3f8a, let's see if that fixes the buildbots.

I think the reason this worked in my testing is that the exegesis targets also depend on the umbrella codegen targets, so it works out okay if BUILD_SHARED_LIBS is not enabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

That fixed the buildbots, thanks!

nikic added a commit that referenced this pull request Jun 14, 2024
EthanLuisMcDonough pushed a commit to EthanLuisMcDonough/llvm-project that referenced this pull request Aug 13, 2024
)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants