diff --git a/llvm/test/ThinLTO/X86/distributed_import.ll b/llvm/test/ThinLTO/X86/distributed_import.ll --- a/llvm/test/ThinLTO/X86/distributed_import.ll +++ b/llvm/test/ThinLTO/X86/distributed_import.ll @@ -1,7 +1,6 @@ ; Test distributed build thin link output from llvm-lto2 -; Generate bitcode files with summary, as well as minimized bitcode without -; the debug metadata for the thin link. +; Generate bitcode files with summary, as well as minimized bitcode containing just the summary ; RUN: opt -thinlto-bc %s -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.bc ; RUN: opt -thinlto-bc %p/Inputs/distributed_import.ll -thin-link-bitcode-file=%t2.thinlink.bc -o %t2.bc ; RUN: llvm-bcanalyzer -dump %t1.thinlink.bc | FileCheck --check-prefix=THINLINKBITCODE %s diff --git a/llvm/test/ThinLTO/X86/emit-inprocess-files.ll b/llvm/test/ThinLTO/X86/emit-inprocess-files.ll new file mode 100644 --- /dev/null +++ b/llvm/test/ThinLTO/X86/emit-inprocess-files.ll @@ -0,0 +1,87 @@ +; Test InProcessThinLTO thin link output from llvm-lto2 +; Partially copied from distributed_import.ll, and added checks for {dis|en}abling imports + +; RUN: rm -f %t1.bc.thinlto.bc %t2.bc.thinlto.bc %t.out.1 %t.out.2 %t1.bc.imports %t2.bc.imports + +; Generate bitcode files with summary, as well as minimized bitcode containing just the summary +; RUN: opt -thinlto-bc %s -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.bc +; RUN: opt -thinlto-bc %p/Inputs/distributed_import.ll -thin-link-bitcode-file=%t2.thinlink.bc -o %t2.bc + +; First perform the thin link on the normal bitcode file using +; -thinlto-distributed-indexes, collecting outputs to be compared with later. +; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps \ +; RUN: -thinlto-distributed-indexes \ +; RUN: -thinlto-emit-imports \ +; RUN: -r=%t1.bc,g, \ +; RUN: -r=%t1.bc,analias, \ +; RUN: -r=%t1.bc,f,px \ +; RUN: -r=%t2.bc,g,px \ +; RUN: -r=%t2.bc,analias,px \ +; RUN: -r=%t2.bc,aliasee,px +; RUN: mv %t1.bc.thinlto.bc %t1.bc.thinlto.bc.orig +; RUN: mv %t2.bc.thinlto.bc %t2.bc.thinlto.bc.orig +; RUN: mv %t1.bc.imports %t1.bc.imports.orig +; RUN: mv %t2.bc.imports %t2.bc.imports.orig + +; Now use -thinlto-emit-indexes instead. +; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps \ +; RUN: -thinlto-emit-indexes \ +; RUN: -r=%t1.bc,g, \ +; RUN: -r=%t1.bc,analias, \ +; RUN: -r=%t1.bc,f,px \ +; RUN: -r=%t2.bc,g,px \ +; RUN: -r=%t2.bc,analias,px \ +; RUN: -r=%t2.bc,aliasee,px \ +; RUN: -o=%t.out + +; Since InProcessThinLTO ran, there should be output +; RUN: ls %t.out.1 +; RUN: ls %t.out.2 + +; Ensure imports weren't generated since -thinlto-emit-imports wasn't specified +; RUN: not ls %t1.bc.imports +; RUN: not ls %t2.bc.imports + +; Compare the generated index files. +; RUN: diff %t1.bc.thinlto.bc %t1.bc.thinlto.bc.orig +; RUN: diff %t2.bc.thinlto.bc %t2.bc.thinlto.bc.orig + +; RUN: rm -f %t1.bc.thinlto.bc %t2.bc.thinlto.bc %t.out.1 %t.out.2 + +; Do the thin link again but also emit imports files now +; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps \ +; RUN: -thinlto-emit-indexes \ +; RUN: -thinlto-emit-imports \ +; RUN: -r=%t1.bc,g, \ +; RUN: -r=%t1.bc,analias, \ +; RUN: -r=%t1.bc,f,px \ +; RUN: -r=%t2.bc,g,px \ +; RUN: -r=%t2.bc,analias,px \ +; RUN: -r=%t2.bc,aliasee,px \ +; RUN: -o=%t.out + +; Check the output +; RUN: ls %t.out.1 +; RUN: ls %t.out.2 +; RUN: diff %t1.bc.thinlto.bc %t1.bc.thinlto.bc.orig +; RUN: diff %t2.bc.thinlto.bc %t2.bc.thinlto.bc.orig +; RUN: diff %t1.bc.imports %t1.bc.imports.orig +; RUN: diff %t2.bc.imports %t2.bc.imports.orig + +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +declare i32 @g(...) +declare void @analias(...) + +define void @f() { +entry: + call i32 (...) @g() + call void (...) @analias() + ret void +} + +!llvm.dbg.cu = !{} + +!1 = !{i32 2, !"Debug Info Version", i32 3} +!llvm.module.flags = !{!1} diff --git a/llvm/test/ThinLTO/X86/emit_imports.ll b/llvm/test/ThinLTO/X86/emit_imports.ll --- a/llvm/test/ThinLTO/X86/emit_imports.ll +++ b/llvm/test/ThinLTO/X86/emit_imports.ll @@ -32,6 +32,20 @@ ; RUN: -r=%t2.bc,g,px \ ; RUN: -r=%t2b.bc,h,px +; Ensure imports weren't generated since -thinlto-emit-imports wasn't specified +; RUN: not ls %t1.bc.imports +; RUN: not ls %t2.bc.imports +; RUN: not ls %t3.bc.imports + +; RUN: llvm-lto2 run %t1.bc %t2.bc %t2b.bc %t3.bc -o %t.o -save-temps \ +; RUN: -thinlto-distributed-indexes \ +; RUN: -thinlto-emit-imports \ +; RUN: -r=%t1.bc,g, \ +; RUN: -r=%t1.bc,h, \ +; RUN: -r=%t1.bc,f,px \ +; RUN: -r=%t2.bc,g,px \ +; RUN: -r=%t2b.bc,h,px + ; RUN: cat %t1.bc.imports | count 2 ; RUN: cat %t1.bc.imports | FileCheck %s --check-prefix=IMPORTS1 diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp --- a/llvm/tools/llvm-lto2/llvm-lto2.cpp +++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -73,6 +73,18 @@ "import files for the " "distributed backend case")); +static cl::opt + ThinLTOEmitIndexes("thinlto-emit-indexes", cl::init(false), + cl::desc("Write out individual index files via " + "InProcessThinLTO")); + +static cl::opt + ThinLTOEmitImports("thinlto-emit-imports", cl::init(false), + cl::desc("Write out individual imports files via " + "InProcessThinLTO. Has no effect unless " + "specified with -thinlto-emit-indexes or " + "-thinlto-distributed-indexes")); + // Default to using all available threads in the system, but using only one // thread per core (no SMT). // Use -thinlto-threads=all to use hardware_concurrency() instead, which means @@ -299,14 +311,16 @@ ThinBackend Backend; if (ThinLTODistributedIndexes) - Backend = createWriteIndexesThinBackend(/* OldPrefix */ "", - /* NewPrefix */ "", - /* ShouldEmitImportsFiles */ true, - /* LinkedObjectsFile */ nullptr, - /* OnWrite */ {}); + Backend = + createWriteIndexesThinBackend(/* OldPrefix */ "", + /* NewPrefix */ "", ThinLTOEmitImports, + /* LinkedObjectsFile */ nullptr, + /* OnWrite */ {}); else Backend = createInProcessThinBackend( - llvm::heavyweight_hardware_concurrency(Threads)); + llvm::heavyweight_hardware_concurrency(Threads), + /* OnWrite */ {}, ThinLTOEmitIndexes, ThinLTOEmitImports); + // Track whether we hit an error; in particular, in the multi-threaded case, // we can't exit() early because the rest of the threads wouldn't have had a // change to be join-ed, and that would result in a "terminate called without