llvm.org GIT mirror llvm / 760d33e
[HotColdSplit] Move splitting after instrumented PGO use Summary: Follow up to D57082 which moved splitting earlier in the pipeline, in order to perform it before inlining. However, it was moved too early, before the IR is annotated with instrumented PGO data. This caused the splitting to incorrectly determine cold functions. Move it to just after PGO annotation (still before inlining), in both pass managers. Reviewers: vsk, hiraditya, sebpop Subscribers: mehdi_amini, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57805 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353270 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 6 months ago
5 changed file(s) with 46 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
679679 // globals.
680680 MPM.addPass(DeadArgumentEliminationPass());
681681
682 // Create a small function pass pipeline to cleanup after all the global
683 // optimizations.
684 FunctionPassManager GlobalCleanupPM(DebugLogging);
685 GlobalCleanupPM.addPass(InstCombinePass());
686 invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
687
688 GlobalCleanupPM.addPass(SimplifyCFGPass());
689 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
690
691 // Add all the requested passes for instrumentation PGO, if requested.
692 if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
693 (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
694 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
695 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile,
696 PGOOpt->ProfileRemappingFile);
697 MPM.addPass(PGOIndirectCallPromotion(false, false));
698 }
699
700 // Synthesize function entry counts for non-PGO compilation.
701 if (EnableSyntheticCounts && !PGOOpt)
702 MPM.addPass(SyntheticCountsPropagation());
703
682704 // Split out cold code. Splitting is done before inlining because 1) the most
683705 // common kinds of cold regions can (a) be found before inlining and (b) do
684706 // not grow after inlining, and 2) inhibiting inlining of cold code improves
686708 // more accurate, but before InstCombine to allow it to clean things up.
687709 if (EnableHotColdSplit && Phase != ThinLTOPhase::PostLink)
688710 MPM.addPass(HotColdSplittingPass());
689
690 // Create a small function pass pipeline to cleanup after all the global
691 // optimizations.
692 FunctionPassManager GlobalCleanupPM(DebugLogging);
693 GlobalCleanupPM.addPass(InstCombinePass());
694 invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
695
696 GlobalCleanupPM.addPass(SimplifyCFGPass());
697 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
698
699 // Add all the requested passes for instrumentation PGO, if requested.
700 if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
701 (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
702 addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
703 PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile,
704 PGOOpt->ProfileRemappingFile);
705 MPM.addPass(PGOIndirectCallPromotion(false, false));
706 }
707
708 // Synthesize function entry counts for non-PGO compilation.
709 if (EnableSyntheticCounts && !PGOOpt)
710 MPM.addPass(SyntheticCountsPropagation());
711711
712712 // Require the GlobalsAA analysis for the module so we can query it within
713713 // the CGSCC pipeline.
516516
517517 MPM.add(createDeadArgEliminationPass()); // Dead argument elimination
518518
519 // Split out cold code before inlining. See comment in the new PM
520 // (\ref buildModuleSimplificationPipeline).
521 if (EnableHotColdSplit && DefaultOrPreLinkPipeline)
522 MPM.add(createHotColdSplittingPass());
523
524519 addInstructionCombiningPass(MPM); // Clean up after IPCP & DAE
525520 addExtensionsToPM(EP_Peephole, MPM);
526521 MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
532527 // not run it a second time
533528 if (DefaultOrPreLinkPipeline && !PrepareForThinLTOUsingPGOSampleProfile)
534529 addPGOInstrPasses(MPM);
530
531 // Split out cold code before inlining. See comment in the new PM
532 // (\ref buildModuleSimplificationPipeline).
533 if (EnableHotColdSplit && DefaultOrPreLinkPipeline)
534 MPM.add(createHotColdSplittingPass());
535535
536536 // We add a module alias analysis pass here. In part due to bugs in the
537537 // analysis infrastructure this "works" in that the analysis stays alive
0 ; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=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=pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 |FileCheck %s --check-prefixes=USE
3 ; RUN: opt -debug-pass-manager -passes='default' -hot-cold-split -pgo-kind=pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 |FileCheck %s --check-prefixes=USE --check-prefixes=SPLIT
34 ; RUN: opt -debug-pass-manager -passes='default' -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \
45 ; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE,SAMPLE_USE_O
56 ; RUN: opt -debug-pass-manager -passes='thinlto-pre-link' -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \
1112 ; GEN: Running pass: PGOInstrumentationGen
1213 ; USE: Running pass: PGOInstrumentationUse
1314 ; USE: Running pass: PGOIndirectCallPromotion
15 ; SPLIT: Running pass: HotColdSplittingPass
1416 ; USE: Running pass: PGOMemOPSizeOpt
1517 ; SAMPLE_USE_O: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
1618 ; SAMPLE_USE_PRE_LINK: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
55 ; RUN: opt -disable-output -disable-verify -debug-pass=Structure \
66 ; RUN: -O2 %s 2>&1 \
77 ; RUN: | FileCheck %s --check-prefix=CHECK-O2
8 ; RUN: llvm-profdata merge %S/Inputs/pass-pipelines.proftext -o %t.profdata
9 ; RUN: opt -disable-output -disable-verify -debug-pass=Structure \
10 ; RUN: -pgo-kind=pgo-instr-use-pipeline -profile-file='%t.profdata' \
11 ; RUN: -O2 %s 2>&1 \
12 ; RUN: | FileCheck %s --check-prefix=CHECK-O2 --check-prefix=PGOUSE
13 ; RUN: opt -disable-output -disable-verify -debug-pass=Structure \
14 ; RUN: -pgo-kind=pgo-instr-use-pipeline -profile-file='%t.profdata' \
15 ; RUN: -hot-cold-split \
16 ; RUN: -O2 %s 2>&1 \
17 ; RUN: | FileCheck %s --check-prefix=CHECK-O2 --check-prefix=PGOUSE --check-prefix=SPLIT
818 ;
919 ; In the first pipeline there should just be a function pass manager, no other
1020 ; pass managers.
2636 ; Very carefully assert the CGSCC pass pipeline as it is fragile and unusually
2737 ; susceptible to phase ordering issues.
2838 ; CHECK-O2: CallGraph Construction
39 ; PGOUSE: Call Graph SCC Pass Manager
40 ; PGOUSE: Function Integration/Inlining
41 ; PGOUSE: PGOInstrumentationUsePass
42 ; PGOUSE: PGOIndirectCallPromotion
43 ; SPLIT: Hot Cold Splitting
44 ; PGOUSE: CallGraph Construction
2945 ; CHECK-O2-NEXT: Globals Alias Analysis
3046 ; CHECK-O2-NEXT: Call Graph SCC Pass Manager
3147 ; CHECK-O2-NEXT: Remove unused exception handling info