Skip to content

Commit 7fb4fc0

Browse files
committed
MandatoryPerformanceOptimizations: fix the linkage of function-signature-specialized functions
We need to keep the original linkage because it would be illegal to call a shared not-serialized function from a serialized function. Also, rename the API to create the specialized function.
1 parent ecbb073 commit 7fb4fc0

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/ModulePassContext.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct ModulePassContext : Context, CustomStringConvertible {
131131
return function.isDefinition
132132
}
133133

134-
func createSpecializedFunctionDeclaration(
134+
func createEmptyFunction(
135135
name: String,
136136
parameters: [ParameterInfo],
137137
hasSelfParameter: Bool,
@@ -140,8 +140,8 @@ struct ModulePassContext : Context, CustomStringConvertible {
140140
return name._withBridgedStringRef { nameRef in
141141
let bridgedParamInfos = parameters.map { $0._bridged }
142142
return bridgedParamInfos.withUnsafeBufferPointer { paramBuf in
143-
_bridged.createSpecializedFunction(nameRef, paramBuf.baseAddress, paramBuf.count,
144-
hasSelfParameter, originalFunction.bridged).function
143+
_bridged.createEmptyFunction(nameRef, paramBuf.baseAddress, paramBuf.count,
144+
hasSelfParameter, originalFunction.bridged).function
145145
}
146146
}
147147
}

SwiftCompilerSources/Sources/Optimizer/Utilities/FunctionSignatureTransforms.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private func createSpecializedFunction(
8282
) -> Function {
8383
let (aliveParameters, hasSelfParameter) = getAliveParameters(of: originalFunction)
8484

85-
let specializedFunction = context.createSpecializedFunctionDeclaration(
85+
let specializedFunction = context.createEmptyFunction(
8686
name: name,
8787
parameters: aliveParameters,
8888
hasSelfParameter: hasSelfParameter,

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ struct BridgedPassContext {
286286
SWIFT_IMPORT_UNSAFE OptionalBridgedFunction lookUpNominalDeinitFunction(BridgedNominalTypeDecl nominal) const;
287287
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedSubstitutionMap getContextSubstitutionMap(BridgedType type) const;
288288
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getBuiltinIntegerType(SwiftInt bitWidth) const;
289-
SWIFT_IMPORT_UNSAFE BridgedFunction createSpecializedFunction(BridgedStringRef name,
290-
const BridgedParameterInfo * _Nullable bridgedParams,
291-
SwiftInt paramCount,
292-
bool hasSelfParam,
293-
BridgedFunction fromFunc) const;
289+
SWIFT_IMPORT_UNSAFE BridgedFunction createEmptyFunction(BridgedStringRef name,
290+
const BridgedParameterInfo * _Nullable bridgedParams,
291+
SwiftInt paramCount,
292+
bool hasSelfParam,
293+
BridgedFunction fromFunc) const;
294294
void moveFunctionBody(BridgedFunction sourceFunc, BridgedFunction destFunc) const;
295295

296296
// Passmanager housekeeping

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,11 +1731,11 @@ bool BridgedPassContext::enableSimplificationFor(BridgedInstruction inst) const
17311731
}
17321732

17331733
BridgedFunction BridgedPassContext::
1734-
createSpecializedFunction(BridgedStringRef name,
1735-
const BridgedParameterInfo * _Nullable bridgedParams,
1736-
SwiftInt paramCount,
1737-
bool hasSelfParam,
1738-
BridgedFunction fromFunc) const {
1734+
createEmptyFunction(BridgedStringRef name,
1735+
const BridgedParameterInfo * _Nullable bridgedParams,
1736+
SwiftInt paramCount,
1737+
bool hasSelfParam,
1738+
BridgedFunction fromFunc) const {
17391739
swift::SILModule *mod = invocation->getPassManager()->getModule();
17401740
SILFunction *fromFn = fromFunc.getFunction();
17411741

@@ -1761,7 +1761,7 @@ createSpecializedFunction(BridgedStringRef name,
17611761
SILOptFunctionBuilder functionBuilder(*invocation->getTransform());
17621762

17631763
SILFunction *newF = functionBuilder.createFunction(
1764-
SILLinkage::Shared, name.unbridged(), newTy, nullptr, fromFn->getLocation(), fromFn->isBare(),
1764+
fromFn->getLinkage(), name.unbridged(), newTy, nullptr, fromFn->getLocation(), fromFn->isBare(),
17651765
fromFn->isTransparent(), fromFn->isSerialized(), IsNotDynamic, IsNotDistributed,
17661766
IsNotRuntimeAccessible, fromFn->getEntryCount(), fromFn->isThunk(),
17671767
fromFn->getClassSubclassScope(), fromFn->getInlineStrategy(), fromFn->getEffectsKind(),

0 commit comments

Comments
 (0)