llvm.org GIT mirror llvm / 87d73e9
IPO, LTO: Plumb the summary from the LTO API into the pass manager. Differential Revision: https://reviews.llvm.org/D28840 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292661 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 2 years ago
6 changed file(s) with 47 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
3333
3434 namespace lto {
3535
36 /// Runs a regular LTO backend.
36 /// Runs a regular LTO backend. The regular LTO backend can also act as the
37 /// regular LTO phase of ThinLTO, which may need to access the combined index.
3738 Error backend(Config &C, AddStreamFn AddStream,
3839 unsigned ParallelCodeGenParallelismLevel,
39 std::unique_ptr M);
40 std::unique_ptr M, ModuleSummaryIndex &CombinedIndex);
4041
4142 /// Runs a ThinLTO backend.
4243 Error thinBackend(Config &C, unsigned Task, AddStreamFn AddStream, Module &M,
2020 #include
2121
2222 namespace llvm {
23 class ModuleSummaryIndex;
2324 class Pass;
2425 class TargetLibraryInfoImpl;
2526 class TargetMachine;
122123 /// added to the per-module passes.
123124 Pass *Inliner;
124125
126 /// The module summary index to use for passing information between the
127 /// regular LTO phase and the thin LTO backends, for example the CFI and
128 /// devirtualization type tests.
129 ModuleSummaryIndex *Summary = nullptr;
130
125131 bool DisableTailCalls;
126132 bool DisableUnitAtATime;
127133 bool DisableUnrollLoops;
600600 return Error::success();
601601 }
602602 return backend(Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel,
603 std::move(RegularLTO.CombinedModule));
603 std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex);
604604 }
605605
606606 /// This class defines the interface to the ThinLTO backend.
167167 }
168168
169169 static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
170 bool IsThinLTO) {
170 bool IsThinLTO, ModuleSummaryIndex &CombinedIndex) {
171171 legacy::PassManager passes;
172172 passes.add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
173173
174174 PassManagerBuilder PMB;
175175 PMB.LibraryInfo = new TargetLibraryInfoImpl(Triple(TM->getTargetTriple()));
176176 PMB.Inliner = createFunctionInliningPass();
177 PMB.Summary = &CombinedIndex;
177178 // Unconditionally verify input since it is not verified before this
178179 // point and has unknown origin.
179180 PMB.VerifyInput = true;
190191 }
191192
192193 bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
193 bool IsThinLTO) {
194 bool IsThinLTO, ModuleSummaryIndex &CombinedIndex) {
194195 if (Conf.OptPipeline.empty())
195 runOldPMPasses(Conf, Mod, TM, IsThinLTO);
196 runOldPMPasses(Conf, Mod, TM, IsThinLTO, CombinedIndex);
196197 else
198 // FIXME: Plumb the combined index into the new pass manager.
197199 runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
198200 Conf.DisableVerify);
199201 return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
290292
291293 Error lto::backend(Config &C, AddStreamFn AddStream,
292294 unsigned ParallelCodeGenParallelismLevel,
293 std::unique_ptr Mod) {
295 std::unique_ptr Mod,
296 ModuleSummaryIndex &CombinedIndex) {
294297 Expected TOrErr = initAndLookupTarget(C, *Mod);
295298 if (!TOrErr)
296299 return TOrErr.takeError();
301304 handleAsmUndefinedRefs(*Mod, *TM);
302305
303306 if (!C.CodeGenOnly)
304 if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false))
307 if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false, CombinedIndex))
305308 return Error::success();
306309
307310 if (ParallelCodeGenParallelismLevel == 1) {
366369 if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
367370 return Error::success();
368371
369 if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true))
372 if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true, CombinedIndex))
370373 return Error::success();
371374
372375 codegen(Conf, TM.get(), AddStream, Task, Mod);
832832 if (VerifyInput)
833833 PM.add(createVerifierPass());
834834
835 if (Summary)
836 PM.add(
837 createLowerTypeTestsPass(LowerTypeTestsSummaryAction::Import, Summary));
838
835839 populateModulePassManager(PM);
836840
837841 if (VerifyOutput)
856860 // Lower type metadata and the type.test intrinsic. This pass supports Clang's
857861 // control flow integrity mechanisms (-fsanitize=cfi*) and needs to run at
858862 // link time if CFI is enabled. The pass does nothing if CFI is disabled.
859 PM.add(createLowerTypeTestsPass(LowerTypeTestsSummaryAction::None,
860 /*Summary=*/nullptr));
863 PM.add(createLowerTypeTestsPass(Summary ? LowerTypeTestsSummaryAction::Export
864 : LowerTypeTestsSummaryAction::None,
865 Summary));
861866
862867 if (OptLevel != 0)
863868 addLateLTOOptimizationPasses(PM);
0 ; RUN: opt -thinlto-bc -o %t %s
1 ; RUN: llvm-lto2 -r %t,f,plx -r %t,foo,lx -r %t,foo,plx -o %t1 %t
2 ; RUN: llvm-nm %t1.0 | FileCheck --check-prefix=MERGED %s
3 ; RUN: llvm-nm %t1.1 | FileCheck %s
4
5 ; MERGED: R __typeid_foo_global_addr
6 ; CHECK: U __typeid_foo_global_addr
7
8 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
9 target triple = "x86_64-unknown-linux-gnu"
10
11 @foo = global i32 0, !type !0
12
13 define i1 @f(i8* %ptr) {
14 %p = call i1 @llvm.type.test(i8* %ptr, metadata !"foo")
15 ret i1 %p
16 }
17
18 declare i1 @llvm.type.test(i8* %ptr, metadata %typeid) nounwind readnone
19
20 !0 = !{i32 0, !"foo"}