diff options
author | Teresa Johnson <tejohnson@google.com> | 2017-03-23 19:47:39 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2017-03-23 19:47:39 +0000 |
commit | 0c6a4ff8dcd32c00b1362d7dd902fe4d4160d642 (patch) | |
tree | 916591cd4c573c735f5dee2cee403cfbd4a2f906 /llvm/test/Transforms/ThinLTOBitcodeWriter | |
parent | c78be4d3be678070ba4ad43bb1a18ddc7b7f96e7 (diff) | |
download | bcm5719-llvm-0c6a4ff8dcd32c00b1362d7dd902fe4d4160d642.tar.gz bcm5719-llvm-0c6a4ff8dcd32c00b1362d7dd902fe4d4160d642.zip |
[ThinLTO] Add support for emitting minimized bitcode for thin link
Summary:
The cumulative size of the bitcode files for a very large application
can be huge, particularly with -g. In a distributed build environment,
all of these files must be sent to the remote build node that performs
the thin link step, and this can exceed size limits.
The thin link actually only needs the summary along with a bitcode
symbol table. Until we have a proper bitcode symbol table, simply
stripping the debug metadata results in significant size reduction.
Add support for an option to additionally emit minimized bitcode
modules, just for use in the thin link step, which for now just strips
all debug metadata. I plan to add a cc1 option so this can be invoked
easily during the compile step.
However, care must be taken to ensure that these minimized thin link
bitcode files produce the same index as with the original bitcode files,
as these original bitcode files will be used in the backends.
Specifically:
1) The module hash used for caching is typically produced by hashing the
written bitcode, and we want to include the hash that would correspond
to the original bitcode file. This is because we want to ensure that
changes in the stripped portions affect caching. Added plumbing to emit
the same module hash in the minimized thin link bitcode file.
2) The module paths in the index are constructed from the module ID of
each thin linked bitcode, and typically is automatically generated from
the input file path. This is the path used for finding the modules to
import from, and obviously we need this to point to the original bitcode
files. Added gold-plugin support to take a suffix replacement during the
thin link that is used to override the identifier on the MemoryBufferRef
constructed from the loaded thin link bitcode file. The assumption is
that the build system can specify that the minimized bitcode file has a
name that is similar but uses a different suffix (e.g. out.thinlink.bc
instead of out.o).
Added various tests to ensure that we get identical index files out of
the thin link step.
Reviewers: mehdi_amini, pcc
Subscribers: Prazek, llvm-commits
Differential Revision: https://reviews.llvm.org/D31027
llvm-svn: 298638
Diffstat (limited to 'llvm/test/Transforms/ThinLTOBitcodeWriter')
-rw-r--r-- | llvm/test/Transforms/ThinLTOBitcodeWriter/no-type-md.ll | 37 | ||||
-rw-r--r-- | llvm/test/Transforms/ThinLTOBitcodeWriter/split.ll | 30 | ||||
-rw-r--r-- | llvm/test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll | 5 |
3 files changed, 61 insertions, 11 deletions
diff --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/no-type-md.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/no-type-md.ll index f1ada67abe5..753e07a326b 100644 --- a/llvm/test/Transforms/ThinLTOBitcodeWriter/no-type-md.ll +++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/no-type-md.ll @@ -1,6 +1,30 @@ -; RUN: opt -thinlto-bc -o %t %s -; RUN: llvm-dis -o - %t | FileCheck %s -; RUN: llvm-bcanalyzer -dump %t | FileCheck --check-prefix=BCA %s +; Generate bitcode files with summary, as well as minimized bitcode without +; the debug metadata for the thin link. +; RUN: opt -thinlto-bc -thin-link-bitcode-file=%t.thinlink.bc -o %t.bc %s +; RUN: llvm-dis -o - %t.bc | FileCheck %s +; RUN: llvm-dis -o - %t.thinlink.bc | FileCheck --check-prefix=NODEBUG %s +; RUN: llvm-bcanalyzer -dump %t.bc | FileCheck --check-prefix=BCA %s + +; Make sure the combined index files produced by both the normal and the +; thin link bitcode files are identical +; RUN: llvm-lto -thinlto -o %t3 %t.bc +; Copy the minimized bitcode to the regular bitcode path so the module +; paths in the index are the same (save and restore the regular bitcode +; for use again further down). +; RUN: mv %t.bc %t.bc.sv +; RUN: cp %t.thinlink.bc %t.bc +; RUN: llvm-lto -thinlto -o %t4 %t.bc +; RUN: mv %t.bc.sv %t.bc +; RUN: diff %t3.thinlto.bc %t4.thinlto.bc + +; Try again using -thinlto-action to produce combined index +; RUN: rm -f %t3.thinlto.bc %t4.thinlto.bc +; RUN: llvm-lto -thinlto-action=thinlink -o %t3.thinlto.bc %t.bc +; Copy the minimized bitcode to the regular bitcode path so the module +; paths in the index are the same. +; RUN: cp %t.thinlink.bc %t.bc +; RUN: llvm-lto -thinlto-action=thinlink -o %t4.thinlto.bc %t.bc +; RUN: diff %t3.thinlto.bc %t4.thinlto.bc ; BCA: <GLOBALVAL_SUMMARY_BLOCK @@ -11,3 +35,10 @@ define void @f() { ret void } + +; CHECK: !llvm.dbg.cu +; NODEBUG-NOT: !llvm.dbg.cu +!llvm.dbg.cu = !{} + +!1 = !{i32 2, !"Debug Info Version", i32 3} +!llvm.module.flags = !{!1} diff --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/split.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/split.ll index 98799a2c01f..d37d10bd356 100644 --- a/llvm/test/Transforms/ThinLTOBitcodeWriter/split.ll +++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/split.ll @@ -1,11 +1,26 @@ -; RUN: opt -thinlto-bc -o %t %s -; RUN: llvm-modextract -b -n 0 -o %t0 %t -; RUN: llvm-modextract -b -n 1 -o %t1 %t +; Generate bitcode files with summary, as well as minimized bitcode without +; the debug metadata for the thin link. +; RUN: opt -thinlto-bc -thin-link-bitcode-file=%t2 -o %t %s +; RUN: llvm-modextract -b -n 0 -o %t0.bc %t +; RUN: llvm-modextract -b -n 1 -o %t1.bc %t +; RUN: llvm-modextract -b -n 0 -o %t0.thinlink.bc %t2 +; RUN: llvm-modextract -b -n 1 -o %t1.thinlink.bc %t2 ; RUN: not llvm-modextract -b -n 2 -o - %t 2>&1 | FileCheck --check-prefix=ERROR %s -; RUN: llvm-dis -o - %t0 | FileCheck --check-prefix=M0 %s -; RUN: llvm-dis -o - %t1 | FileCheck --check-prefix=M1 %s -; RUN: llvm-bcanalyzer -dump %t0 | FileCheck --check-prefix=BCA0 %s -; RUN: llvm-bcanalyzer -dump %t1 | FileCheck --check-prefix=BCA1 %s +; RUN: llvm-dis -o - %t0.bc | FileCheck --check-prefix=M0 %s +; RUN: llvm-dis -o - %t1.bc | FileCheck --check-prefix=M1 %s +; RUN: llvm-dis -o - %t0.thinlink.bc | FileCheck --check-prefix=NODEBUG %s +; RUN: llvm-dis -o - %t1.thinlink.bc | FileCheck --check-prefix=NODEBUG %s +; RUN: llvm-bcanalyzer -dump %t0.bc | FileCheck --check-prefix=BCA0 %s +; RUN: llvm-bcanalyzer -dump %t1.bc | FileCheck --check-prefix=BCA1 %s + +; Make sure the combined index files produced by both the normal and the +; thin link bitcode files are identical +; RUN: llvm-lto -thinlto -o %t3 %t0.bc +; Copy the minimized bitcode to the regular bitcode path so the module +; paths in the index are the same. +; RUN: cp %t0.thinlink.bc %t0.bc +; RUN: llvm-lto -thinlto -o %t4 %t0.bc +; RUN: diff %t3.thinlto.bc %t4.thinlto.bc ; ERROR: llvm-modextract: error: module index out of range; bitcode file contains 2 module(s) @@ -29,6 +44,7 @@ define i8* @f() { ; M0: !llvm.dbg.cu ; M1-NOT: !llvm.dbg.cu +; NODEBUG-NOT: !llvm.dbg.cu !llvm.dbg.cu = !{} !1 = !{i32 2, !"Debug Info Version", i32 3} diff --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll index fbc97a00097..718013e39b3 100644 --- a/llvm/test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll +++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/unsplittable.ll @@ -1,6 +1,9 @@ -; RUN: opt -thinlto-bc -o %t %s +; RUN: opt -thinlto-bc -thin-link-bitcode-file=%t2 -o %t %s ; RUN: llvm-dis -o - %t | FileCheck %s ; RUN: llvm-bcanalyzer -dump %t | FileCheck --check-prefix=BCA %s +; When not splitting the module, the thin link bitcode file should simply be a +; copy of the regular module. +; RUN: diff %t %t2 ; BCA-NOT: <GLOBALVAL_SUMMARY_BLOCK |