Skip to content

Commit 594bc52

Browse files
authored
[lld] Change --lto-emit-llvm to use the pre-codegen module (#97480)
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).
1 parent b5b0a22 commit 594bc52

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lld/ELF/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static lto::Config createConfig() {
147147
c.PGOWarnMismatch = config->ltoPGOWarnMismatch;
148148

149149
if (config->emitLLVM) {
150-
c.PostInternalizeModuleHook = [](size_t task, const Module &m) {
150+
c.PreCodeGenModuleHook = [](size_t task, const Module &m) {
151151
if (std::unique_ptr<raw_fd_ostream> os =
152152
openLTOOutputFile(config->outputFile))
153153
WriteBitcodeToFile(m, *os, false);

lld/test/ELF/lto/emit-llvm.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
; RUN: ld.lld --plugin-opt=emit-llvm -mllvm -bitcode-flush-threshold=0 -o /dev/null %t.o
1010
; RUN: ld.lld --lto-emit-llvm -mllvm -bitcode-flush-threshold=0 -o /dev/null %t.o
1111

12-
; CHECK: define internal void @main()
12+
; CHECK: define hidden void @main()
1313

1414
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1515
target triple = "x86_64-unknown-linux-gnu"
1616

17-
define void @main() {
17+
@llvm.compiler.used = appending global [1 x ptr] [ptr @main], section "llvm.metadata"
18+
19+
define hidden void @main() {
1820
ret void
1921
}

0 commit comments

Comments
 (0)