Skip to content

Commit 0b1914e

Browse files
committed
[ThinLTO][gold] Fix filenaming scheme for tasks.
The gold LTO plugin uses a set of hooks to implements emit-llvm and capture intermediate file generated during LTO. The hooks are called by each lto backend thread with a taskID as argument to differentiate between threads and tasks. Currently, all threads are overwriting the same file which results into only the intermediate output of the last backend thread to be preserved. This diff encodes the taskID into the filename. Reviewed By: tejohnson, wenlei Differential Revision: https://reviews.llvm.org/D96173
1 parent 66900b3 commit 0b1914e

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
2+
target triple = "x86_64-unknown-linux-gnu"
3+
4+
define dso_local i32 @_Z3barv() #0 {
5+
ret i32 0
6+
}
7+
8+
^0 = module: (path: "bar.o", hash: (3853957065, 2310817429, 3119833948, 1366622700, 2470927843))
9+
^1 = gv: (name: "_Z3barv", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0), insts: 1, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 1, alwaysInline: 0)))) ; guid = 17377440600225628772
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
2+
target triple = "x86_64-unknown-linux-gnu"
3+
4+
define dso_local i32 @_Z3foov() #0 {
5+
ret i32 0
6+
}
7+
8+
^0 = module: (path: "foo.o", hash: (3786635673, 3275786284, 1544384821, 2103351884, 2354656665))
9+
^1 = gv: (name: "_Z3foov", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0), insts: 1, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, returnDoesNotAlias: 0, noInline: 1, alwaysInline: 0)))) ; guid = 9191153033785521275
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: llvm-as %p/Inputs/emit-llvm.foo.ll -o %t.foo.bc
2+
; RUN: llvm-as %p/Inputs/emit-llvm.bar.ll -o %t.bar.bc
3+
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext --shared -plugin-opt thinlto -plugin-opt emit-llvm -m elf_x86_64 %t.foo.bc %t.bar.bc -o %t.bc
4+
; RUN: llvm-dis %t.bc1 -o - | FileCheck --check-prefix=CHECK-BC1 %s
5+
; RUN: llvm-dis %t.bc2 -o - | FileCheck --check-prefix=CHECK-BC2 %s
6+
7+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8+
target triple = "x86_64-unknown-linux-gnu"
9+
10+
; CHECK-BC1: define dso_local i32 @_Z3foov()
11+
define dso_local i32 @_Z3foov() {
12+
ret i32 0
13+
}
14+
; CHECK-BC2: define dso_local i32 @_Z3barv()
15+
define dso_local i32 @_Z3barv() {
16+
ret i32 0
17+
}

llvm/tools/gold/gold-plugin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,10 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
915915
case options::OT_BC_ONLY:
916916
Conf.PostInternalizeModuleHook = [](size_t Task, const Module &M) {
917917
std::error_code EC;
918-
raw_fd_ostream OS(output_name, EC, sys::fs::OpenFlags::OF_None);
918+
SmallString<128> TaskFilename;
919+
getOutputFileName(output_name, /* TempOutFile */ false, TaskFilename,
920+
Task);
921+
raw_fd_ostream OS(TaskFilename, EC, sys::fs::OpenFlags::OF_None);
919922
if (EC)
920923
message(LDPL_FATAL, "Failed to write the output file.");
921924
WriteBitcodeToFile(M, OS, /* ShouldPreserveUseListOrder */ false);

0 commit comments

Comments
 (0)