Skip to content

Commit 500f8ad

Browse files
committed
[embedded] Only treat findStringSwitchCaseWithCache as anchor in early DFE, let late DFE collect it if unused
1 parent e1d22b5 commit 500f8ad

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class DeadFunctionAndGlobalElimination {
9090
llvm::SmallPtrSet<void *, 32> AliveFunctionsAndTables;
9191

9292
bool keepExternalWitnessTablesAlive;
93+
bool keepStringSwitchIntrinsicAlive;
9394

9495
/// Checks is a function is alive, e.g. because it is visible externally.
9596
bool isAnchorFunction(SILFunction *F) {
@@ -127,9 +128,10 @@ class DeadFunctionAndGlobalElimination {
127128
// To support ObjectOutliner's replacing of calls to findStringSwitchCase
128129
// with _findStringSwitchCaseWithCache. In Embedded Swift, we have to load
129130
// 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"))
133135
return true;
134136

135137
return false;
@@ -721,9 +723,11 @@ class DeadFunctionAndGlobalElimination {
721723

722724
public:
723725
DeadFunctionAndGlobalElimination(SILModule *module,
724-
bool keepExternalWitnessTablesAlive) :
726+
bool keepExternalWitnessTablesAlive,
727+
bool keepStringSwitchIntrinsicAlive) :
725728
Module(module),
726-
keepExternalWitnessTablesAlive(keepExternalWitnessTablesAlive) {}
729+
keepExternalWitnessTablesAlive(keepExternalWitnessTablesAlive),
730+
keepStringSwitchIntrinsicAlive(keepStringSwitchIntrinsicAlive) {}
727731

728732
/// The main entry point of the optimization.
729733
void eliminateFunctionsAndGlobals(SILModuleTransform *DFEPass) {
@@ -807,8 +811,10 @@ class DeadFunctionAndGlobalEliminationPass : public SILModuleTransform {
807811
// can eliminate such functions.
808812
getModule()->invalidateSILLoaderCaches();
809813

810-
DeadFunctionAndGlobalElimination deadFunctionElimination(getModule(),
811-
/*keepExternalWitnessTablesAlive*/ !isLateDFE);
814+
DeadFunctionAndGlobalElimination deadFunctionElimination(
815+
getModule(),
816+
/*keepExternalWitnessTablesAlive*/ !isLateDFE,
817+
/*keepStringSwitchIntrinsicAlive*/ !isLateDFE);
812818
deadFunctionElimination.eliminateFunctionsAndGlobals(this);
813819
}
814820
};

0 commit comments

Comments
 (0)