diff --git a/llvm/include/llvm/Transforms/IPO/Inliner.h b/llvm/include/llvm/Transforms/IPO/Inliner.h --- a/llvm/include/llvm/Transforms/IPO/Inliner.h +++ b/llvm/include/llvm/Transforms/IPO/Inliner.h @@ -121,7 +121,7 @@ ModuleInlinerWrapperPass( InlineParams Params = getInlineParams(), bool MandatoryFirst = true, InliningAdvisorMode Mode = InliningAdvisorMode::Default, - unsigned MaxDevirtIterations = 0); + unsigned MaxDevirtIterations = 0, bool skipInline = false); ModuleInlinerWrapperPass(ModuleInlinerWrapperPass &&Arg) = default; PreservedAnalyses run(Module &, ModuleAnalysisManager &); diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -263,6 +263,9 @@ EnablePGOInlineDeferral("enable-npm-pgo-inline-deferral", cl::init(true), cl::Hidden, cl::desc("Enable inline deferral during PGO")); +static cl::opt EnableCGSCCInline("enable-cgscc-inline", cl::init(true), + cl::Hidden, + cl::desc("Enable CGSCC Inlining")); static cl::opt EnableMemProfiler("enable-mem-prof", cl::init(false), cl::Hidden, cl::ZeroOrMore, @@ -974,7 +977,8 @@ IP.EnableDeferral = EnablePGOInlineDeferral; ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst, - UseInlineAdvisor, MaxDevirtIterations); + UseInlineAdvisor, MaxDevirtIterations, + !EnableCGSCCInline); // Require the GlobalsAA analysis for the module so we can query it within // the CGSCC pipeline. @@ -1772,7 +1776,9 @@ // valuable as the inliner doesn't currently care whether it is inlining an // invoke or a call. // Run the inliner now. - MPM.addPass(ModuleInlinerWrapperPass(getInlineParamsFromOptLevel(Level))); + MPM.addPass(ModuleInlinerWrapperPass(getInlineParamsFromOptLevel(Level), true, + InliningAdvisorMode::Default, 0, + !EnableCGSCCInline)); // Optimize globals again after we ran the inliner. MPM.addPass(GlobalOptPass()); diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -1105,7 +1105,8 @@ ModuleInlinerWrapperPass::ModuleInlinerWrapperPass(InlineParams Params, bool MandatoryFirst, InliningAdvisorMode Mode, - unsigned MaxDevirtIterations) + unsigned MaxDevirtIterations, + bool skipInline) : Params(Params), Mode(Mode), MaxDevirtIterations(MaxDevirtIterations), PM(), MPM() { // Run the inliner first. The theory is that we are walking bottom-up and so @@ -1115,7 +1116,8 @@ // because it makes profile annotation in the backend inaccurate. if (MandatoryFirst) PM.addPass(InlinerPass(/*OnlyMandatory*/ true)); - PM.addPass(InlinerPass()); + if (!skipInline) + PM.addPass(InlinerPass()); } PreservedAnalyses ModuleInlinerWrapperPass::run(Module &M, diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -208,6 +208,10 @@ cl::desc("Use call site prioritized inlining for sample profile loader." "Currently only CSSPGO is supported.")); +static cl::opt EnableSampleProfileInline( + "enable-sample-profile-inline", cl::Hidden, cl::init(true), + cl::desc("Enable Inlining from sample profile loader.")); + static cl::opt ProfileInlineReplayFile( "sample-profile-inline-replay", cl::init(""), cl::value_desc("filename"), cl::desc( @@ -1156,6 +1160,12 @@ bool SampleProfileLoader::tryInlineCandidate( InlineCandidate &Candidate, SmallVector *InlinedCallSites) { + // Disable only the inlining part of sample profile loader, and still + // perform profile annotation. This can be useful for pre-LTO pipeline + // tuning. Note that to preserve context profile from previous inline, + // ProfileMergeInlinee and ProfileTopDownLoad will also be needed. + if (!EnableSampleProfileInline) + return false; CallBase &CB = *Candidate.CallInstr; Function *CalledFunction = CB.getCalledFunction(); @@ -1304,6 +1314,16 @@ "ProfAccForSymsInList should be false when profile-sample-accurate " "is enabled"); + // Disable only the inlining part of sample profile loader, and still + // perform profile annotation. This can be useful for pre-LTO pipeline + // tuning. Note that to preserve context profile from previous inline, + // ProfileMergeInlinee and ProfileTopDownLoad will also be needed. + // For ThinLTO PreLink, we needed to collect InlinedGUIDs, so don't + // bail out just yet. + if (!EnableSampleProfileInline && + !(LTOPhase == ThinOrFullLTOPhase::ThinLTOPreLink)) + return false; + // Populating worklist with initial call sites from root inliner, along // with call site weights. CandidateQueue CQueue;