Skip to content

Commit

Permalink
[CSSPGO] Minor tweak for inline candidate priority tie breaker
Browse files Browse the repository at this point in the history
When prioritize call site to consider for inlining in sample loader, use number of samples as a first tier breaker before using name/guid comparison. This would favor smaller functions when hotness is the same (from the same block). We could try to retrieve accurate function size if this turns out to be more important.

Differential Revision: https://reviews.llvm.org/D99370
  • Loading branch information
WenleiHe committed Mar 26, 2021
1 parent 850fced commit 5f59f40
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions llvm/lib/Transforms/IPO/SampleProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,16 @@ struct CandidateComparer {
if (LHS.CallsiteCount != RHS.CallsiteCount)
return LHS.CallsiteCount < RHS.CallsiteCount;

const FunctionSamples *LCS = LHS.CalleeSamples;
const FunctionSamples *RCS = RHS.CalleeSamples;
assert(LCS && RCS && "Expect non-null FunctionSamples");

// Tie breaker using number of samples try to favor smaller functions first
if (LCS->getBodySamples().size() != RCS->getBodySamples().size())
return LCS->getBodySamples().size() > RCS->getBodySamples().size();

// Tie breaker using GUID so we have stable/deterministic inlining order
assert(LHS.CalleeSamples && RHS.CalleeSamples &&
"Expect non-null FunctionSamples");
return LHS.CalleeSamples->getGUID(LHS.CalleeSamples->getName()) <
RHS.CalleeSamples->getGUID(RHS.CalleeSamples->getName());
return LCS->getGUID(LCS->getName()) < RCS->getGUID(RCS->getName());
}
};

Expand Down

0 comments on commit 5f59f40

Please sign in to comment.