Skip to content

Commit 48513f3

Browse files
committed
[embedded] Introduce isGenericFunction and addAllNonGenericFunctions.
1 parent 9f75a26 commit 48513f3

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ let mandatoryPerformanceOptimizations = ModulePass(name: "mandatory-performance-
3232
var worklist = FunctionWorklist()
3333
worklist.addAllPerformanceAnnotatedFunctions(of: moduleContext)
3434
worklist.addAllAnnotatedGlobalInitOnceFunctions(of: moduleContext)
35+
// For embedded Swift, optimize all the functions (there cannot be any
36+
// generics, type metadata, etc.)
37+
if moduleContext.options.enableEmbeddedSwift {
38+
worklist.addAllNonGenericFunctions(of: moduleContext)
39+
}
3540

3641
optimizeFunctionsTopDown(using: &worklist, moduleContext)
3742
}
@@ -300,18 +305,16 @@ fileprivate struct FunctionWorklist {
300305
}
301306

302307
mutating func addAllPerformanceAnnotatedFunctions(of moduleContext: ModulePassContext) {
303-
// For embedded Swift, optimize all the functions (there cannot be any
304-
// generics, type metadata, etc.)
305-
if moduleContext.options.enableEmbeddedSwift {
306-
for f in moduleContext.functions {
307-
pushIfNotVisited(f)
308-
}
309-
return
308+
for f in moduleContext.functions where f.performanceConstraints != .none {
309+
pushIfNotVisited(f)
310310
}
311+
}
311312

312-
for f in moduleContext.functions where f.performanceConstraints != .none {
313+
mutating func addAllNonGenericFunctions(of moduleContext: ModulePassContext) {
314+
for f in moduleContext.functions where f.isGenericFunction {
313315
pushIfNotVisited(f)
314316
}
317+
return
315318
}
316319

317320
mutating func addAllAnnotatedGlobalInitOnceFunctions(of moduleContext: ModulePassContext) {

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
137137
/// It's called from a `[global_init]` function via a `builtin "once"`.
138138
public var isGlobalInitOnceFunction: Bool { bridged.isGlobalInitOnceFunction() }
139139

140+
public var isGenericFunction: Bool { bridged.isGenericFunction() }
141+
140142
/// Kinds of effect attributes which can be defined for a Swift function.
141143
public enum EffectAttribute {
142144
/// No effect attribute is specified.

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ struct BridgedFunction {
260260
return getFunction()->isGlobalInitOnceFunction();
261261
}
262262

263+
bool isGenericFunction() const {
264+
return getFunction()->getGenericSignature().isNull();
265+
}
266+
263267
bool hasSemanticsAttr(llvm::StringRef attrName) const {
264268
return getFunction()->hasSemanticsAttr(attrName);
265269
}

0 commit comments

Comments
 (0)