Skip to content

Commit 5f59f40

Browse files
committed
[CSSPGO] Minor tweak for inline candidate priority tie breaker
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
1 parent 850fced commit 5f59f40

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,16 @@ struct CandidateComparer {
321321
if (LHS.CallsiteCount != RHS.CallsiteCount)
322322
return LHS.CallsiteCount < RHS.CallsiteCount;
323323

324+
const FunctionSamples *LCS = LHS.CalleeSamples;
325+
const FunctionSamples *RCS = RHS.CalleeSamples;
326+
assert(LCS && RCS && "Expect non-null FunctionSamples");
327+
328+
// Tie breaker using number of samples try to favor smaller functions first
329+
if (LCS->getBodySamples().size() != RCS->getBodySamples().size())
330+
return LCS->getBodySamples().size() > RCS->getBodySamples().size();
331+
324332
// Tie breaker using GUID so we have stable/deterministic inlining order
325-
assert(LHS.CalleeSamples && RHS.CalleeSamples &&
326-
"Expect non-null FunctionSamples");
327-
return LHS.CalleeSamples->getGUID(LHS.CalleeSamples->getName()) <
328-
RHS.CalleeSamples->getGUID(RHS.CalleeSamples->getName());
333+
return LCS->getGUID(LCS->getName()) < RCS->getGUID(RCS->getName());
329334
}
330335
};
331336

0 commit comments

Comments
 (0)