Skip to content

Commit

Permalink
[ThinLTO][test] Add tests for emitting files in-process
Browse files Browse the repository at this point in the history
Completes D127777 by adding llvm-side tests for emitting index and imports files from in-process ThinLTO

Differential Revision: https://reviews.llvm.org/D128771
  • Loading branch information
Northbadge committed Jun 29, 2022
1 parent ff093c0 commit f702c7b
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 8 deletions.
3 changes: 1 addition & 2 deletions 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
Expand Down
87 changes: 87 additions & 0 deletions 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}
14 changes: 14 additions & 0 deletions llvm/test/ThinLTO/X86/emit_imports.ll
Expand Up @@ -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

Expand Down
26 changes: 20 additions & 6 deletions llvm/tools/llvm-lto2/llvm-lto2.cpp
Expand Up @@ -73,6 +73,18 @@ static cl::opt<bool>
"import files for the "
"distributed backend case"));

static cl::opt<bool>
ThinLTOEmitIndexes("thinlto-emit-indexes", cl::init(false),
cl::desc("Write out individual index files via "
"InProcessThinLTO"));

static cl::opt<bool>
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
Expand Down Expand Up @@ -299,14 +311,16 @@ static int run(int argc, char **argv) {

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
Expand Down

0 comments on commit f702c7b

Please sign in to comment.