Skip to content

Commit e08b139

Browse files
author
Easwaran Raman
committedJan 9, 2017
Refactor inline threshold update code.
Functional change: Previously, if a callee is cold, we used ColdThreshold if it minimizes the existing threshold. This was irrespective of whether we were optimizing for minsize (-Oz) or not. But -Oz uses very low threshold to begin with and the inlining with -Oz is expected to be tuned for lowering code size, so there is no good reason to set an even lower threshold for cold callees. We now lower the threshold for cold callees only when -Oz is not used. For default values of -inlinethreshold and -inlinecold-threshold, this change has no effect and this simplifies the code. NFC changes: Group all threshold updates that are guarded by !Caller->optForMinSize() and within that group threshold updates that require profile summary info. Differential revision: https://reviews.llvm.org/D28369 llvm-svn: 291487
1 parent 472684e commit e08b139

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed
 

‎llvm/lib/Analysis/InlineCost.cpp

+19-22
Original file line numberDiff line numberDiff line change
@@ -636,30 +636,27 @@ void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) {
636636
else if (Caller->optForSize())
637637
Threshold = MinIfValid(Threshold, Params.OptSizeThreshold);
638638

639-
bool HotCallsite = false;
640-
uint64_t TotalWeight;
641-
if (PSI && CS.getInstruction()->extractProfTotalWeight(TotalWeight) &&
642-
PSI->isHotCount(TotalWeight)) {
643-
HotCallsite = true;
639+
// Adjust the threshold based on inlinehint attribute and profile based
640+
// hotness information if the caller does not have MinSize attribute.
641+
if (!Caller->optForMinSize()) {
642+
if (Callee.hasFnAttribute(Attribute::InlineHint))
643+
Threshold = MaxIfValid(Threshold, Params.HintThreshold);
644+
if (PSI) {
645+
uint64_t TotalWeight;
646+
if (CS.getInstruction()->extractProfTotalWeight(TotalWeight) &&
647+
PSI->isHotCount(TotalWeight)) {
648+
Threshold = MaxIfValid(Threshold, Params.HotCallSiteThreshold);
649+
} else if (PSI->isFunctionEntryHot(&Callee)) {
650+
// If callsite hotness can not be determined, we may still know
651+
// that the callee is hot and treat it as a weaker hint for threshold
652+
// increase.
653+
Threshold = MaxIfValid(Threshold, Params.HintThreshold);
654+
} else if (PSI->isFunctionEntryCold(&Callee)) {
655+
Threshold = MinIfValid(Threshold, Params.ColdThreshold);
656+
}
657+
}
644658
}
645659

646-
// Listen to the inlinehint attribute or profile based hotness information
647-
// when it would increase the threshold and the caller does not need to
648-
// minimize its size.
649-
bool InlineHint = Callee.hasFnAttribute(Attribute::InlineHint) ||
650-
(PSI && PSI->isFunctionEntryHot(&Callee));
651-
if (InlineHint && !Caller->optForMinSize())
652-
Threshold = MaxIfValid(Threshold, Params.HintThreshold);
653-
654-
if (HotCallsite && !Caller->optForMinSize())
655-
Threshold = MaxIfValid(Threshold, Params.HotCallSiteThreshold);
656-
657-
bool ColdCallee = PSI && PSI->isFunctionEntryCold(&Callee);
658-
// For cold callees, use the ColdThreshold knob if it is available and reduces
659-
// the threshold.
660-
if (ColdCallee)
661-
Threshold = MinIfValid(Threshold, Params.ColdThreshold);
662-
663660
// Finally, take the target-specific inlining threshold multiplier into
664661
// account.
665662
Threshold *= TTI.getInliningThresholdMultiplier();

0 commit comments

Comments
 (0)
Please sign in to comment.