aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorFedor Sergeev <fedor.sergeev@azul.com>2019-06-26 13:24:24 +0000
committerFedor Sergeev <fedor.sergeev@azul.com>2019-06-26 13:24:24 +0000
commit1a3dc761860d620ac8ed7e32a4285952142f780b (patch)
treeb290d2280cfc3f4b9be36e7de9fcdc1bfc186134 /llvm/lib/Analysis/InlineCost.cpp
parent09bc66576600d06ce5cbcd55731f04a93adfdcfd (diff)
downloadllvm-1a3dc761860d620ac8ed7e32a4285952142f780b.zip
llvm-1a3dc761860d620ac8ed7e32a4285952142f780b.tar.gz
llvm-1a3dc761860d620ac8ed7e32a4285952142f780b.tar.bz2
[InlineCost] cleanup calculations of Cost and Threshold
Summary: Doing better separation of Cost and Threshold. Cost counts the abstract complexity of live instructions, while Threshold is an upper bound of complexity that inlining is comfortable to pay. There are two parts: - huge 15K last-call-to-static bonus is no longer subtracted from Cost but rather is now added to Threshold. That makes much more sense, as the cost of inlining (Cost) is not changed by the fact that internal function is called once. It only changes the likelyhood of this inlining being profitable (Threshold). - bonus for calls proved-to-be-inlinable into callee is no longer subtracted from Cost but added to Threshold instead. While calculations are somewhat different, overall InlineResult should stay the same since Cost >= Threshold compares the same. Reviewers: eraman, greened, chandlerc, yrouban, apilipenko Reviewed By: apilipenko Tags: #llvm Differential Revision: https://reviews.llvm.org/D60740 llvm-svn: 364422
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 3cb56f8..b7b58d8 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -897,7 +897,15 @@ void CallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
// and the callsite.
int SingleBBBonusPercent = 50;
int VectorBonusPercent = 150;
- int LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus;
+
+ int LastCallToStaticBonus = 0;
+ bool OnlyOneCallAndLocalLinkage =
+ F.hasLocalLinkage() && F.hasOneUse() && &F == Call.getCalledFunction();
+ // If there is only one call of the function, and it has internal linkage,
+ // we can allow to inline pretty anything as it will lead to size reduction
+ // anyway.
+ if (OnlyOneCallAndLocalLinkage)
+ LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus;
// Lambda to set all the above bonus and bonus percentages to 0.
auto DisallowAllBonuses = [&]() {
@@ -970,20 +978,13 @@ void CallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
}
}
- // Finally, take the target-specific inlining threshold multiplier into
- // account.
+ // Take the target-specific inlining threshold multiplier into account.
Threshold *= TTI.getInliningThresholdMultiplier();
SingleBBBonus = Threshold * SingleBBBonusPercent / 100;
VectorBonus = Threshold * VectorBonusPercent / 100;
- bool OnlyOneCallAndLocalLinkage =
- F.hasLocalLinkage() && F.hasOneUse() && &F == Call.getCalledFunction();
- // If there is only one call of the function, and it has internal linkage,
- // the cost of inlining it drops dramatically. It may seem odd to update
- // Cost in updateThreshold, but the bonus depends on the logic in this method.
- if (OnlyOneCallAndLocalLinkage)
- Cost -= LastCallToStaticBonus;
+ Threshold += LastCallToStaticBonus;
}
bool CallAnalyzer::visitCmpInst(CmpInst &I) {
@@ -1330,9 +1331,10 @@ bool CallAnalyzer::visitCallBase(CallBase &Call) {
CallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F, Call,
IndirectCallParams);
if (CA.analyzeCall(Call)) {
- // We were able to inline the indirect call! Subtract the cost from the
- // threshold to get the bonus we want to apply, but don't go below zero.
- Cost -= std::max(0, CA.getThreshold() - CA.getCost());
+ // We were able to inline the indirect call! Increase the threshold
+ // with the bonus we want to apply (less the cost of inlinee).
+ // Make sure the bonus doesn't go below zero.
+ Threshold += std::max(0, CA.getThreshold() - CA.getCost());
}
if (!F->onlyReadsMemory())