summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2019-07-03 04:01:51 +0000
committerJordan Rupprecht <rupprecht@google.com>2019-07-03 04:01:51 +0000
commit02647f73d4a37274f3306e71e2c0dd2f268d0b85 (patch)
tree369ec480f7c21f1cc2b7bc6981141064ed22eba2 /llvm/lib/Analysis/InlineCost.cpp
parentd5bea6e0c1a43b19e01be4d95d99d066d2848cc2 (diff)
downloadbcm5719-llvm-02647f73d4a37274f3306e71e2c0dd2f268d0b85.tar.gz
bcm5719-llvm-02647f73d4a37274f3306e71e2c0dd2f268d0b85.zip
Revert [InlineCost] cleanup calculations of Cost and Threshold
This reverts r364422 (git commit 1a3dc761860d620ac8ed7e32a4285952142f780b) The inlining cost calculation is incorrect, leading to stack overflow due to large stack frames from heavy inlining. llvm-svn: 365000
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index b7b58d8aca3..3cb56f8cccf 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -897,15 +897,7 @@ void CallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
// and the callsite.
int SingleBBBonusPercent = 50;
int VectorBonusPercent = 150;
-
- 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;
+ int LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus;
// Lambda to set all the above bonus and bonus percentages to 0.
auto DisallowAllBonuses = [&]() {
@@ -978,13 +970,20 @@ void CallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
}
}
- // Take the target-specific inlining threshold multiplier into account.
+ // Finally, take the target-specific inlining threshold multiplier into
+ // account.
Threshold *= TTI.getInliningThresholdMultiplier();
SingleBBBonus = Threshold * SingleBBBonusPercent / 100;
VectorBonus = Threshold * VectorBonusPercent / 100;
- Threshold += LastCallToStaticBonus;
+ 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;
}
bool CallAnalyzer::visitCmpInst(CmpInst &I) {
@@ -1331,10 +1330,9 @@ 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! 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());
+ // 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());
}
if (!F->onlyReadsMemory())
OpenPOWER on IntegriCloud