[prev in list] [next in list] [prev in thread] [next in thread]
List: llvm-commits
Subject: [PATCH] D79138: [Inlining] Teach shouldBeDeferred to take the total cost into account
From: Kazu Hirata via Phabricator via llvm-commits <llvm-commits () lists ! llvm ! org>
Date: 2020-04-30 23:39:55
Message-ID: 1a52bb2e059f2d501529170ffedde830 () localhost ! localdomain
[Download RAW message or body]
kazu updated this revision to Diff 261386.
kazu added a comment.
I've renamed SecondaryUsers to NumCallerUsers.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79138/new/
https://reviews.llvm.org/D79138
Files:
llvm/lib/Transforms/IPO/Inliner.cpp
Index: llvm/lib/Transforms/IPO/Inliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Inliner.cpp
+++ llvm/lib/Transforms/IPO/Inliner.cpp
@@ -93,6 +93,11 @@
DisableInlinedAllocaMerging("disable-inlined-alloca-merging",
cl::init(false), cl::Hidden);
+static cl::opt<int>
+ InlineDeferralScale("inline-deferral-scale",
+ cl::desc("Scale to limit the cost of inline deferral"),
+ cl::init(2), cl::Hidden);
+
namespace {
enum class InlinerFunctionImportStatsOpts {
@@ -338,12 +343,8 @@
bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();
// This bool tracks what happens if we DO inline C into B.
bool InliningPreventsSomeOuterInline = false;
+ unsigned NumCallerUsers = 0;
for (User *U : Caller->users()) {
- // If the caller will not be removed (either because it does not have a
- // local linkage or because the LastCallToStaticBonus has been already
- // applied), then we can exit the loop early.
- if (!ApplyLastCallBonus && TotalSecondaryCost >= IC.getCost())
- return false;
CallBase *CS2 = dyn_cast<CallBase>(U);
// If this isn't a call to Caller (it could be some other sort
@@ -369,8 +370,13 @@
if (IC2.getCostDelta() <= CandidateCost) {
InliningPreventsSomeOuterInline = true;
TotalSecondaryCost += IC2.getCost();
+ NumCallerUsers++;
}
}
+
+ if (!InliningPreventsSomeOuterInline)
+ return false;
+
// If all outer calls to Caller would get inlined, the cost for the last
// one is set very low by getInlineCost, in anticipation that Caller will
// be removed entirely. We did not account for this above unless there
@@ -378,7 +384,9 @@
if (ApplyLastCallBonus)
TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
- return InliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost();
+ int TotalCost = TotalSecondaryCost + IC.getCost() * NumCallerUsers;
+ int Allowance = IC.getCost() * InlineDeferralScale;
+ return TotalCost < Allowance;
}
static std::basic_ostream<char> &operator<<(std::basic_ostream<char> &R,
["D79138.261386.patch" (text/x-patch)]
Index: llvm/lib/Transforms/IPO/Inliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Inliner.cpp
+++ llvm/lib/Transforms/IPO/Inliner.cpp
@@ -93,6 +93,11 @@
DisableInlinedAllocaMerging("disable-inlined-alloca-merging",
cl::init(false), cl::Hidden);
+static cl::opt<int>
+ InlineDeferralScale("inline-deferral-scale",
+ cl::desc("Scale to limit the cost of inline deferral"),
+ cl::init(2), cl::Hidden);
+
namespace {
enum class InlinerFunctionImportStatsOpts {
@@ -338,12 +343,8 @@
bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();
// This bool tracks what happens if we DO inline C into B.
bool InliningPreventsSomeOuterInline = false;
+ unsigned NumCallerUsers = 0;
for (User *U : Caller->users()) {
- // If the caller will not be removed (either because it does not have a
- // local linkage or because the LastCallToStaticBonus has been already
- // applied), then we can exit the loop early.
- if (!ApplyLastCallBonus && TotalSecondaryCost >= IC.getCost())
- return false;
CallBase *CS2 = dyn_cast<CallBase>(U);
// If this isn't a call to Caller (it could be some other sort
@@ -369,8 +370,13 @@
if (IC2.getCostDelta() <= CandidateCost) {
InliningPreventsSomeOuterInline = true;
TotalSecondaryCost += IC2.getCost();
+ NumCallerUsers++;
}
}
+
+ if (!InliningPreventsSomeOuterInline)
+ return false;
+
// If all outer calls to Caller would get inlined, the cost for the last
// one is set very low by getInlineCost, in anticipation that Caller will
// be removed entirely. We did not account for this above unless there
@@ -378,7 +384,9 @@
if (ApplyLastCallBonus)
TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
- return InliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost();
+ int TotalCost = TotalSecondaryCost + IC.getCost() * NumCallerUsers;
+ int Allowance = IC.getCost() * InlineDeferralScale;
+ return TotalCost < Allowance;
}
static std::basic_ostream<char> &operator<<(std::basic_ostream<char> &R,
[Attachment #4 (text/plain)]
_______________________________________________
llvm-commits mailing list
llvm-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic