@@ -154,6 +154,9 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
154
154
// / analysis.
155
155
void updateThreshold (CallSite CS, Function &Callee);
156
156
157
+ // / Return true if size growth is allowed when inlining the callee at CS.
158
+ bool allowSizeGrowth (CallSite CS);
159
+
157
160
// Custom analysis routines.
158
161
bool analyzeBlock (BasicBlock *BB, SmallPtrSetImpl<const Value *> &EphValues);
159
162
@@ -573,7 +576,39 @@ bool CallAnalyzer::isKnownNonNullInCallee(Value *V) {
573
576
return false ;
574
577
}
575
578
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
+
576
605
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
+
577
612
// If -inline-threshold is not given, listen to the optsize and minsize
578
613
// attributes when they would decrease the threshold.
579
614
Function *Caller = CS.getCaller ();
@@ -1215,28 +1250,6 @@ bool CallAnalyzer::analyzeCall(CallSite CS) {
1215
1250
if (OnlyOneCallAndLocalLinkage)
1216
1251
Cost += InlineConstants::LastCallToStaticBonus;
1217
1252
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
-
1240
1253
// If this function uses the coldcc calling convention, prefer not to inline
1241
1254
// it.
1242
1255
if (F.getCallingConv () == CallingConv::Cold)
0 commit comments