@@ -90,6 +90,7 @@ class DeadFunctionAndGlobalElimination {
90
90
llvm::SmallPtrSet<void *, 32 > AliveFunctionsAndTables;
91
91
92
92
bool keepExternalWitnessTablesAlive;
93
+ bool keepStringSwitchIntrinsicAlive;
93
94
94
95
// / Checks is a function is alive, e.g. because it is visible externally.
95
96
bool isAnchorFunction (SILFunction *F) {
@@ -127,9 +128,10 @@ class DeadFunctionAndGlobalElimination {
127
128
// To support ObjectOutliner's replacing of calls to findStringSwitchCase
128
129
// with _findStringSwitchCaseWithCache. In Embedded Swift, we have to load
129
130
// the body of this function early and specialize it, so that ObjectOutliner
130
- // can reference it later. To make this work we have to avoid DFE'ing it.
131
- // Linker's dead-stripping will eventually remove this if actually unused.
132
- if (F->hasSemanticsAttr (" findStringSwitchCaseWithCache" ))
131
+ // can reference it later. To make this work we have to avoid DFE'ing it in
132
+ // the early DFE pass. Late DFE will take care of it if actually unused.
133
+ if (keepStringSwitchIntrinsicAlive &&
134
+ F->hasSemanticsAttr (" findStringSwitchCaseWithCache" ))
133
135
return true ;
134
136
135
137
return false ;
@@ -721,9 +723,11 @@ class DeadFunctionAndGlobalElimination {
721
723
722
724
public:
723
725
DeadFunctionAndGlobalElimination (SILModule *module ,
724
- bool keepExternalWitnessTablesAlive) :
726
+ bool keepExternalWitnessTablesAlive,
727
+ bool keepStringSwitchIntrinsicAlive) :
725
728
Module (module ),
726
- keepExternalWitnessTablesAlive (keepExternalWitnessTablesAlive) {}
729
+ keepExternalWitnessTablesAlive (keepExternalWitnessTablesAlive),
730
+ keepStringSwitchIntrinsicAlive (keepStringSwitchIntrinsicAlive) {}
727
731
728
732
// / The main entry point of the optimization.
729
733
void eliminateFunctionsAndGlobals (SILModuleTransform *DFEPass) {
@@ -807,8 +811,10 @@ class DeadFunctionAndGlobalEliminationPass : public SILModuleTransform {
807
811
// can eliminate such functions.
808
812
getModule ()->invalidateSILLoaderCaches ();
809
813
810
- DeadFunctionAndGlobalElimination deadFunctionElimination (getModule (),
811
- /* keepExternalWitnessTablesAlive*/ !isLateDFE);
814
+ DeadFunctionAndGlobalElimination deadFunctionElimination (
815
+ getModule (),
816
+ /* keepExternalWitnessTablesAlive*/ !isLateDFE,
817
+ /* keepStringSwitchIntrinsicAlive*/ !isLateDFE);
812
818
deadFunctionElimination.eliminateFunctionsAndGlobals (this );
813
819
}
814
820
};
0 commit comments