[PATCH] D35850: [InlineCost] Add cl::opt to allow full inline cost to be computed for debugging purposes.
Chad Rosier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 25 11:59:20 PDT 2017
mcrosier created this revision.
Currently, the inline cost model will bail once the inline cost exceeds the inline threshold in order to avoid unnecessary compile-time. However, when debugging I found it useful to compute the full cost, so I added this command line option to override the default behavior.
I wanted to see if others thought this might be useful. I also wanted to have someone more familiar with the inline cost model double check to make sure the patch is correct.
Chad
https://reviews.llvm.org/D35850
Files:
lib/Analysis/InlineCost.cpp
Index: lib/Analysis/InlineCost.cpp
===================================================================
--- lib/Analysis/InlineCost.cpp
+++ lib/Analysis/InlineCost.cpp
@@ -72,6 +72,11 @@
"entry frequency, for a callsite to be cold in the absence of "
"profile information."));
+static cl::opt<bool> ComputeFullInlineCost(
+ "inline-cost-full", cl::Hidden, cl::init(false),
+ cl::desc("Compute the full inline cost of a call site even when the cost "
+ "exceeds the threshold."));
+
namespace {
class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
@@ -1225,7 +1230,7 @@
// Check if we've past the maximum possible threshold so we don't spin in
// huge basic blocks that will never inline.
- if (Cost > Threshold)
+ if (Cost > Threshold && !ComputeFullInlineCost)
return false;
}
@@ -1327,7 +1332,7 @@
Cost += InlineConstants::ColdccPenalty;
// Check if we're done. This can happen due to bonuses and penalties.
- if (Cost > Threshold)
+ if (Cost > Threshold && !ComputeFullInlineCost)
return false;
if (F.empty())
@@ -1392,7 +1397,7 @@
for (unsigned Idx = 0; Idx != BBWorklist.size(); ++Idx) {
// Bail out the moment we cross the threshold. This means we'll under-count
// the cost, but only when undercounting doesn't matter.
- if (Cost > Threshold)
+ if (Cost > Threshold && !ComputeFullInlineCost)
break;
BasicBlock *BB = BBWorklist[Idx];
@@ -1558,13 +1563,14 @@
return llvm::InlineCost::getNever();
}
+ Function *Caller = CS.getCaller();
// Never inline functions with conflicting attributes (unless callee has
// always-inline attribute).
- if (!functionsHaveCompatibleAttributes(CS.getCaller(), Callee, CalleeTTI))
+ if (!functionsHaveCompatibleAttributes(Caller, Callee, CalleeTTI))
return llvm::InlineCost::getNever();
// Don't inline this call if the caller has the optnone attribute.
- if (CS.getCaller()->hasFnAttribute(Attribute::OptimizeNone))
+ if (Caller->hasFnAttribute(Attribute::OptimizeNone))
return llvm::InlineCost::getNever();
// Don't inline functions which can be interposed at link-time. Don't inline
@@ -1576,7 +1582,7 @@
return llvm::InlineCost::getNever();
DEBUG(llvm::dbgs() << " Analyzing call of " << Callee->getName()
- << "...\n");
+ << "... (Caller:" << Caller->getName() << ")\n");
CallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, *Callee, CS,
Params);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35850.108131.patch
Type: text/x-patch
Size: 2564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170725/09c13bab/attachment.bin>
More information about the llvm-commits
mailing list