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,107 @@ +; 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 without +; the debug metadata for the thin link. +; 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 + +; 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: -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 +} + +; THINLINKBITCODE-NOT: IDENTIFICATION_BLOCK_ID +; THINLINKBITCODE-NOT: BLOCKINFO_BLOCK +; THINLINKBITCODE-NOT: TYPE_BLOCK_ID +; THINLINKBITCODE-NOT: VSTOFFSET +; THINLINKBITCODE-NOT: CONSTANTS_BLOCK +; THINLINKBITCODE-NOT: METADATA_KIND_BLOCK +; THINLINKBITCODE-NOT: METADATA_BLOCK +; THINLINKBITCODE-NOT: OPERAND_BUNDLE_TAGS_BLOCK +; THINLINKBITCODE-NOT: UnknownBlock26 +; THINLINKBITCODE-NOT: FUNCTION_BLOCK +; THINLINKBITCODE-NOT: VALUE_SYMTAB +; THINLINKBITCODE: MODULE_BLOCK +; THINLINKBITCODE: VERSION +; THINLINKBITCODE: SOURCE_FILENAME +; THINLINKBITCODE: GLOBALVAL_SUMMARY_BLOCK +; THINLINKBITCODE: HASH +; THINLINKBITCODE: SYMTAB_BLOCK +; THINLINKBITCODE: STRTAB_BLOCK + +!llvm.dbg.cu = !{} + +!1 = !{i32 2, !"Debug Info Version", i32 3} +!llvm.module.flags = !{!1} 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,17 @@ "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. Must be specified together " + "with -thinlto-emit-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 @@ -306,7 +317,9 @@ /* 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