@@ -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) {
@@ -124,6 +125,15 @@ class DeadFunctionAndGlobalElimination {
124
125
if (F->getRepresentation () == SILFunctionTypeRepresentation::ObjCMethod)
125
126
return true ;
126
127
128
+ // To support ObjectOutliner's replacing of calls to findStringSwitchCase
129
+ // with _findStringSwitchCaseWithCache. In Embedded Swift, we have to load
130
+ // the body of this function early and specialize it, so that ObjectOutliner
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" ))
135
+ return true ;
136
+
127
137
return false ;
128
138
}
129
139
@@ -713,9 +723,11 @@ class DeadFunctionAndGlobalElimination {
713
723
714
724
public:
715
725
DeadFunctionAndGlobalElimination (SILModule *module,
716
- bool keepExternalWitnessTablesAlive) :
726
+ bool keepExternalWitnessTablesAlive,
727
+ bool keepStringSwitchIntrinsicAlive) :
717
728
Module (module),
718
- keepExternalWitnessTablesAlive (keepExternalWitnessTablesAlive) {}
729
+ keepExternalWitnessTablesAlive (keepExternalWitnessTablesAlive),
730
+ keepStringSwitchIntrinsicAlive (keepStringSwitchIntrinsicAlive) {}
719
731
720
732
// / The main entry point of the optimization.
721
733
void eliminateFunctionsAndGlobals (SILModuleTransform *DFEPass) {
@@ -799,8 +811,10 @@ class DeadFunctionAndGlobalEliminationPass : public SILModuleTransform {
799
811
// can eliminate such functions.
800
812
getModule ()->invalidateSILLoaderCaches ();
801
813
802
- DeadFunctionAndGlobalElimination deadFunctionElimination (getModule (),
803
- /* keepExternalWitnessTablesAlive*/ !isLateDFE);
814
+ DeadFunctionAndGlobalElimination deadFunctionElimination (
815
+ getModule (),
816
+ /* keepExternalWitnessTablesAlive*/ !isLateDFE,
817
+ /* keepStringSwitchIntrinsicAlive*/ !isLateDFE);
804
818
deadFunctionElimination.eliminateFunctionsAndGlobals (this );
805
819
}
806
820
};
0 commit comments