Changeset View
Standalone View
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Show First 20 Lines • Show All 492 Lines • ▼ Show 20 Lines | void PassManagerBuilder::populateModulePassManager( | ||||
// the ThinLTO backend when PerformThinLTO=true, when we promote imported | // the ThinLTO backend when PerformThinLTO=true, when we promote imported | ||||
// inter-module indirect calls. For that we perform indirect call promotion | // inter-module indirect calls. For that we perform indirect call promotion | ||||
// earlier in the pass pipeline, here before globalopt. Otherwise imported | // earlier in the pass pipeline, here before globalopt. Otherwise imported | ||||
// available_externally functions look unreferenced and are removed. | // available_externally functions look unreferenced and are removed. | ||||
if (PerformThinLTO) | if (PerformThinLTO) | ||||
MPM.add(createPGOIndirectCallPromotionLegacyPass(/*InLTO = */ true, | MPM.add(createPGOIndirectCallPromotionLegacyPass(/*InLTO = */ true, | ||||
!PGOSampleUse.empty())); | !PGOSampleUse.empty())); | ||||
// For SamplePGO in ThinLTO compile phase, we do not want to unroll loops | // For SamplePGO in the *LTO compile phase, we do not want to unroll loops | ||||
// as it will change the CFG too much to make the 2nd profile annotation | // as it will change the CFG too much to make the 2nd profile annotation | ||||
// in backend more difficult. | // in backend more difficult. | ||||
bool PrepareForThinLTOUsingPGOSampleProfile = | bool PrepareForLTOUsingPGOSampleProfile = | ||||
PrepareForThinLTO && !PGOSampleUse.empty(); | (PrepareForThinLTO || PrepareForLTO) && !PGOSampleUse.empty(); | ||||
if (PrepareForThinLTOUsingPGOSampleProfile) | if (PrepareForLTOUsingPGOSampleProfile) | ||||
DisableUnrollLoops = true; | DisableUnrollLoops = true; | ||||
// Infer attributes about declarations if possible. | // Infer attributes about declarations if possible. | ||||
MPM.add(createInferFunctionAttrsLegacyPass()); | MPM.add(createInferFunctionAttrsLegacyPass()); | ||||
addExtensionsToPM(EP_ModuleOptimizerEarly, MPM); | addExtensionsToPM(EP_ModuleOptimizerEarly, MPM); | ||||
if (OptLevel > 2) | if (OptLevel > 2) | ||||
Show All 10 Lines | void PassManagerBuilder::populateModulePassManager( | ||||
MPM.add(createPromoteMemoryToRegisterPass()); | MPM.add(createPromoteMemoryToRegisterPass()); | ||||
MPM.add(createDeadArgEliminationPass()); // Dead argument elimination | MPM.add(createDeadArgEliminationPass()); // Dead argument elimination | ||||
addInstructionCombiningPass(MPM); // Clean up after IPCP & DAE | addInstructionCombiningPass(MPM); // Clean up after IPCP & DAE | ||||
addExtensionsToPM(EP_Peephole, MPM); | addExtensionsToPM(EP_Peephole, MPM); | ||||
MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE | MPM.add(createCFGSimplificationPass()); // Clean up after IPCP & DAE | ||||
// For SamplePGO in ThinLTO compile phase, we do not want to do indirect | // For SamplePGO in the *LTO compile phase, we do not want to do indirect | ||||
// call promotion as it will change the CFG too much to make the 2nd | // call promotion as it will change the CFG too much to make the 2nd | ||||
// profile annotation in backend more difficult. | // profile annotation in backend more difficult. | ||||
// PGO instrumentation is added during the compile phase for ThinLTO, do | // PGO instrumentation is added during the compile phase for *LTO, do | ||||
// not run it a second time | // not run it a second time | ||||
if (DefaultOrPreLinkPipeline && !PrepareForThinLTOUsingPGOSampleProfile) | if (DefaultOrPreLinkPipeline && !PrepareForLTOUsingPGOSampleProfile) | ||||
addPGOInstrPasses(MPM); | addPGOInstrPasses(MPM); | ||||
// Create profile COMDAT variables. Lld linker wants to see all variables | // Create profile COMDAT variables. Lld linker wants to see all variables | ||||
// before the LTO/ThinLTO link since it needs to resolve symbols/comdats. | // before the LTO/ThinLTO link since it needs to resolve symbols/comdats. | ||||
if (!PerformThinLTO && EnablePGOCSInstrGen) | if (!PerformThinLTO && EnablePGOCSInstrGen) | ||||
MPM.add(createPGOInstrumentationGenCreateVarLegacyPass(PGOInstrGen)); | MPM.add(createPGOInstrumentationGenCreateVarLegacyPass(PGOInstrGen)); | ||||
// We add a module alias analysis pass here. In part due to bugs in the | // We add a module alias analysis pass here. In part due to bugs in the | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | void PassManagerBuilder::populateModulePassManager( | ||||
if (RunInliner) { | if (RunInliner) { | ||||
MPM.add(createGlobalOptimizerPass()); | MPM.add(createGlobalOptimizerPass()); | ||||
MPM.add(createGlobalDCEPass()); | MPM.add(createGlobalDCEPass()); | ||||
} | } | ||||
// If we are planning to perform ThinLTO later, let's not bloat the code with | // If we are planning to perform ThinLTO later, let's not bloat the code with | ||||
// unrolling/vectorization/... now. We'll first run the inliner + CGSCC passes | // unrolling/vectorization/... now. We'll first run the inliner + CGSCC passes | ||||
// during ThinLTO and perform the rest of the optimizations afterward. | // during ThinLTO and perform the rest of the optimizations afterward. | ||||
if (PrepareForThinLTO) { | if (PrepareForThinLTO) { | ||||
wenlei: this also need to be `PrepareForThinLTO || PrepareForLTO` for oldPM? | |||||
wristowUnsubmitted Not Done ReplyInline ActionsI agree this is another instance where a balancing act question applies. In this case, assuming the comment about the concern of code bloat is accurate, it's not so much about compile-time resources in the full LTO back-end, but rather about minimizing the ThinLTO bitcode write/read time. So if as this WIP evolves, it ultimately is a win for SamplePGO to suppress some loop optimizations (unrolling/vectorization) here, then that will probably also be a small win in full LTO compile time. That said, in addition to these loop-related optimizations, there are other transformations here that are done in the full LTO pipeline (but not in the ThinLTO pipeline). So I suspect if some change to check for PrepareForThinLTO || PrepareForLTO (rather than only PrepareForThinLTO) makes sense here from a Sample PGO perspective, then the change will be more complicated than simply adding the small set of passes here followed by the early return (that is, I think there are probably things after the return on line 621 that still ought to be enabled for full LTO -- essentially continuing to do them in the pre-link stage for full LTO, to try to avoid needing to do too much work in the full LTO backend stage, since it's more of a problem for the full backend to absorb that compile time cost). wristow: I agree this is another instance where a balancing act question applies. In this case… | |||||
tejohnsonAuthorUnsubmitted This early return was not for Sample PGO btw. It was added much earlier with the thought that a) these types of optimizations might affect function importing heuristics because they could bloat the code; b) we can push more optimizations to the post-link in ThinLTO because it is parallel; and c) there isn't otherwise a benefit to doing these optimizations in the pre vs post link, i.e. they aren't cleanup/simplification passes. The equation is of course different for full LTO which has a monolithic serial post link backend. But I believe this early return is the one @ormris is looking to remove on the ThinLTO pass to "merge" the two pipelines, which needs a good amount of evaluation on the ThinLTO performance side. tejohnson: This early return was not for Sample PGO btw. It was added much earlier with the thought that… | |||||
// Ensure we perform any last passes, but do so before renaming anonymous | // Ensure we perform any last passes, but do so before renaming anonymous | ||||
// globals in case the passes add any. | // globals in case the passes add any. | ||||
addExtensionsToPM(EP_OptimizerLast, MPM); | addExtensionsToPM(EP_OptimizerLast, MPM); | ||||
MPM.add(createCanonicalizeAliasesPass()); | MPM.add(createCanonicalizeAliasesPass()); | ||||
// Rename anon globals to be able to export them in the summary. | // Rename anon globals to be able to export them in the summary. | ||||
MPM.add(createNameAnonGlobalPass()); | MPM.add(createNameAnonGlobalPass()); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 514 Lines • Show Last 20 Lines |
this also need to be PrepareForThinLTO || PrepareForLTO for oldPM?