Skip to content

Commit 4fa9e53

Browse files
committed
[embedded] Move embedded Swift logic to isAnchorFunction
1 parent 325bc94 commit 4fa9e53

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class DeadFunctionAndGlobalElimination {
9797

9898
/// Checks is a function is alive, e.g. because it is visible externally.
9999
bool isAnchorFunction(SILFunction *F) {
100+
// In embedded Swift, (even public) generic functions *after serialization*
101+
// cannot be used externally and are not anchors.
102+
bool embedded = Module->getOptions().EmbeddedSwift;
103+
bool generic = loweredFunctionHasGenericArguments(F);
104+
bool isSerialized = Module->isSerialized();
105+
if (embedded && generic && isSerialized)
106+
return false;
100107

101108
// Functions that may be used externally cannot be removed.
102109
if (F->isPossiblyUsedExternally())
@@ -427,15 +434,7 @@ class DeadFunctionAndGlobalElimination {
427434
findAnchorsInTables();
428435

429436
for (SILFunction &F : *Module) {
430-
// In embedded Swift, generic functions, even public ones cannot be used
431-
// externally and are not anchors.
432-
bool embedded = Module->getOptions().EmbeddedSwift;
433-
bool generic = loweredFunctionHasGenericArguments(&F);
434-
bool isSerialized = Module->isSerialized();
435-
bool ignoreAnchor =
436-
embedded && generic && isSerialized;
437-
438-
if (isAnchorFunction(&F) && !ignoreAnchor) {
437+
if (isAnchorFunction(&F)) {
439438
LLVM_DEBUG(llvm::dbgs() << " anchor function: " << F.getName() <<"\n");
440439
ensureAlive(&F);
441440
}
@@ -446,7 +445,7 @@ class DeadFunctionAndGlobalElimination {
446445
[this](SILFunction *targetFun) { ensureAlive(targetFun); });
447446

448447
bool retainBecauseFunctionIsNoOpt = !F.shouldOptimize();
449-
if (embedded)
448+
if (Module->getOptions().EmbeddedSwift)
450449
retainBecauseFunctionIsNoOpt = false;
451450

452451
if (retainBecauseFunctionIsNoOpt) {

0 commit comments

Comments
 (0)