[llvm] 0b1914e - [ThinLTO][gold] Fix filenaming scheme for tasks.

Hongtao Yu via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 09:40:19 PST 2021


Author: Hongtao Yu
Date: 2021-02-12T09:40:08-08:00
New Revision: 0b1914e83a03be926569892c17ca743c5ea46d1f

URL: https://github.com/llvm/llvm-project/commit/0b1914e83a03be926569892c17ca743c5ea46d1f
DIFF: https://github.com/llvm/llvm-project/commit/0b1914e83a03be926569892c17ca743c5ea46d1f.diff

LOG: [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

Added: 
    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

Modified: 
    llvm/tools/gold/gold-plugin.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/gold/X86/Inputs/emit-llvm.bar.ll b/llvm/test/tools/gold/X86/Inputs/emit-llvm.bar.ll
new file mode 100644
index 000000000000..93a37fe595ee
--- /dev/null
+++ b/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

diff  --git a/llvm/test/tools/gold/X86/Inputs/emit-llvm.foo.ll b/llvm/test/tools/gold/X86/Inputs/emit-llvm.foo.ll
new file mode 100644
index 000000000000..85c59b4f9114
--- /dev/null
+++ b/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

diff  --git a/llvm/test/tools/gold/X86/thinlto-emit-llvm.ll b/llvm/test/tools/gold/X86/thinlto-emit-llvm.ll
new file mode 100644
index 000000000000..09318ddc98ac
--- /dev/null
+++ b/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
+}

diff  --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index c0e0d5bbcf56..38f959699e42 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -915,7 +915,10 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite,
   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, /* TempOutFile */ 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);


        


More information about the llvm-commits mailing list