mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
MandatoryPerformanceOptimizations: only set the [perf_constraint] flag for callees of performance constraint functions
It used to also set it for functions which are referenced from a global with a const/section attribute - even if not performance attribute was present in the whole module. This is unnecessary and can lead to worse code generation. rdar://152665294
This commit is contained in:
@@ -40,6 +40,12 @@ let mandatoryPerformanceOptimizations = ModulePass(name: "mandatory-performance-
|
||||
}
|
||||
|
||||
optimizeFunctionsTopDown(using: &worklist, moduleContext)
|
||||
|
||||
// It's not required to set the perf_constraint flag on all functions in embedded mode.
|
||||
// Embedded mode already implies that flag.
|
||||
if !moduleContext.options.enableEmbeddedSwift {
|
||||
setPerformanceConstraintFlags(moduleContext)
|
||||
}
|
||||
}
|
||||
|
||||
private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
|
||||
@@ -49,13 +55,6 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
|
||||
if !context.loadFunction(function: f, loadCalleesRecursively: true) {
|
||||
return
|
||||
}
|
||||
|
||||
// It's not required to set the perf_constraint flag on all functions in embedded mode.
|
||||
// Embedded mode already implies that flag.
|
||||
if !moduleContext.options.enableEmbeddedSwift {
|
||||
f.set(isPerformanceConstraint: true, context)
|
||||
}
|
||||
|
||||
optimize(function: f, context, moduleContext, &worklist)
|
||||
}
|
||||
|
||||
@@ -68,6 +67,17 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
|
||||
}
|
||||
}
|
||||
|
||||
private func setPerformanceConstraintFlags(_ moduleContext: ModulePassContext) {
|
||||
var worklist = FunctionWorklist()
|
||||
for f in moduleContext.functions where f.performanceConstraints != .none && f.isDefinition {
|
||||
worklist.pushIfNotVisited(f)
|
||||
}
|
||||
while let f = worklist.pop() {
|
||||
moduleContext.transform(function: f) { f.set(isPerformanceConstraint: true, $0) }
|
||||
worklist.addCallees(of: f, moduleContext)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct PathFunctionTuple: Hashable {
|
||||
var path: SmallProjectionPath
|
||||
var function: Function
|
||||
|
||||
Reference in New Issue
Block a user