[PATCH] D96173: [ThinLTO][gold] Fix filenaming scheme for tasks.

Hongtao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 5 13:18:38 PST 2021


hoy created this revision.
Herald added subscribers: wenlei, steven_wu, hiraditya, inglorion.
hoy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96173

Files:
  llvm/test/tools/gold/X86/Inputs/emit-llvm.bar.ll
  llvm/test/tools/gold/X86/Inputs/emit-llvm.foo.ll
  llvm/test/tools/gold/X86/thinlto-emit-llvm.ll
  llvm/tools/gold/gold-plugin.cpp


Index: llvm/tools/gold/gold-plugin.cpp
===================================================================
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -915,7 +915,9 @@
   case options::OT_BC_ONLY:
     Conf.PostInternalizeModuleHook = [](size_t Task, const Module &M) {
       std::error_code EC;
-      raw_fd_ostream OS(output_name, EC, sys::fs::OpenFlags::OF_None);
+      SmallString<128> TaskFilename;
+      getOutputFileName(output_name, false, TaskFilename, Task);
+      raw_fd_ostream OS(TaskFilename, EC, sys::fs::OpenFlags::OF_None);
       if (EC)
         message(LDPL_FATAL, "Failed to write the output file.");
       WriteBitcodeToFile(M, OS, /* ShouldPreserveUseListOrder */ false);
Index: llvm/test/tools/gold/X86/thinlto-emit-llvm.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/gold/X86/thinlto-emit-llvm.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-as %p/Inputs/emit-llvm.foo.ll -o %t.foo.bc
+; RUN: llvm-as %p/Inputs/emit-llvm.bar.ll -o %t.bar.bc
+; 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
+; RUN: llvm-dis %t.bc1 -o - | FileCheck --check-prefix=CHECK-BC1 %s
+; RUN: llvm-dis %t.bc2 -o - | FileCheck --check-prefix=CHECK-BC2 %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-BC1: define dso_local i32 @_Z3foov()
+define dso_local i32 @_Z3foov() {
+    ret i32 0
+}
+; CHECK-BC2: define dso_local i32 @_Z3barv()
+define dso_local i32 @_Z3barv() {
+    ret i32 0
+}
Index: llvm/test/tools/gold/X86/Inputs/emit-llvm.foo.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/gold/X86/Inputs/emit-llvm.foo.ll
@@ -0,0 +1,9 @@
+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 dso_local i32 @_Z3foov() #0 {
+  ret i32 0
+}
+
+^0 = module: (path: "foo.o", hash: (3786635673, 3275786284, 1544384821, 2103351884, 2354656665))
+^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
Index: llvm/test/tools/gold/X86/Inputs/emit-llvm.bar.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/gold/X86/Inputs/emit-llvm.bar.ll
@@ -0,0 +1,9 @@
+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 dso_local i32 @_Z3barv() #0 {
+  ret i32 0
+}
+
+^0 = module: (path: "bar.o", hash: (3853957065, 2310817429, 3119833948, 1366622700, 2470927843))
+^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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96173.321861.patch
Type: text/x-patch
Size: 3242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210205/ba2ec071/attachment.bin>


More information about the llvm-commits mailing list