llvm.org GIT mirror llvm / 2ba6898
[SamplePGO] More pipeline changes when flattened profile used in ThinLTO postlink Summary: Follow on to D54819/r351476. We also don't need to perform extra InstCombine pass when we aren't loading the sample profile in the ThinLTO backend because we have a flattened sample profile. Additionally, for consistency and clarity, when we aren't reloading the sample profile, perform ICP in the same location as non-sample PGO backends. To this end I have moved the ICP invocation for non-SamplePGO ThinLTO down into buildModuleSimplificationPipeline (partly addresses the FIXME where we were previously setting this up). Reviewers: wmi Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57705 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353135 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 6 months ago
2 changed file(s) with 34 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
588588 bool DebugLogging) {
589589 ModulePassManager MPM(DebugLogging);
590590
591 bool HasSampleProfile = PGOOpt && !PGOOpt->SampleProfileFile.empty();
592
593 // In ThinLTO mode, when flattened profile is used, all the available
594 // profile information will be annotated in PreLink phase so there is
595 // no need to load the profile again in PostLink.
596 bool LoadSampleProfile =
597 HasSampleProfile &&
598 !(FlattenedProfileUsed && Phase == ThinLTOPhase::PostLink);
599
600 // During the ThinLTO backend phase we perform early indirect call promotion
601 // here, before globalopt. Otherwise imported available_externally functions
602 // look unreferenced and are removed. If we are going to load the sample
603 // profile then defer until later.
604 // TODO: See if we can move later and consolidate with the location where
605 // we perform ICP when we are loading a sample profile.
606 // TODO: We pass HasSampleProfile (whether there was a sample profile file
607 // passed to the compile) to the SamplePGO flag of ICP. This is used to
608 // determine whether the new direct calls are annotated with prof metadata.
609 // Ideally this should be determined from whether the IR is annotated with
610 // sample profile, and not whether the a sample profile was provided on the
611 // command line. E.g. for flattened profiles where we will not be reloading
612 // the sample profile in the ThinLTO backend, we ideally shouldn't have to
613 // provide the sample profile file.
614 if (Phase == ThinLTOPhase::PostLink && !LoadSampleProfile)
615 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, HasSampleProfile));
616
591617 // Do basic inference of function attributes from known properties of system
592618 // libraries and other oracles.
593619 MPM.addPass(InferFunctionAttrsPass());
608634 // More details about SamplePGO design can be found in:
609635 // https://research.google.com/pubs/pub45290.html
610636 // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
611 if (PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
612 Phase == ThinLTOPhase::PostLink)
637 if (LoadSampleProfile)
613638 EarlyFPM.addPass(InstCombinePass());
614639 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
615640
616 if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
641 if (LoadSampleProfile) {
617642 // Annotate sample profile right after early FPM to ensure freshness of
618643 // the debug info.
619 // In ThinLTO mode, when flattened profile is used, all the available
620 // profile information will be annotated in PreLink phase so there is
621 // no need to load the profile again in PostLink.
622 if (!(FlattenedProfileUsed && Phase == ThinLTOPhase::PostLink))
623 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
624 PGOOpt->ProfileRemappingFile,
625 Phase == ThinLTOPhase::PreLink));
644 MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
645 PGOOpt->ProfileRemappingFile,
646 Phase == ThinLTOPhase::PreLink));
626647 // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
627648 // for the profile annotation to be accurate in the ThinLTO backend.
628649 if (Phase != ThinLTOPhase::PreLink)
631652 // imported available_externally functions look unreferenced and are
632653 // removed.
633654 MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
634 true));
655 true /* SamplePGO */));
635656 }
636657
637658 // Interprocedural constant propagation now that basic cleanup has occurred
9881009
9891010 // Force any function attributes we want the rest of the pipeline to observe.
9901011 MPM.addPass(ForceFunctionAttrsPass());
991
992 // During the ThinLTO backend phase we perform early indirect call promotion
993 // here, before globalopt. Otherwise imported available_externally functions
994 // look unreferenced and are removed.
995 // FIXME: move this into buildModuleSimplificationPipeline to merge the logic
996 // with SamplePGO.
997 if (!PGOOpt || PGOOpt->SampleProfileFile.empty())
998 MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
999 false /* SamplePGO */));
10001012
10011013 // Add the core simplification pipeline.
10021014 MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
5454 ; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
5555 ; CHECK-DIS-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
5656 ; CHECK-DIS-NEXT: Running analysis: InnerAnalysisManagerProxy
57 ; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
58 ; CHECK-O-NEXT: Starting llvm::Module pass manager run.
5759 ; CHECK-POSTLINK-O-NEXT: Running pass: PGOIndirectCallPromotion
5860 ; CHECK-POSTLINK-O-NEXT: Running analysis: ProfileSummaryAnalysis
5961 ; CHECK-POSTLINK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
6062 ; CHECK-POSTLINK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
6163 ; CHECK-POSTLINK-O-NEXT: Running analysis: PassInstrumentationAnalysis
62 ; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
63 ; CHECK-O-NEXT: Starting llvm::Module pass manager run.
6464 ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
6565 ; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
6666 ; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>