// At O0 and O1 we only run the always inliner which is more efficient. At // higher optimization levels we run the normal inliner. if (CodeGenOpts.OptimizationLevel <= 1) { bool InsertLifetimeIntrinsics = (CodeGenOpts.OptimizationLevel != 0 && !CodeGenOpts.DisableLifetimeMarkers); PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics); } else { // We do not want to inline hot callsites for SamplePGO module-summary build // because profile annotation will happen again in ThinLTO backend, and we // want the IR of the hot path to match the profile. PMBuilder.Inliner = createFunctionInliningPass( CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize, (!CodeGenOpts.SampleProfileFile.empty() && CodeGenOpts.EmitSummaryIndex)); }
// If all optimizations are disabled, just run the always-inline pass and, // if enabled, the function merging pass. if (OptLevel == 0) { addPGOInstrPasses(MPM); if (Inliner) { MPM.add(Inliner); Inliner = nullptr; }
// FIXME: The BarrierNoopPass is a HACK! The inliner pass above implicitly // creates a CGSCC pass manager, but we don't want to add extensions into // that pass manager. To prevent this we insert a no-op module pass to reset // the pass manager to get the same behavior as EP_OptimizerLast in non-O0 // builds. The function merging pass is if (MergeFunctions) MPM.add(createMergeFunctionsPass()); elseif (GlobalExtensionsNotEmpty() || !Extensions.empty()) MPM.add(createBarrierNoopPass());
addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
// Rename anon globals to be able to export them in the summary. // This has to be done after we add the extensions to the pass manager // as there could be passes (e.g. Adddress sanitizer) which introduce // new unnamed globals. if (PrepareForThinLTO) MPM.add(createNameAnonGlobalPass());
voidPassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy, legacy::PassManagerBase &PM)const{ if (GlobalExtensionsNotEmpty()) { for (auto &Ext : *GlobalExtensions) { if (Ext.first == ETy) Ext.second(*this, PM); } } for (unsigned i = 0, e = Extensions.size(); i != e; ++i) if (Extensions[i].first == ETy) Extensions[i].second(*this, PM); }