Skip to content

Commit 0a2d233

Browse files
committed
compute effects: Don't modify the effects if they didn't change
This avoids sending a change notification which can trigger unnecessary other invalidations.
1 parent 0d73a21 commit 0a2d233

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeEscapeEffects.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ import SIL
2828
let computeEscapeEffects = FunctionPass(name: "compute-escape-effects", {
2929
(function: Function, context: PassContext) in
3030

31-
var newEffects = Stack<EscapeEffects.ArgumentEffect>(context)
32-
defer { newEffects.deinitialize() }
31+
var newEffects = function.effects.escapeEffects.arguments.filter {!$0.isDerived }
3332

3433
let returnInst = function.returnInstruction
3534
let argsWithDefinedEffects = getArgIndicesWithDefinedEscapingEffects(of: function)
3635

3736
for arg in function.arguments {
3837
// We are not interested in arguments with trivial types.
3938
if !arg.type.isNonTrivialOrContainsRawPointer(in: function) { continue }
40-
39+
4140
// Also, we don't want to override defined effects.
4241
if argsWithDefinedEffects.contains(arg.index) { continue }
4342

@@ -52,7 +51,7 @@ let computeEscapeEffects = FunctionPass(name: "compute-escape-effects", {
5251
context) {
5352
let effect = EscapeEffects.ArgumentEffect(.notEscaping, argumentIndex: arg.index,
5453
pathPattern: SmallProjectionPath(.anything))
55-
newEffects.push(effect)
54+
newEffects.append(effect)
5655
continue
5756
}
5857

@@ -65,17 +64,22 @@ let computeEscapeEffects = FunctionPass(name: "compute-escape-effects", {
6564
}
6665
}
6766

67+
// Don't modify the effects if they didn't change. This avoids sending a change notification
68+
// which can trigger unnecessary other invalidations.
69+
if newEffects == function.effects.escapeEffects.arguments {
70+
return
71+
}
72+
6873
context.modifyEffects(in: function) { (effects: inout FunctionEffects) in
69-
effects.escapeEffects.arguments = effects.escapeEffects.arguments.filter { !$0.isDerived }
70-
effects.escapeEffects.arguments.append(contentsOf: newEffects)
74+
effects.escapeEffects.arguments = newEffects
7175
}
7276
})
7377

7478

7579
/// Returns true if an argument effect was added.
7680
private
7781
func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
78-
to newEffects: inout Stack<EscapeEffects.ArgumentEffect>,
82+
to newEffects: inout [EscapeEffects.ArgumentEffect],
7983
_ returnInst: ReturnInst?, _ context: PassContext) -> Bool {
8084
// Correct the path if the argument is not a class reference itself, but a value type
8185
// containing one or more references.
@@ -159,7 +163,7 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
159163
effect = EscapeEffects.ArgumentEffect(.escapingToArgument(toArgIdx, toPath, exclusive),
160164
argumentIndex: arg.index, pathPattern: argPath)
161165
}
162-
newEffects.push(effect)
166+
newEffects.append(effect)
163167
return true
164168
}
165169

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ let computeSideEffects = FunctionPass(name: "compute-side-effects", {
6666
collectedEffects.addEffectsForEcapingArgument(argument: argument)
6767
}
6868

69+
// Don't modify the effects if they didn't change. This avoids sending a change notification
70+
// which can trigger unnecessary other invalidations.
71+
if let existingEffects = function.effects.sideEffects,
72+
existingEffects.arguments == collectedEffects.argumentEffects,
73+
existingEffects.global == collectedEffects.globalEffects {
74+
return
75+
}
76+
6977
// Finally replace the function's side effects.
7078
context.modifyEffects(in: function) { (effects: inout FunctionEffects) in
7179
effects.sideEffects = SideEffects(arguments: collectedEffects.argumentEffects, global: collectedEffects.globalEffects)

SwiftCompilerSources/Sources/SIL/Effects.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ public struct EscapeEffects : CustomStringConvertible, NoReflectionChildren {
134134
}
135135

136136
/// An escape effect on a function argument.
137-
public struct ArgumentEffect : CustomStringConvertible, NoReflectionChildren {
137+
public struct ArgumentEffect : Equatable, CustomStringConvertible, NoReflectionChildren {
138138

139-
public enum Kind {
139+
public enum Kind : Equatable {
140140
/// The argument value does not escape.
141141
///
142142
/// Syntax examples:

0 commit comments

Comments
 (0)