@@ -336,8 +336,8 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
336
336
337
337
// / Called at the end of processing a switch instruction, with the given
338
338
// / number of case clusters.
339
- virtual void onFinalizeSwitch (unsigned JumpTableSize,
340
- unsigned NumCaseCluster ) {}
339
+ virtual void onFinalizeSwitch (unsigned JumpTableSize, unsigned NumCaseCluster,
340
+ bool DefaultDestUndefined ) {}
341
341
342
342
// / Called to account for any other instruction not specifically accounted
343
343
// / for.
@@ -699,15 +699,16 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
699
699
CallPenalty));
700
700
}
701
701
702
- void onFinalizeSwitch (unsigned JumpTableSize,
703
- unsigned NumCaseCluster) override {
702
+ void onFinalizeSwitch (unsigned JumpTableSize, unsigned NumCaseCluster,
703
+ bool DefaultDestUndefined) override {
704
+ if (!DefaultDestUndefined)
705
+ addCost (2 * InstrCost);
704
706
// If suitable for a jump table, consider the cost for the table size and
705
707
// branch to destination.
706
708
// Maximum valid cost increased in this function.
707
709
if (JumpTableSize) {
708
710
int64_t JTCost =
709
711
static_cast <int64_t >(JumpTableSize) * InstrCost + 4 * InstrCost;
710
-
711
712
addCost (JTCost);
712
713
return ;
713
714
}
@@ -1153,6 +1154,7 @@ class InlineCostFeaturesAnalyzer final : public CallAnalyzer {
1153
1154
// heuristics in the ML inliner.
1154
1155
static constexpr int JTCostMultiplier = 4 ;
1155
1156
static constexpr int CaseClusterCostMultiplier = 2 ;
1157
+ static constexpr int SwitchDefaultDestCostMultiplier = 2 ;
1156
1158
static constexpr int SwitchCostMultiplier = 2 ;
1157
1159
1158
1160
// FIXME: These are taken from the heuristic-based cost visitor: we should
@@ -1231,8 +1233,11 @@ class InlineCostFeaturesAnalyzer final : public CallAnalyzer {
1231
1233
}
1232
1234
}
1233
1235
1234
- void onFinalizeSwitch (unsigned JumpTableSize,
1235
- unsigned NumCaseCluster) override {
1236
+ void onFinalizeSwitch (unsigned JumpTableSize, unsigned NumCaseCluster,
1237
+ bool DefaultDestUndefined) override {
1238
+ if (!DefaultDestUndefined)
1239
+ increment (InlineCostFeatureIndex::switch_default_dest_penalty,
1240
+ SwitchDefaultDestCostMultiplier * InstrCost);
1236
1241
1237
1242
if (JumpTableSize) {
1238
1243
int64_t JTCost = static_cast <int64_t >(JumpTableSize) * InstrCost +
@@ -2461,7 +2466,7 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {
2461
2466
unsigned NumCaseCluster =
2462
2467
TTI.getEstimatedNumberOfCaseClusters (SI, JumpTableSize, PSI, BFI);
2463
2468
2464
- onFinalizeSwitch (JumpTableSize, NumCaseCluster);
2469
+ onFinalizeSwitch (JumpTableSize, NumCaseCluster, SI. defaultDestUndefined () );
2465
2470
return false ;
2466
2471
}
2467
2472
0 commit comments