[llvm] r281725 - [LTO] Fix handling of mixed (regular and thin) mode LTO

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 16 06:54:19 PDT 2016


Author: tejohnson
Date: Fri Sep 16 08:54:19 2016
New Revision: 281725

URL: http://llvm.org/viewvc/llvm-project?rev=281725&view=rev
Log:
[LTO] Fix handling of mixed (regular and thin) mode LTO

Summary:
In runThinLTO we start the task numbering for ThinLTO backend
tasks depending on whether there was also a regular LTO object
(CombinedModule). However, the CombinedModule is moved at
the end of runRegularLTO, so we need to save this information and
pass it into runThinLTO. Otherwise the AddOutput callback to the client
will use the same task number for both the regular LTO object
and the first ThinLTO object, which in gold-plugin caused only
one to be end up in the output filename array and therefore passed
back to gold for the final native link.

Reviewers: pcc, mehdi_amini

Subscribers: mehdi_amini, kromanova

Differential Revision: https://reviews.llvm.org/D24643

Added:
    llvm/trunk/test/LTO/Resolution/X86/Inputs/mixed_lto.ll
    llvm/trunk/test/LTO/Resolution/X86/mixed_lto.ll
    llvm/trunk/test/tools/gold/X86/Inputs/mixed_lto.ll
    llvm/trunk/test/tools/gold/X86/mixed_lto.ll
Modified:
    llvm/trunk/include/llvm/LTO/LTO.h
    llvm/trunk/lib/LTO/LTO.cpp

Modified: llvm/trunk/include/llvm/LTO/LTO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTO.h?rev=281725&r1=281724&r2=281725&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTO.h (original)
+++ llvm/trunk/include/llvm/LTO/LTO.h Fri Sep 16 08:54:19 2016
@@ -387,7 +387,7 @@ private:
                    ArrayRef<SymbolResolution> Res);
 
   Error runRegularLTO(AddOutputFn AddOutput);
-  Error runThinLTO(AddOutputFn AddOutput);
+  Error runThinLTO(AddOutputFn AddOutput, bool HasRegularLTO);
 
   mutable bool CalledGetMaxTasks = false;
 };

Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=281725&r1=281724&r2=281725&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Fri Sep 16 08:54:19 2016
@@ -410,11 +410,15 @@ unsigned LTO::getMaxTasks() const {
 }
 
 Error LTO::run(AddOutputFn AddOutput) {
+  // Save the status of having a regularLTO combined module, as
+  // this is needed for generating the ThinLTO Task ID, and
+  // the CombinedModule will be moved at the end of runRegularLTO.
+  bool HasRegularLTO = RegularLTO.CombinedModule != nullptr;
   // Invoke regular LTO if there was a regular LTO module to start with.
-  if (RegularLTO.CombinedModule)
+  if (HasRegularLTO)
     if (auto E = runRegularLTO(AddOutput))
       return E;
-  return runThinLTO(AddOutput);
+  return runThinLTO(AddOutput, HasRegularLTO);
 }
 
 Error LTO::runRegularLTO(AddOutputFn AddOutput) {
@@ -696,7 +700,7 @@ ThinBackend lto::createWriteIndexesThinB
   };
 }
 
-Error LTO::runThinLTO(AddOutputFn AddOutput) {
+Error LTO::runThinLTO(AddOutputFn AddOutput, bool HasRegularLTO) {
   if (ThinLTO.ModuleMap.empty())
     return Error();
 
@@ -753,9 +757,8 @@ Error LTO::runThinLTO(AddOutputFn AddOut
   // ParallelCodeGenParallelismLevel if an LTO module is present, as tasks 0
   // through ParallelCodeGenParallelismLevel-1 are reserved for parallel code
   // generation partitions.
-  unsigned Task = RegularLTO.CombinedModule
-                      ? RegularLTO.ParallelCodeGenParallelismLevel
-                      : 0;
+  unsigned Task =
+      HasRegularLTO ? RegularLTO.ParallelCodeGenParallelismLevel : 0;
   unsigned Partition = 1;
 
   for (auto &Mod : ThinLTO.ModuleMap) {

Added: llvm/trunk/test/LTO/Resolution/X86/Inputs/mixed_lto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/Inputs/mixed_lto.ll?rev=281725&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/Inputs/mixed_lto.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/Inputs/mixed_lto.ll Fri Sep 16 08:54:19 2016
@@ -0,0 +1,6 @@
+target triple = "x86_64-unknown-linux-gnu"
+declare i32 @g()
+define i32 @main() {
+  call i32 @g()
+  ret i32 0
+}

Added: llvm/trunk/test/LTO/Resolution/X86/mixed_lto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/mixed_lto.ll?rev=281725&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/mixed_lto.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/mixed_lto.ll Fri Sep 16 08:54:19 2016
@@ -0,0 +1,19 @@
+; Test mixed-mode LTO (mix of regular and thin LTO objects)
+; RUN: opt %s -o %t1.o
+; RUN: opt -module-summary %p/Inputs/mixed_lto.ll -o %t2.o
+
+; RUN: llvm-lto2 -o %t3.o %t2.o %t1.o -r %t2.o,main,px -r %t2.o,g, -r %t1.o,g,px
+
+; Task 0 is the regular LTO file (this file)
+; RUN: nm %t3.o.0 | FileCheck %s --check-prefix=NM0
+; NM0: T g
+
+; Task 1 is the (first) ThinLTO file (Inputs/mixed_lto.ll)
+; RUN: nm %t3.o.1 | FileCheck %s --check-prefix=NM1
+; NM1-DAG: T main
+; NM1-DAG: U g
+
+target triple = "x86_64-unknown-linux-gnu"
+define i32 @g() {
+  ret i32 0
+}

Added: llvm/trunk/test/tools/gold/X86/Inputs/mixed_lto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/Inputs/mixed_lto.ll?rev=281725&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/X86/Inputs/mixed_lto.ll (added)
+++ llvm/trunk/test/tools/gold/X86/Inputs/mixed_lto.ll Fri Sep 16 08:54:19 2016
@@ -0,0 +1,6 @@
+target triple = "x86_64-unknown-linux-gnu"
+declare i32 @g()
+define i32 @main() {
+  call i32 @g()
+  ret i32 0
+}

Added: llvm/trunk/test/tools/gold/X86/mixed_lto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/mixed_lto.ll?rev=281725&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/X86/mixed_lto.ll (added)
+++ llvm/trunk/test/tools/gold/X86/mixed_lto.ll Fri Sep 16 08:54:19 2016
@@ -0,0 +1,18 @@
+; Test mixed-mode LTO (mix of regular and thin LTO objects)
+; RUN: opt %s -o %t.o
+; RUN: opt -module-summary %p/Inputs/mixed_lto.ll -o %t2.o
+
+; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
+; RUN:     -shared \
+; RUN:     --plugin-opt=thinlto \
+; RUN:     --plugin-opt=-import-instr-limit=0 \
+; RUN:     -o %t3.o %t2.o %t.o
+; RUN: nm %t3.o | FileCheck %s
+
+; CHECK-DAG: T main
+; CHECK-DAG: T g
+
+target triple = "x86_64-unknown-linux-gnu"
+define i32 @g() {
+  ret i32 0
+}




More information about the llvm-commits mailing list