summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorEaswaran Raman <eraman@google.com>2016-04-08 21:28:02 +0000
committerEaswaran Raman <eraman@google.com>2016-04-08 21:28:02 +0000
commit9a3fc17ad47bf23e5b65e42f7600d91791d2c82e (patch)
treee8e856727b5b11a43b26259ca9a6d32c042b275c /llvm/lib/Analysis/InlineCost.cpp
parent0012756489bd46c1a5c3ff89ce281c14e88bee1f (diff)
downloadbcm5719-llvm-9a3fc17ad47bf23e5b65e42f7600d91791d2c82e.tar.gz
bcm5719-llvm-9a3fc17ad47bf23e5b65e42f7600d91791d2c82e.zip
Refactor Threshold computation. NFC.
This is part of changes reviewed in http://reviews.llvm.org/D17584. llvm-svn: 265852
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp57
1 files changed, 35 insertions, 22 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index ceab8331a11..e29c09e7cab 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -154,6 +154,9 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
/// analysis.
void updateThreshold(CallSite CS, Function &Callee);
+ /// Return true if size growth is allowed when inlining the callee at CS.
+ bool allowSizeGrowth(CallSite CS);
+
// Custom analysis routines.
bool analyzeBlock(BasicBlock *BB, SmallPtrSetImpl<const Value *> &EphValues);
@@ -572,7 +575,39 @@ bool CallAnalyzer::isKnownNonNullInCallee(Value *V) {
return false;
}
+bool CallAnalyzer::allowSizeGrowth(CallSite CS) {
+ // If the normal destination of the invoke or the parent block of the call
+ // site is unreachable-terminated, there is little point in inlining this
+ // unless there is literally zero cost.
+ // FIXME: Note that it is possible that an unreachable-terminated block has a
+ // hot entry. For example, in below scenario inlining hot_call_X() may be
+ // beneficial :
+ // main() {
+ // hot_call_1();
+ // ...
+ // hot_call_N()
+ // exit(0);
+ // }
+ // For now, we are not handling this corner case here as it is rare in real
+ // code. In future, we should elaborate this based on BPI and BFI in more
+ // general threshold adjusting heuristics in updateThreshold().
+ Instruction *Instr = CS.getInstruction();
+ if (InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
+ if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
+ return false;
+ } else if (isa<UnreachableInst>(Instr->getParent()->getTerminator()))
+ return false;
+
+ return true;
+}
+
void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) {
+ // If no size growth is allowed for this inlining, set Threshold to 0.
+ if (!allowSizeGrowth(CS)) {
+ Threshold = 0;
+ return;
+ }
+
// If -inline-threshold is not given, listen to the optsize and minsize
// attributes when they would decrease the threshold.
Function *Caller = CS.getCaller();
@@ -1214,28 +1249,6 @@ bool CallAnalyzer::analyzeCall(CallSite CS) {
if (OnlyOneCallAndLocalLinkage)
Cost += InlineConstants::LastCallToStaticBonus;
- // If the normal destination of the invoke or the parent block of the call
- // site is unreachable-terminated, there is little point in inlining this
- // unless there is literally zero cost.
- // FIXME: Note that it is possible that an unreachable-terminated block has a
- // hot entry. For example, in below scenario inlining hot_call_X() may be
- // beneficial :
- // main() {
- // hot_call_1();
- // ...
- // hot_call_N()
- // exit(0);
- // }
- // For now, we are not handling this corner case here as it is rare in real
- // code. In future, we should elaborate this based on BPI and BFI in more
- // general threshold adjusting heuristics in updateThreshold().
- Instruction *Instr = CS.getInstruction();
- if (InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
- if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
- Threshold = 0;
- } else if (isa<UnreachableInst>(Instr->getParent()->getTerminator()))
- Threshold = 0;
-
// If this function uses the coldcc calling convention, prefer not to inline
// it.
if (F.getCallingConv() == CallingConv::Cold)
OpenPOWER on IntegriCloud