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 @@ -183,6 +183,11 @@ cl::desc("Inline cold call sites in profile loader if it's beneficial " "for code size.")); +static cl::opt ProfileInlineFunctions( + "sample-profile-inline-functions", cl::Hidden, cl::init(true), + cl::desc("If false, inliner is turned off in profile loader. Used for " + "debugging or evaluation.")); + cl::opt ProfileInlineGrowthLimit( "sample-profile-inline-growth-limit", cl::Hidden, cl::init(12), cl::desc("The size growth ratio limit for proirity-based sample profile " @@ -295,8 +300,6 @@ "overwrite-existing-weights", cl::Hidden, cl::init(false), cl::desc("Ignore existing branch weights on IR and always overwrite.")); -extern cl::opt EnableExtTspBlockPlacement; - namespace { using BlockWeightMap = DenseMap; @@ -1113,6 +1116,8 @@ /// \returns True if there is any inline happened. bool SampleProfileLoader::inlineHotFunctions( Function &F, DenseSet &InlinedGUIDs) { + if (!ProfileInlineFunctions) + return; // ProfAccForSymsInList is used in callsiteIsHot. The assertion makes sure // Profile symbol list is ignored when profile-sample-accurate is on. assert((!ProfAccForSymsInList || @@ -1228,45 +1233,45 @@ InlineFunctionInfo IFI(nullptr, GetAC); IFI.UpdateProfile = false; - if (!InlineFunction(CB, IFI).isSuccess()) - return false; - - // Merge the attributes based on the inlining. - AttributeFuncs::mergeAttributesForInlining(*BB->getParent(), - *CalledFunction); - - // The call to InlineFunction erases I, so we can't pass it here. - emitInlinedIntoBasedOnCost(*ORE, DLoc, BB, *CalledFunction, - *BB->getParent(), Cost, true, CSINLINE_DEBUG); - - // Now populate the list of newly exposed call sites. - if (InlinedCallSites) { - InlinedCallSites->clear(); - for (auto &I : IFI.InlinedCallSites) - InlinedCallSites->push_back(I); - } + if (InlineFunction(CB, IFI).isSuccess()) { + // Merge the attributes based on the inlining. + AttributeFuncs::mergeAttributesForInlining(*BB->getParent(), + *CalledFunction); + + // The call to InlineFunction erases I, so we can't pass it here. + emitInlinedIntoBasedOnCost(*ORE, DLoc, BB, *CalledFunction, + *BB->getParent(), Cost, true, CSINLINE_DEBUG); + + // Now populate the list of newly exposed call sites. + if (InlinedCallSites) { + InlinedCallSites->clear(); + for (auto &I : IFI.InlinedCallSites) + InlinedCallSites->push_back(I); + } - if (ProfileIsCSFlat) - ContextTracker->markContextSamplesInlined(Candidate.CalleeSamples); - ++NumCSInlined; - - // Prorate inlined probes for a duplicated inlining callsite which probably - // has a distribution less than 100%. Samples for an inlinee should be - // distributed among the copies of the original callsite based on each - // callsite's distribution factor for counts accuracy. Note that an inlined - // probe may come with its own distribution factor if it has been duplicated - // in the inlinee body. The two factor are multiplied to reflect the - // aggregation of duplication. - if (Candidate.CallsiteDistribution < 1) { - for (auto &I : IFI.InlinedCallSites) { - if (Optional Probe = extractProbe(*I)) - setProbeDistributionFactor(*I, Probe->Factor * - Candidate.CallsiteDistribution); + if (ProfileIsCSFlat) + ContextTracker->markContextSamplesInlined(Candidate.CalleeSamples); + ++NumCSInlined; + + // Prorate inlined probes for a duplicated inlining callsite which probably + // has a distribution less than 100%. Samples for an inlinee should be + // distributed among the copies of the original callsite based on each + // callsite's distribution factor for counts accuracy. Note that an inlined + // probe may come with its own distribution factor if it has been duplicated + // in the inlinee body. The two factor are multiplied to reflect the + // aggregation of duplication. + if (Candidate.CallsiteDistribution < 1) { + for (auto &I : IFI.InlinedCallSites) { + if (Optional Probe = extractProbe(*I)) + setProbeDistributionFactor(*I, Probe->Factor * + Candidate.CallsiteDistribution); + } + NumDuplicatedInlinesite++; } - NumDuplicatedInlinesite++; - } - return true; + return true; + } + return false; } bool SampleProfileLoader::getInlineCandidate(InlineCandidate *NewCandidate, @@ -1542,10 +1547,6 @@ continue; } - // Do not merge a context that is already duplicated into the base profile. - if (FS->getContext().hasAttribute(sampleprof::ContextDuplicatedIntoBase)) - continue; - if (ProfileMergeInlinee) { // A function call can be replicated by optimizations like callsite // splitting or jump threading and the replicates end up sharing the @@ -2006,10 +2007,6 @@ if (!SampleProfileUseProfi.getNumOccurrences()) SampleProfileUseProfi = true; - // Enable EXT-TSP block layout for CSSPGO. - if (!EnableExtTspBlockPlacement.getNumOccurrences()) - EnableExtTspBlockPlacement = true; - if (FunctionSamples::ProfileIsCSFlat) { // Tracker for profiles under different context ContextTracker = std::make_unique( @@ -2208,4 +2205,4 @@ return PreservedAnalyses::all(); return PreservedAnalyses::none(); -} +} \ No newline at end of file