Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 8a0abe7

Browse files
author
Easwaran Raman
committed
Refactor Threshold computation. NFC.
This is part of changes reviewed in http://reviews.llvm.org/D17584. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265852 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1a7750e commit 8a0abe7

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

lib/Analysis/InlineCost.cpp

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
154154
/// analysis.
155155
void updateThreshold(CallSite CS, Function &Callee);
156156

157+
/// Return true if size growth is allowed when inlining the callee at CS.
158+
bool allowSizeGrowth(CallSite CS);
159+
157160
// Custom analysis routines.
158161
bool analyzeBlock(BasicBlock *BB, SmallPtrSetImpl<const Value *> &EphValues);
159162

@@ -572,7 +575,39 @@ bool CallAnalyzer::isKnownNonNullInCallee(Value *V) {
572575
return false;
573576
}
574577

578+
bool CallAnalyzer::allowSizeGrowth(CallSite CS) {
579+
// If the normal destination of the invoke or the parent block of the call
580+
// site is unreachable-terminated, there is little point in inlining this
581+
// unless there is literally zero cost.
582+
// FIXME: Note that it is possible that an unreachable-terminated block has a
583+
// hot entry. For example, in below scenario inlining hot_call_X() may be
584+
// beneficial :
585+
// main() {
586+
// hot_call_1();
587+
// ...
588+
// hot_call_N()
589+
// exit(0);
590+
// }
591+
// For now, we are not handling this corner case here as it is rare in real
592+
// code. In future, we should elaborate this based on BPI and BFI in more
593+
// general threshold adjusting heuristics in updateThreshold().
594+
Instruction *Instr = CS.getInstruction();
595+
if (InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
596+
if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
597+
return false;
598+
} else if (isa<UnreachableInst>(Instr->getParent()->getTerminator()))
599+
return false;
600+
601+
return true;
602+
}
603+
575604
void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) {
605+
// If no size growth is allowed for this inlining, set Threshold to 0.
606+
if (!allowSizeGrowth(CS)) {
607+
Threshold = 0;
608+
return;
609+
}
610+
576611
// If -inline-threshold is not given, listen to the optsize and minsize
577612
// attributes when they would decrease the threshold.
578613
Function *Caller = CS.getCaller();
@@ -1214,28 +1249,6 @@ bool CallAnalyzer::analyzeCall(CallSite CS) {
12141249
if (OnlyOneCallAndLocalLinkage)
12151250
Cost += InlineConstants::LastCallToStaticBonus;
12161251

1217-
// If the normal destination of the invoke or the parent block of the call
1218-
// site is unreachable-terminated, there is little point in inlining this
1219-
// unless there is literally zero cost.
1220-
// FIXME: Note that it is possible that an unreachable-terminated block has a
1221-
// hot entry. For example, in below scenario inlining hot_call_X() may be
1222-
// beneficial :
1223-
// main() {
1224-
// hot_call_1();
1225-
// ...
1226-
// hot_call_N()
1227-
// exit(0);
1228-
// }
1229-
// For now, we are not handling this corner case here as it is rare in real
1230-
// code. In future, we should elaborate this based on BPI and BFI in more
1231-
// general threshold adjusting heuristics in updateThreshold().
1232-
Instruction *Instr = CS.getInstruction();
1233-
if (InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
1234-
if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
1235-
Threshold = 0;
1236-
} else if (isa<UnreachableInst>(Instr->getParent()->getTerminator()))
1237-
Threshold = 0;
1238-
12391252
// If this function uses the coldcc calling convention, prefer not to inline
12401253
// it.
12411254
if (F.getCallingConv() == CallingConv::Cold)

0 commit comments

Comments
 (0)