-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[lld] Change --lto-emit-llvm
to use the pre-codegen module
#97480
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
Conversation
Summary: Currently the `--lto-emit-llvm` option writes out the post-internalization bitcode. This is the bitcode before any optimizations or other pipelines have been run on it. This patch changes that to use the pre-codegen module, which is the state of the LLVM-IR after the optimizations have been run. I believe that this makes sense as the `--lto-emit-llvm` option seems to imply that we should emit the final output of the LLVM pass as if it were the desired output. This should include optimizations at the requested optimization level. My main motivation for this change is to be able to use this to link several LLVM-IR files into a single one that I can then pass back to `ld.lld` later (for JIT purposes).
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-elf Author: Joseph Huber (jhuber6) ChangesSummary: I believe that this makes sense as the Full diff: https://github.com/llvm/llvm-project/pull/97480.diff 2 Files Affected:
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 3d92007469263..935d0a9eab9ee 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -147,7 +147,7 @@ static lto::Config createConfig() {
c.PGOWarnMismatch = config->ltoPGOWarnMismatch;
if (config->emitLLVM) {
- c.PostInternalizeModuleHook = [](size_t task, const Module &m) {
+ c.PreCodeGenModuleHook = [](size_t task, const Module &m) {
if (std::unique_ptr<raw_fd_ostream> os =
openLTOOutputFile(config->outputFile))
WriteBitcodeToFile(m, *os, false);
diff --git a/lld/test/ELF/lto/emit-llvm.ll b/lld/test/ELF/lto/emit-llvm.ll
index 01f5a056e0c0d..37488016a4bc2 100644
--- a/lld/test/ELF/lto/emit-llvm.ll
+++ b/lld/test/ELF/lto/emit-llvm.ll
@@ -9,11 +9,13 @@
; RUN: ld.lld --plugin-opt=emit-llvm -mllvm -bitcode-flush-threshold=0 -o /dev/null %t.o
; RUN: ld.lld --lto-emit-llvm -mllvm -bitcode-flush-threshold=0 -o /dev/null %t.o
-; CHECK: define internal void @main()
+; CHECK: define hidden void @main()
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
-define void @main() {
+@llvm.compiler.used = appending global [1 x ptr] [ptr @main], section "llvm.metadata"
+
+define hidden void @main() {
ret void
}
|
|
|
||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define void @main() { | ||
@llvm.compiler.used = appending global [1 x ptr] [ptr @main], section "llvm.metadata" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test doesn't change for PostInternal / PreCodegen. Use a different one? Perhaps two modules are needed to show a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It optimizes it out completely, so I just made it used so it sticks around. Could make it slightly more complicated if you want. But, I think the test is mostly just to show "Yes it outputs something"
) Summary: Currently the `--lto-emit-llvm` option writes out the post-internalization bitcode. This is the bitcode before any optimizations or other pipelines have been run on it. This patch changes that to use the pre-codegen module, which is the state of the LLVM-IR after the optimizations have been run. I believe that this makes sense as the `--lto-emit-llvm` option seems to imply that we should emit the final output of the LLVM pass as if it were the desired output. This should include optimizations at the requested optimization level. My main motivation for this change is to be able to use this to link several LLVM-IR files into a single one that I can then pass back to `ld.lld` later (for JIT purposes).
) Summary: Currently the `--lto-emit-llvm` option writes out the post-internalization bitcode. This is the bitcode before any optimizations or other pipelines have been run on it. This patch changes that to use the pre-codegen module, which is the state of the LLVM-IR after the optimizations have been run. I believe that this makes sense as the `--lto-emit-llvm` option seems to imply that we should emit the final output of the LLVM pass as if it were the desired output. This should include optimizations at the requested optimization level. My main motivation for this change is to be able to use this to link several LLVM-IR files into a single one that I can then pass back to `ld.lld` later (for JIT purposes).
Summary: This matches ELF (#97480). clang cc1 -emit-llvm and -emit-llvm-bc for ThinLTO backend compilation also uses `PreCodeGenModuleHook`. While here, replace deprecated %T with %t. Pull Request: #98589 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250940
Summary:
Currently the
--lto-emit-llvm
option writes out thepost-internalization bitcode. This is the bitcode before any
optimizations or other pipelines have been run on it. This patch changes
that to use the pre-codegen module, which is the state of the LLVM-IR
after the optimizations have been run.
I believe that this makes sense as the
--lto-emit-llvm
option seems toimply that we should emit the final output of the LLVM pass as if it
were the desired output. This should include optimizations at the
requested optimization level. My main motivation for this change is to
be able to use this to link several LLVM-IR files into a single one that
I can then pass back to
ld.lld
later (for JIT purposes).