llvm.org GIT mirror llvm / cbd2841
Update the new PM pipeline to make ICP aware if it is SamplePGO build. Summary: In ThinLTO backend compile, OPTOptions are not set so that the ICP in ThinLTO backend does not know if it is a SamplePGO build, in which profile count needs to be annotated directly on call instructions. This patch cleaned up the PGOOptions handling logic and passes down PGOOptions to ThinLTO backend. Reviewers: chandlerc, tejohnson, davidxl Reviewed By: chandlerc Subscribers: sanjoy, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D36052 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309780 91177308-0d34-0410-b5e6-96231b3b80d8 Dehao Chen 3 years ago
4 changed file(s) with 81 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
130130 Conf.CodeModel, Conf.CGOptLevel));
131131 }
132132
133 static void runNewPMPasses(Module &Mod, TargetMachine *TM, unsigned OptLevel,
134 bool IsThinLTO) {
135 PassBuilder PB(TM);
133 static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
134 unsigned OptLevel, bool IsThinLTO) {
135 Optional PGOOpt;
136 if (!Conf.SampleProfile.empty())
137 PGOOpt = PGOOptions("", "", Conf.SampleProfile, false, true);
138
139 PassBuilder PB(TM, PGOOpt);
136140 AAManager AA;
137141
138142 // Parse a custom AA pipeline if asked to.
261265 runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
262266 Conf.DisableVerify);
263267 else if (Conf.UseNewPM)
264 runNewPMPasses(Mod, TM, Conf.OptLevel, IsThinLTO);
268 runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO);
265269 else
266270 runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
267271 return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
570570 GlobalCleanupPM.addPass(SimplifyCFGPass());
571571 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
572572
573 // Add all the requested passes for PGO, if requested.
574 if (PGOOpt) {
575 if (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())
576 // Instrumentation based PGO (gen and use)
577 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
578 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
579 else if (!PGOOpt->SampleProfileFile.empty())
580 // SamplePGO use
581 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
582
583 // Indirect call promotion that promotes intra-module targes only.
584 // Do not enable it in PreLinkThinLTO phase during sample PGO because
585 // it changes IR to makes profile annotation in back compile inaccurate.
586 if ((Phase != ThinLTOPhase::PreLink && !PGOOpt->SampleProfileFile.empty())
587 || !PGOOpt->ProfileUseFile.empty())
588 MPM.addPass(PGOIndirectCallPromotion(
589 false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
573 // Add all the requested passes for instrumentation PGO, if requested.
574 if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
575 (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
576 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
577 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
578 MPM.addPass(PGOIndirectCallPromotion(false, false));
590579 }
591580
592581 // Require the GlobalsAA analysis for the module so we can query it within
778767 // Force any function attributes we want the rest of the pipeline to observe.
779768 MPM.addPass(ForceFunctionAttrsPass());
780769
781 if (PGOOpt && PGOOpt->SamplePGOSupport)
770 if (PGOOpt && PGOOpt->SamplePGOSupport) {
782771 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
772 if (!PGOOpt->SampleProfileFile.empty()) {
773 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
774 MPM.addPass(PGOIndirectCallPromotion(false, true));
775 }
776 }
783777
784778 // Add the core simplification pipeline.
785779 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
801795 // Force any function attributes we want the rest of the pipeline to observe.
802796 MPM.addPass(ForceFunctionAttrsPass());
803797
804 if (PGOOpt && PGOOpt->SamplePGOSupport)
798 // Invoke the SamplePGO annotation pass for the first time to annotate
799 // profile for functions in the current module to give ThinLink info
800 // about module grouping.
801 if (PGOOpt && PGOOpt->SamplePGOSupport) {
805802 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
803 if (!PGOOpt->SampleProfileFile.empty())
804 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
805 }
806806
807807 // If we are planning to perform ThinLTO later, we don't bloat the code with
808808 // unrolling/vectorization/... now. Just simplify the module as much as we
838838 // Force any function attributes we want the rest of the pipeline to observe.
839839 MPM.addPass(ForceFunctionAttrsPass());
840840
841 // Invoke the SamplePGO annotation pass for the second time to annotate on
842 // functions imported from other modules.
843 if (PGOOpt && !PGOOpt->SampleProfileFile.empty())
844 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
845
841846 // During the ThinLTO backend phase we perform early indirect call promotion
842847 // here, before globalopt. Otherwise imported available_externally functions
843848 // look unreferenced and are removed.
844849 MPM.addPass(PGOIndirectCallPromotion(
845 true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
846 !PGOOpt->ProfileUseFile.empty()));
850 true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
847851
848852 // Add the core simplification pipeline.
849853 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
0 ; Test that llvm-lto2 handles the -lto-sample-profile-file option and pass
1 ; down to the ICP correctly.
2 ;
3 ; RUN: opt -module-summary < %s -o %t.bc
4 ; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
5 ; RUN: -r %t.bc,test,px -r %t.bc,bar,x \
6 ; 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
8 ; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
9 ; RUN: -r %t.bc,test,px -r %t.bc,bar,x -use-new-pm \
10 ; 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
12
13 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
14 target triple = "x86_64-unknown-linux-gnu"
15
16 ; CHECK-LABEL: @test
17 ; Checks that the call instruction is promoted to direct call and has
18 ; profile count annotated on the direct call.
19 define void @test(void ()*) !dbg !7 {
20 %2 = alloca void ()*
21 store void ()* %0, void ()** %2
22 %3 = load void ()*, void ()** %2
23 ; CHECK: call void @bar(),{{.*}}!prof
24 call void %3(), !dbg !10
25 ret void
26 }
27
28 declare void @bar() local_unnamed_addr
29
30 !llvm.dbg.cu = !{!0}
31 !llvm.module.flags = !{!3, !4, !5}
32 !llvm.ident = !{!6}
33
34 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
35 !1 = !DIFile(filename: "test.c", directory: "/tmp")
36 !2 = !{}
37 !3 = !{i32 2, !"Dwarf Version", i32 4}
38 !4 = !{i32 2, !"Debug Info Version", i32 3}
39 !5 = !{i32 1, !"wchar_size", i32 4}
40 !6 = !{!"clang version 6.0.0 "}
41 !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, variables: !2)
42 !8 = !DISubroutineType(types: !9)
43 !9 = !{null}
44 !10 = !DILocation(line: 4, column: 5, scope: !7)
45 !11 = !DILocation(line: 5, column: 1, scope: !7)