llvm.org GIT mirror llvm / 6858db5
Move the SampleProfileLoader right after EarlyFPM. Summary: SampleProfileLoader pass do need to happen after some early cleanup passes so that inlining can happen correctly inside the SampleProfileLoader pass. Reviewers: chandlerc, davidxl, tejohnson Reviewed By: chandlerc, tejohnson Subscribers: sanjoy, mehdi_amini, eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D36333 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310296 91177308-0d34-0410-b5e6-96231b3b80d8 Dehao Chen 2 years ago
3 changed file(s) with 49 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
539539 EarlyFPM.addPass(SROA());
540540 EarlyFPM.addPass(EarlyCSEPass());
541541 EarlyFPM.addPass(LowerExpectIntrinsicPass());
542 // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
543 // to convert bitcast to direct calls so that they can be inlined during the
544 // profile annotation prepration step.
545 // More details about SamplePGO design can be found in:
546 // https://research.google.com/pubs/pub45290.html
547 // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
548 if (PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
549 Phase == ThinLTOPhase::PostLink)
550 EarlyFPM.addPass(InstCombinePass());
542551 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
552
553 if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
554 // Annotate sample profile right after early FPM to ensure freshness of
555 // the debug info.
556 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
557 // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
558 // for the profile annotation to be accurate in the ThinLTO backend.
559 if (Phase != ThinLTOPhase::PreLink)
560 // We perform early indirect call promotion here, before globalopt.
561 // This is important for the ThinLTO backend phase because otherwise
562 // imported available_externally functions look unreferenced and are
563 // removed.
564 MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
565 true));
566 }
543567
544568 // Interprocedural constant propagation now that basic cleanup has occured
545569 // and prior to optimizing globals.
767791 // Force any function attributes we want the rest of the pipeline to observe.
768792 MPM.addPass(ForceFunctionAttrsPass());
769793
770 if (PGOOpt && PGOOpt->SamplePGOSupport) {
794 if (PGOOpt && PGOOpt->SamplePGOSupport)
771795 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
772 if (!PGOOpt->SampleProfileFile.empty()) {
773 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
774 MPM.addPass(PGOIndirectCallPromotion(false, true));
775 }
776 }
777796
778797 // Add the core simplification pipeline.
779798 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
795814 // Force any function attributes we want the rest of the pipeline to observe.
796815 MPM.addPass(ForceFunctionAttrsPass());
797816
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) {
817 if (PGOOpt && PGOOpt->SamplePGOSupport)
802818 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
803 if (!PGOOpt->SampleProfileFile.empty())
804 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
805 }
806819
807820 // If we are planning to perform ThinLTO later, we don't bloat the code with
808821 // unrolling/vectorization/... now. Just simplify the module as much as we
838851 // Force any function attributes we want the rest of the pipeline to observe.
839852 MPM.addPass(ForceFunctionAttrsPass());
840853
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
846854 // During the ThinLTO backend phase we perform early indirect call promotion
847855 // here, before globalopt. Otherwise imported available_externally functions
848856 // look unreferenced and are removed.
849 MPM.addPass(PGOIndirectCallPromotion(
850 true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
857 // FIXME: move this into buildModuleSimplificationPipeline to merge the logic
858 // with SamplePGO.
859 if (PGOOpt && !PGOOpt->ProfileUseFile.empty())
860 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
861 false /* SamplePGO */));
851862
852863 // Add the core simplification pipeline.
853864 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
0 ; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=new-pm-pgo-instr-gen-pipeline -profile-file='temp' %s 2>&1 |FileCheck %s --check-prefixes=GEN
11 ; RUN: llvm-profdata merge %S/Inputs/new-pm-pgo.proftext -o %t.profdata
22 ; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=new-pm-pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 |FileCheck %s --check-prefixes=USE
3 ; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_USE
3 ; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \
4 ; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE,SAMPLE_USE_O
5 ; RUN: opt -debug-pass-manager -passes='thinlto-pre-link' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \
6 ; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE,SAMPLE_USE_PRE_LINK
7 ; RUN: opt -debug-pass-manager -passes='thinlto' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \
8 ; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE,SAMPLE_USE_POST_LINK
49 ; RUN: opt -debug-pass-manager -passes='default' -new-pm-debug-info-for-profiling %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_GEN
510 ;
611 ; GEN: Running pass: PGOInstrumentationGen
712 ; USE: Running pass: PGOInstrumentationUse
8 ; SAMPLE_USE: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
13 ; SAMPLE_USE_O: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
14 ; SAMPLE_USE_PRE_LINK: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
15 ; SAMPLE_USE: Running pass: SimplifyCFGPass
16 ; SAMPLE_USE: Running pass: SROA
17 ; SAMPLE_USE: Running pass: EarlyCSEPass
18 ; SAMPLE_USE: Running pass: LowerExpectIntrinsicPass
19 ; SAMPLE_USE_POST_LINK: Running pass: InstCombinePass
920 ; SAMPLE_USE: Running pass: SampleProfileLoaderPass
21 ; SAMPLE_USE_O: Running pass: PGOIndirectCallPromotion
22 ; SAMPLE_USE_POST_LINK-NOT: Running pass: GlobalOptPass
23 ; SAMPLE_USE_POST_LINK: Running pass: PGOIndirectCallPromotion
1024 ; SAMPLE_GEN: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
1125
1226 define void @foo() {
5252 ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass
5353 ; CHECK-DIS-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
5454 ; CHECK-DIS-NEXT: Running analysis: InnerAnalysisManagerProxy
55 ; CHECK-POSTLINK-O-NEXT: Running pass: PGOIndirectCallPromotion
56 ; CHECK-POSTLINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}Function
57 ; CHECK-POSTLINK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
5855 ; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
5956 ; CHECK-O-NEXT: Starting llvm::Module pass manager run.
6057 ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
6158 ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
6259 ; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>
6360 ; CHECK-PRELINK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy
61 ; CHECK-POSTLINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
6462 ; CHECK-O-NEXT: Starting llvm::Function pass manager run.
6563 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
6664 ; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
7977 ; CHECK-O-NEXT: Starting llvm::Function pass manager run.
8078 ; CHECK-O-NEXT: Running pass: InstCombinePass
8179 ; CHECK-PRELINK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
80 ; CHECK-POSTLINK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
8281 ; CHECK-O-NEXT: Running pass: SimplifyCFGPass
8382 ; CHECK-O-NEXT: Finished llvm::Function pass manager run.
8483 ; CHECK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}GlobalsAA