llvm.org GIT mirror llvm / ef76fcd
[LTO] Make processing of combined module more consistent Summary: 1. Use stream 0 only for combined module. Previously if combined module was not processes ThinLTO used the stream for own output. However small changes in input, could trigger combined module and shuffle outputs making life of llvm::LTO harder. 2. Always process combined module and write output to stream 0. Processing empty combined module is cheap and allows llvm::LTO users to avoid implementing processing which is already done in llvm::LTO. Subscribers: mehdi_amini, inglorion, eraman, hiraditya Differential Revision: https://reviews.llvm.org/D41267 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320905 91177308-0d34-0410-b5e6-96231b3b80d8 Vitaly Buka 1 year, 9 months ago
23 changed file(s) with 70 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
370370 const SymbolResolution *&ResI, const SymbolResolution *ResE);
371371
372372 Error runRegularLTO(AddStreamFn AddStream);
373 Error runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
374 bool HasRegularLTO);
373 Error runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache);
375374
376375 mutable bool CalledGetMaxTasks = false;
377376 };
384384 LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
385385 Config &Conf)
386386 : ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel),
387 Ctx(Conf) {}
387 Ctx(Conf), CombinedModule(llvm::make_unique("ld-temp.o", Ctx)),
388 Mover(llvm::make_unique(*CombinedModule)) {}
388389
389390 LTO::ThinLTOState::ThinLTOState(ThinBackend Backend) : Backend(Backend) {
390391 if (!Backend)
470471
471472 if (Conf.ResolutionFile)
472473 writeToResolutionFile(*Conf.ResolutionFile, Input.get(), Res);
474
475 if (RegularLTO.CombinedModule->getTargetTriple().empty())
476 RegularLTO.CombinedModule->setTargetTriple(Input->getTargetTriple());
473477
474478 const SymbolResolution *ResI = Res.begin();
475479 for (unsigned I = 0; I != Input->Mods.size(); ++I)
658662
659663 Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod,
660664 bool LivenessFromIndex) {
661 if (!RegularLTO.CombinedModule) {
662 RegularLTO.CombinedModule =
663 llvm::make_unique("ld-temp.o", RegularLTO.Ctx);
664 RegularLTO.Mover = llvm::make_unique(*RegularLTO.CombinedModule);
665 }
666
667665 std::vector Keep;
668666 for (GlobalValue *GV : Mod.Keep) {
669667 if (LivenessFromIndex && !ThinLTO.CombinedIndex.isGUIDLive(GV->getGUID()))
756754
757755 computeDeadSymbols(ThinLTO.CombinedIndex, GUIDPreservedSymbols);
758756
759 // Save the status of having a regularLTO combined module, as
760 // this is needed for generating the ThinLTO Task ID, and
761 // the CombinedModule will be moved at the end of runRegularLTO.
762 bool HasRegularLTO = RegularLTO.CombinedModule != nullptr ||
763 !RegularLTO.ModsWithSummaries.empty();
764 // Invoke regular LTO if there was a regular LTO module to start with.
765 if (HasRegularLTO)
766 if (auto E = runRegularLTO(AddStream))
767 return E;
768 return runThinLTO(AddStream, Cache, HasRegularLTO);
757 if (auto E = runRegularLTO(AddStream))
758 return E;
759 return runThinLTO(AddStream, Cache);
769760 }
770761
771762 Error LTO::runRegularLTO(AddStreamFn AddStream) {
10801071 };
10811072 }
10821073
1083 Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
1084 bool HasRegularLTO) {
1074 Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache) {
10851075 if (ThinLTO.ModuleMap.empty())
10861076 return Error::success();
10871077
11661156 ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
11671157 AddStream, Cache);
11681158
1169 // Task numbers start at ParallelCodeGenParallelismLevel if an LTO
1170 // module is present, as tasks 0 through ParallelCodeGenParallelismLevel-1
1171 // are reserved for parallel code generation partitions.
1172 unsigned Task =
1173 HasRegularLTO ? RegularLTO.ParallelCodeGenParallelismLevel : 0;
1159 // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for combined
1160 // module and parallel code generation partitions.
1161 unsigned Task = RegularLTO.ParallelCodeGenParallelismLevel;
11741162 for (auto &Mod : ThinLTO.ModuleMap) {
11751163 if (Error E = BackendProc->start(Task, Mod.second, ImportLists[Mod.first],
11761164 ExportLists[Mod.first],
22 ; RUN: llvm-lto2 run %t -r %t,main,px -r %t,alias,p -r %t,external, \
33 ; RUN: %t2 -r %t2,external,p \
44 ; RUN: -save-temps -o %t3
5 ; RUN: llvm-nm %t3.1 | FileCheck %s
5 ; RUN: llvm-nm %t3.2 | FileCheck %s
66
77 ; CHECK: D external
88
0 ; RUN: opt -module-summary -o %t.bc %s
11 ; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -o %t2
2 ; RUN: llvm-nm %t2.0 | FileCheck %s
2 ; RUN: llvm-nm %t2.1 | FileCheck %s
33 ; CHECK: T foo
44 ; CHECK: t foo_ifunc
55
0 ; RUN: opt -module-summary %s -o %t.o
11 ; RUN: llvm-lto2 run -o %t1.o %t.o -r %t.o,patatino,pr
2 ; RUN: llvm-readobj -t %t1.o.0 | FileCheck %s
2 ; RUN: llvm-readobj -t %t1.o.1 | FileCheck %s
33
44 ; CHECK: Name: patatino
55 ; CHECK-NEXT: Value:
0 ; RUN: opt -module-summary -o %t %s
11 ; RUN: llvm-lto2 run %t -O0 -r %t,foo,px -o %t2
2 ; RUN: llvm-nm %t2.0 | FileCheck %s
2 ; RUN: llvm-nm %t2.1 | FileCheck %s
33
44 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
55 target triple = "x86_64-unknown-linux-gnu"
44 ; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
55 ; RUN: -r %t.bc,test,px -r %t.bc,bar,x \
66 ; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof-icp.prof
7 ; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
7 ; RUN: llvm-dis %t.out.1.4.opt.bc -o - | FileCheck %s
88 ; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
99 ; RUN: -r %t.bc,test,px -r %t.bc,bar,x -use-new-pm \
1010 ; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof-icp.prof
11 ; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
11 ; RUN: llvm-dis %t.out.1.4.opt.bc -o - | FileCheck %s
1212
1313 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
1414 target triple = "x86_64-unknown-linux-gnu"
33 ; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
44 ; RUN: -r %t.bc,foo,px -r %t.bc,bar,x \
55 ; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof.prof
6 ; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
6 ; RUN: llvm-dis %t.out.1.4.opt.bc -o - | FileCheck %s
77 ;
88 ; CHECK: !prof
99
0 ; RUN: opt -module-summary -o %t.bc %s
11 ; RUN: opt -module-summary -o %t2.bc %S/Inputs/mod-asm-used.ll
22 ; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,l %t2.bc -r %t2.bc,foo,pl -o %t3
3 ; RUN: llvm-nm %t3.1 | FileCheck %s
3 ; RUN: llvm-nm %t3.* | FileCheck %s
44
55 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
66 target triple = "x86_64-unknown-linux-gnu"
1818 ; RUN: -r %t2.bc,_dead_func,l \
1919 ; RUN: -r %t2.bc,_another_dead_func,pl
2020 ; RUN: llvm-dis < %t.out.0.3.import.bc | FileCheck %s --check-prefix=LTO2
21 ; RUN: llvm-dis < %t.out.1.3.import.bc | FileCheck %s --check-prefix=LTO2-CHECK2
21 ; RUN: llvm-dis < %t.out.2.3.import.bc | FileCheck %s --check-prefix=LTO2-CHECK2
2222 ; RUN: llvm-nm %t.out.1 | FileCheck %s --check-prefix=CHECK2-NM
2323
2424 ; RUN: llvm-bcanalyzer -dump %t.out.index.bc | FileCheck %s --check-prefix=COMBINED
1010 ; RUN: -r %t2.bc,main,plx \
1111 ; RUN: -r %t2.bc,foo,l \
1212 ; RUN: -r %t1.bc,foo,pl
13 ; RUN: llvm-dis < %t.out.1.3.import.bc | FileCheck %s
13 ; RUN: llvm-dis < %t.out.2.3.import.bc | FileCheck %s
1414
1515 ; CHECK: distinct !DICompositeType(tag: DW_TAG_enumeration_type, name: "enum", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 50, size: 32, flags: DIFlagFwdDecl, identifier: "enum")
1616 ; CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, name: "class", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 728, size: 448, flags: DIFlagFwdDecl, identifier: "class")
2424 ; RUN: -r %t2.bc,main,plx \
2525 ; RUN: -r %t2.bc,foo,l \
2626 ; RUN: -r %t1.bc,foo,pl
27 ; RUN: llvm-dis < %t.out.1.3.import.bc | FileCheck %s --check-prefix=FULL
27 ; RUN: llvm-dis < %t.out.2.3.import.bc | FileCheck %s --check-prefix=FULL
2828
2929 ; FULL: distinct !DICompositeType(tag: DW_TAG_enumeration_type, name: "enum", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 50, size: 32, elements: !{{[0-9]+}}, identifier: "enum")
3030 ; FULL: distinct !DICompositeType(tag: DW_TAG_class_type, name: "class", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 728, size: 448, elements: !{{[0-9]+}}, identifier: "class")
5757 ; IMPORT: define available_externally void @analias() !thinlto_src_module
5858 ; EXPORT: @G.llvm.
5959
60 target triple = "x86_64-unknown-linux-gnu"
6061 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6162
6263 declare i32 @g(...)
0 ; RUN: opt -module-summary -o %t.bc %s
1
2 ; RUN: rm -f %t2.0
3 ; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -o %t2 -thinlto-distributed-indexes
4 ; RUN: llvm-readobj -h %t2.0 | FileCheck %s
5 ; RUN: llvm-nm %t2.0 | count 0
6
7 ; CHECK: Format: ELF64-x86-64
8
9 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
10 target triple = "x86_64-unknown-linux-gnu"
11
12 @foo = ifunc i32 (i32), i64 ()* @foo_ifunc
13
14 define internal i64 @foo_ifunc() {
15 entry:
16 ret i64 0
17 }
55 ; RUN: -r=%t1.bc,_foo,plx \
66 ; RUN: -r=%t2.bc,_main,plx \
77 ; RUN: -r=%t2.bc,_foo,l
8 ; RUN: llvm-dis %t.o.1.3.import.bc -o - | FileCheck %s
8 ; RUN: llvm-dis %t.o.2.3.import.bc -o - | FileCheck %s
99 ; CHECK: define available_externally dso_local void @foo()
1010
1111 ; We shouldn't do any importing at -O0
1515 ; RUN: -r=%t1.bc,_foo,plx \
1616 ; RUN: -r=%t2.bc,_main,plx \
1717 ; RUN: -r=%t2.bc,_foo,l
18 ; RUN: llvm-dis %t.o.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECKO0
18 ; RUN: llvm-dis %t.o.2.3.import.bc -o - | FileCheck %s --check-prefix=CHECKO0
1919 ; CHECKO0: declare dso_local void @foo(...)
2020
2121 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
66 ; RUN: -r=%t1.bc,_foo,pxl \
77 ; RUN: -r=%t1.bc,_bar,pl \
88 ; RUN: -r=%t1.bc,_linkonce_func,pl
9 ; RUN: llvm-dis < %t.o.0.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE2
9 ; RUN: llvm-dis < %t.o.1.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE2
1010
1111
1212 ; REGULAR: define void @foo
2626 ; RUN: -r=%t2.bc,func3,l \
2727 ; RUN: -r=%t2.bc,callglobalfunc,l \
2828 ; RUN: -r=%t2.bc,callweakfunc,l
29 ; RUN: llvm-nm %t.o.0 | FileCheck %s --check-prefix=NM0
30 ; RUN: llvm-nm %t.o.1 | FileCheck %s --check-prefix=NM1
29 ; RUN: llvm-nm %t.o.1 | FileCheck %s --check-prefix=NM0
30 ; RUN: llvm-nm %t.o.2 | FileCheck %s --check-prefix=NM1
3131
3232 ; Check that local values b and x, which are referenced on
3333 ; llvm.used and llvm.compiler.used, respectively, are not promoted.
1010 ; RUN: -r=%t1.bc,_simplefunction,pl \
1111 ; RUN: -r=%t2.bc,main,plx \
1212 ; RUN: -r=%t2.bc,_simplefunction,l
13 ; RUN: llvm-nm %t.o.0 | FileCheck %s --check-prefix=NM0
14 ; RUN: llvm-nm %t.o.1 | FileCheck %s --check-prefix=NM1
13 ; RUN: llvm-nm %t.o.1 | FileCheck %s --check-prefix=NM0
14 ; RUN: llvm-nm %t.o.2 | FileCheck %s --check-prefix=NM1
1515
1616 ; NM0: T foo
1717 ; NM1-NOT: foo
55 ; RUN: -r %t1.bc,foo,l \
66 ; RUN: -r %t1.bc,bar,p \
77 ; RUN: -r %t1.bc,main,xp
8 ; RUN: llvm-readobj -t %t.o.1 | FileCheck %s
8 ; RUN: llvm-readobj -t %t.o.2 | FileCheck %s
99
1010 ; CHECK: Symbol {
1111 ; CHECK: Name: foo
1313 ; RUN: -r %t1.bc,personality_routine3,l \
1414 ; RUN: -r %t1.bc,main,xp \
1515 ; RUN: -r %t1.bc,bar,l
16 ; RUN: llvm-readobj -t %t.o.1 | FileCheck %s --check-prefix=BINDING
16 ; RUN: llvm-readobj -t %t.o.2 | FileCheck %s --check-prefix=BINDING
1717
1818 ; BINDING: Symbol {
1919 ; BINDING: Name: personality_routine
1313 target triple = "x86_64-apple-macosx10.11.0"
1414
1515 ; We shouldn't promote the private because it has a section
16 ; RUN: llvm-dis < %t.o.0.2.internalize.bc | FileCheck %s --check-prefix=PROMOTE
16 ; RUN: llvm-dis < %t.o.1.2.internalize.bc | FileCheck %s --check-prefix=PROMOTE
1717 ; PROMOTE: @a = private global i8 0, section "__TEXT,__cstring,cstring_literals"
1818 @a = private global i8 0, section "__TEXT,__cstring,cstring_literals"
1919 @b = global i8 *@a
2020
2121
2222 ; We want foo to be imported in the main module!
23 ; RUN: llvm-dis < %t.o.1.3.import.bc | FileCheck %s --check-prefix=IMPORT
23 ; RUN: llvm-dis < %t.o.2.3.import.bc | FileCheck %s --check-prefix=IMPORT
2424 ; IMPORT: define available_externally dso_local i8** @foo()
2525 define i8 **@foo() {
2626 ret i8 **@b
99 ; RUN: -r %t.bc,_Z4LinkPKcS0_,plx \
1010 ; RUN: -r %t.bc,link,l \
1111 ; RUN: -r %t2.bc,get_link,plx
12 ; RUN: llvm-nm %t.out.0 | FileCheck %s
12 ; RUN: llvm-nm %t.out.1 | FileCheck %s
1313 ; CHECK: U link
1414
1515 ; REQUIRES: x86-registered-target
2020 ; IMPORTS2-NOT: Import _ZL3barv
2121 ; RUN: llvm-nm %t3.2 | FileCheck %s --check-prefix=NM
2222 ; NM: _ZL3barv
23 ; RUN: llvm-dis < %t3.2.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE
23 ; RUN: llvm-dis < %t3.3.2.internalize.bc | FileCheck %s --check-prefix=INTERNALIZE
2424 ; INTERNALIZE: define dso_local void @_ZL3barv
2525
2626 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6767 ; RUN: --plugin-opt=jobs=2 \
6868 ; RUN: --plugin-opt=obj-path=%t5.o \
6969 ; RUN: -shared %t.o %t2.o -o %t4
70 ; RUN: llvm-nm %t5.o | FileCheck %s --check-prefix=NM2
7170 ; RUN: llvm-nm %t5.o1 | FileCheck %s --check-prefix=NM2
71 ; RUN: llvm-nm %t5.o2 | FileCheck %s --check-prefix=NM2
72
73 ; Test to ensure that thinlto-index-only with obj-path creates the file.
74 ; RUN: rm -f %t5.o %t5.o1
75 ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
76 ; RUN: -m elf_x86_64 \
77 ; RUN: --plugin-opt=thinlto \
78 ; RUN: --plugin-opt=jobs=2 \
79 ; RUN: --plugin-opt=thinlto-index-only \
80 ; RUN: --plugin-opt=obj-path=%t5.o \
81 ; RUN: -shared %t.o %t2.o -o %t4
82 ; RUN: llvm-readobj -h %t5.o | FileCheck %s --check-prefix=FORMAT
83 ; RUN: llvm-nm %t5.o | count 0
7284
7385 ; NM: T f
7486 ; NM2: T {{f|g}}
87 ; FORMAT: Format: ELF64-x86-64
7588
7689 ; The backend index for this module contains summaries from itself and
7790 ; Inputs/thinlto.ll, as it imports from the latter.