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

Commit f0cf974

Browse files
Easwaran Ramanahatanaka
authored andcommitted
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 (cherry picked from commit 8a0abe7)
1 parent c337eb7 commit f0cf974

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

@@ -573,7 +576,39 @@ bool CallAnalyzer::isKnownNonNullInCallee(Value *V) {
573576
return false;
574577
}
575578

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

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

0 commit comments

Comments
 (0)