Skip to content

Commit

Permalink
[SamplePGO] Skip inlinee profile scaling for sample loader inlining
Browse files Browse the repository at this point in the history
For CGSCC inline, we need to scale down a function's branch weights and entry counts when thee it's inlined at a callsite. This is done through updateCallProfile. Additionally, we also scale the weigths for the inlined clone based on call site count in updateCallerBFI. Neither is needed for inlining during sample profile loader as it's using context profile that is separated from inlinee's own profile. This change skip the inlinee profile scaling for sample loader inlining.

Differential Revision: https://reviews.llvm.org/D98187
  • Loading branch information
WenleiHe committed Mar 11, 2021
1 parent 8d8a919 commit 051f2c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 7 additions & 2 deletions llvm/include/llvm/Transforms/Utils/Cloning.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ class InlineFunctionInfo {
function_ref<AssumptionCache &(Function &)> GetAssumptionCache = nullptr,
ProfileSummaryInfo *PSI = nullptr,
BlockFrequencyInfo *CallerBFI = nullptr,
BlockFrequencyInfo *CalleeBFI = nullptr)
BlockFrequencyInfo *CalleeBFI = nullptr, bool UpdateProfile = true)
: CG(cg), GetAssumptionCache(GetAssumptionCache), PSI(PSI),
CallerBFI(CallerBFI), CalleeBFI(CalleeBFI) {}
CallerBFI(CallerBFI), CalleeBFI(CalleeBFI),
UpdateProfile(UpdateProfile) {}

/// If non-null, InlineFunction will update the callgraph to reflect the
/// changes it makes.
Expand All @@ -223,6 +224,10 @@ class InlineFunctionInfo {
/// `InlinedCalls` above is used.
SmallVector<CallBase *, 8> InlinedCallSites;

/// Update profile for callee as well as cloned version. We need to do this
/// for regular inlining, but not for inlining from sample profile loader.
bool UpdateProfile;

void reset() {
StaticAllocas.clear();
InlinedCalls.clear();
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/IPO/SampleProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ bool SampleProfileLoader::tryInlineCandidate(
return false;

InlineFunctionInfo IFI(nullptr, GetAC);
IFI.UpdateProfile = false;
if (InlineFunction(CB, IFI).isSuccess()) {
// The call to InlineFunction erases I, so we can't pass it here.
emitInlinedInto(*ORE, DLoc, BB, *CalledFunction, *BB->getParent(), Cost,
Expand Down
20 changes: 13 additions & 7 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1954,13 +1954,19 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
if (objcarc::hasAttachedCallOpBundle(&CB))
inlineRetainOrClaimRVCalls(CB, Returns);

if (IFI.CallerBFI != nullptr && IFI.CalleeBFI != nullptr)
// Update the BFI of blocks cloned into the caller.
updateCallerBFI(OrigBB, VMap, IFI.CallerBFI, IFI.CalleeBFI,
CalledFunc->front());

updateCallProfile(CalledFunc, VMap, CalledFunc->getEntryCount(), CB,
IFI.PSI, IFI.CallerBFI);
// Updated caller/callee profiles only when requested. For sample loader
// inlining, the context-sensitive inlinee profile doesn't need to be
// subtracted from callee profile, and the inlined clone also doesn't need
// to be scaled based on call site count.
if (IFI.UpdateProfile) {
if (IFI.CallerBFI != nullptr && IFI.CalleeBFI != nullptr)
// Update the BFI of blocks cloned into the caller.
updateCallerBFI(OrigBB, VMap, IFI.CallerBFI, IFI.CalleeBFI,
CalledFunc->front());

updateCallProfile(CalledFunc, VMap, CalledFunc->getEntryCount(), CB,
IFI.PSI, IFI.CallerBFI);
}

// Inject byval arguments initialization.
for (std::pair<Value*, Value*> &Init : ByValInit)
Expand Down

0 comments on commit 051f2c1

Please sign in to comment.