Skip to content

Commit e1d22b5

Browse files
committed
[embedded] Avoid changing lookupStdlibFunction, load findStringSwitchCaseWithCache in MPO instead
1 parent 92b0c5f commit e1d22b5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
8686
// eagerly linking and specializing _findStringSwitchCaseWithCache whenever findStringSwitchCase is found in the module.
8787
if context.options.enableEmbeddedSwift {
8888
if function.hasSemanticsAttribute("findStringSwitchCase"),
89-
let f = context.lookupStdlibFunction(name: "_findStringSwitchCaseWithCache") {
89+
let f = context.lookupStdlibFunction(name: "_findStringSwitchCaseWithCache"),
90+
context.loadFunction(function: f, loadCalleesRecursively: true) {
9091
worklist.pushIfNotVisited(f)
9192
}
9293
}

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ class DeadFunctionAndGlobalElimination {
124124
if (F->getRepresentation() == SILFunctionTypeRepresentation::ObjCMethod)
125125
return true;
126126

127+
// To support ObjectOutliner's replacing of calls to findStringSwitchCase
128+
// with _findStringSwitchCaseWithCache. In Embedded Swift, we have to load
129+
// 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"))
133+
return true;
134+
127135
return false;
128136
}
129137

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,11 +1929,7 @@ OptionalBridgedFunction BridgedPassContext::lookupStdlibFunction(BridgedStringRe
19291929

19301930
SILDeclRef declRef(decl, SILDeclRef::Kind::Func);
19311931
SILOptFunctionBuilder funcBuilder(*invocation->getTransform());
1932-
SILFunction *function = funcBuilder.getOrCreateFunction(SILLocation(decl), declRef, NotForDefinition);
1933-
if (mod->getOptions().EmbeddedSwift) {
1934-
mod->linkFunction(function, SILModule::LinkingMode::LinkAll);
1935-
}
1936-
return {function};
1932+
return {funcBuilder.getOrCreateFunction(SILLocation(decl), declRef, NotForDefinition)};
19371933
}
19381934

19391935
OptionalBridgedFunction BridgedPassContext::lookUpNominalDeinitFunction(BridgedDeclObj nominal) const {

0 commit comments

Comments
 (0)