summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/LTO/LTOBackend.cpp12
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp46
2 files changed, 33 insertions, 25 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 3f72e446cdf..6d1e37fa7e1 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -131,9 +131,13 @@ createTargetMachine(Config &Conf, const Target *TheTarget, Module &M) {
Conf.CodeModel, Conf.CGOptLevel));
}
-static void runNewPMPasses(Module &Mod, TargetMachine *TM, unsigned OptLevel,
- bool IsThinLTO) {
- PassBuilder PB(TM);
+static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
+ unsigned OptLevel, bool IsThinLTO) {
+ Optional<PGOOptions> PGOOpt;
+ if (!Conf.SampleProfile.empty())
+ PGOOpt = PGOOptions("", "", Conf.SampleProfile, false, true);
+
+ PassBuilder PB(TM, PGOOpt);
AAManager AA;
// Parse a custom AA pipeline if asked to.
@@ -262,7 +266,7 @@ bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
Conf.DisableVerify);
else if (Conf.UseNewPM)
- runNewPMPasses(Mod, TM, Conf.OptLevel, IsThinLTO);
+ runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO);
else
runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index de9e2a98deb..f2dd950f22e 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -571,23 +571,12 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
GlobalCleanupPM.addPass(SimplifyCFGPass());
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
- // Add all the requested passes for PGO, if requested.
- if (PGOOpt) {
- if (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())
- // Instrumentation based PGO (gen and use)
- addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
- PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
- else if (!PGOOpt->SampleProfileFile.empty())
- // SamplePGO use
- MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
-
- // Indirect call promotion that promotes intra-module targes only.
- // Do not enable it in PreLinkThinLTO phase during sample PGO because
- // it changes IR to makes profile annotation in back compile inaccurate.
- if ((Phase != ThinLTOPhase::PreLink && !PGOOpt->SampleProfileFile.empty())
- || !PGOOpt->ProfileUseFile.empty())
- MPM.addPass(PGOIndirectCallPromotion(
- false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
+ // Add all the requested passes for instrumentation PGO, if requested.
+ if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
+ (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
+ addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
+ PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
+ MPM.addPass(PGOIndirectCallPromotion(false, false));
}
// Require the GlobalsAA analysis for the module so we can query it within
@@ -779,8 +768,13 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
- if (PGOOpt && PGOOpt->SamplePGOSupport)
+ if (PGOOpt && PGOOpt->SamplePGOSupport) {
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+ if (!PGOOpt->SampleProfileFile.empty()) {
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+ MPM.addPass(PGOIndirectCallPromotion(false, true));
+ }
+ }
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
@@ -802,8 +796,14 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
- if (PGOOpt && PGOOpt->SamplePGOSupport)
+ // Invoke the SamplePGO annotation pass for the first time to annotate
+ // profile for functions in the current module to give ThinLink info
+ // about module grouping.
+ if (PGOOpt && PGOOpt->SamplePGOSupport) {
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+ if (!PGOOpt->SampleProfileFile.empty())
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+ }
// If we are planning to perform ThinLTO later, we don't bloat the code with
// unrolling/vectorization/... now. Just simplify the module as much as we
@@ -839,12 +839,16 @@ PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
+ // Invoke the SamplePGO annotation pass for the second time to annotate on
+ // functions imported from other modules.
+ if (PGOOpt && !PGOOpt->SampleProfileFile.empty())
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+
// During the ThinLTO backend phase we perform early indirect call promotion
// here, before globalopt. Otherwise imported available_externally functions
// look unreferenced and are removed.
MPM.addPass(PGOIndirectCallPromotion(
- true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
- !PGOOpt->ProfileUseFile.empty()));
+ true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
OpenPOWER on IntegriCloud