@@ -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
@@ -572,7 +575,39 @@ bool CallAnalyzer::isKnownNonNullInCallee(Value *V) {
572
575
return false ;
573
576
}
574
577
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
+
575
604
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
+
576
611
// If -inline-threshold is not given, listen to the optsize and minsize
577
612
// attributes when they would decrease the threshold.
578
613
Function *Caller = CS.getCaller ();
@@ -1214,28 +1249,6 @@ bool CallAnalyzer::analyzeCall(CallSite CS) {
1214
1249
if (OnlyOneCallAndLocalLinkage)
1215
1250
Cost += InlineConstants::LastCallToStaticBonus;
1216
1251
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
-
1239
1252
// If this function uses the coldcc calling convention, prefer not to inline
1240
1253
// it.
1241
1254
if (F.getCallingConv () == CallingConv::Cold)
0 commit comments