Skip to content

Commit caea41a

Browse files
committed
ComputeEscapeEffects: don't support exclusive argument -> argument effects.
Exclusive argument -> argument effects cannot appear because such an effect would involve a store which is not permitted for exclusive escapes.
1 parent dbd3ebe commit caea41a

File tree

4 files changed

+12
-51
lines changed

4 files changed

+12
-51
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeEscapeEffects.swift

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
158158
effect = EscapeEffects.ArgumentEffect(.escapingToReturn(toPath, exclusive),
159159
argumentIndex: arg.index, pathPattern: argPath)
160160
case .toArgument(let toArgIdx, let toPath):
161-
let exclusive = isExclusiveEscapeToArgument(fromArgument: arg, fromPath: argPath,
162-
toArgumentIndex: toArgIdx, toPath: toPath, context)
163-
effect = EscapeEffects.ArgumentEffect(.escapingToArgument(toArgIdx, toPath, exclusive),
161+
// Exclusive argument -> argument effects cannot appear because such an effect would
162+
// involve a store which is not permitted for exclusive escapes.
163+
effect = EscapeEffects.ArgumentEffect(.escapingToArgument(toArgIdx, toPath, /*exclusive*/ false),
164164
argumentIndex: arg.index, pathPattern: argPath)
165165
}
166166
newEffects.append(effect)
@@ -234,29 +234,3 @@ func isExclusiveEscapeToReturn(fromArgument: Argument, fromPath: SmallProjection
234234
let visitor = IsExclusiveReturnEscapeVisitor(fromArgument: fromArgument, fromPath: fromPath, toPath: toPath)
235235
return !returnInst.operand.at(toPath).isEscaping(using: visitor, context)
236236
}
237-
238-
private
239-
func isExclusiveEscapeToArgument(fromArgument: Argument, fromPath: SmallProjectionPath,
240-
toArgumentIndex: Int, toPath: SmallProjectionPath, _ context: FunctionPassContext) -> Bool {
241-
struct IsExclusiveArgumentEscapeVisitor : EscapeVisitor {
242-
let fromArgument: Argument
243-
let fromPath: SmallProjectionPath
244-
let toArgumentIndex: Int
245-
let toPath: SmallProjectionPath
246-
247-
mutating func visitDef(def: Value, path: EscapePath) -> DefResult {
248-
guard let arg = def as? FunctionArgument else {
249-
return .continueWalkUp
250-
}
251-
if path.followStores { return .abort }
252-
if arg == fromArgument && path.projectionPath.matches(pattern: fromPath) { return .walkDown }
253-
if arg.index == toArgumentIndex && path.projectionPath.matches(pattern: toPath) { return .walkDown }
254-
return .abort
255-
}
256-
}
257-
let visitor = IsExclusiveArgumentEscapeVisitor(fromArgument: fromArgument, fromPath: fromPath,
258-
toArgumentIndex: toArgumentIndex, toPath: toPath)
259-
let toArg = fromArgument.parentFunction.arguments[toArgumentIndex]
260-
return !toArg.at(toPath).isEscapingWhenWalkingDown(using: visitor, context)
261-
}
262-

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
592592
var matched = false
593593
for effect in effects.escapeEffects.arguments {
594594
switch effect.kind {
595-
case .escapingToArgument(let toArgIdx, let toPath, let exclusive):
595+
case .escapingToArgument(let toArgIdx, let toPath, _):
596+
// Note: exclusive argument -> argument effects cannot appear, so we don't need to handle them here.
596597
if effect.matches(calleeArgIdx, argPath.projectionPath) {
597598
guard let callerToIdx = apply.callerArgIndex(calleeArgIndex: toArgIdx) else {
598599
return isEscaping
@@ -602,20 +603,6 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
602603
let arg = apply.arguments[callerToIdx]
603604

604605
let p = Path(projectionPath: toPath, followStores: false, knownType: nil)
605-
if walkUp(addressOrValue: arg, path: p) == .abortWalk {
606-
return .abortWalk
607-
}
608-
matched = true
609-
} else if toArgIdx == calleeArgIdx && argPath.projectionPath.matches(pattern: toPath) {
610-
// Handle the reverse direction of an arg-to-arg escape.
611-
guard let callerArgIdx = apply.callerArgIndex(calleeArgIndex: effect.argumentIndex) else {
612-
return isEscaping
613-
}
614-
if !exclusive { return isEscaping }
615-
616-
let arg = apply.arguments[callerArgIdx]
617-
let p = Path(projectionPath: effect.pathPattern, followStores: false, knownType: nil)
618-
619606
if walkUp(addressOrValue: arg, path: p) == .abortWalk {
620607
return .abortWalk
621608
}

test/SILOptimizer/escape_effects.sil

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ sil [ossa] @unknown_function : $@convention(thin) (@owned X) -> ()
5757
sil [ossa] @unknown_function_y : $@convention(thin) (@owned Y) -> ()
5858

5959
// CHECK-LABEL: sil [ossa] @test_basic
60-
// CHECK-NEXT: [%1: escape v** => %3.v**]
60+
// CHECK-NEXT: [%1: escape v** -> %3.v**]
6161
// CHECK-NEXT: [%2: noescape, escape c*.v** -> %r.v**]
6262
// CHECK-NEXT: [%3: noescape]
6363
// CHECK-NEXT: {{^[^[]}}
@@ -201,7 +201,7 @@ sil [ossa] @self_arg_callee : $@convention(thin) (@inout Str) -> () {
201201
}
202202

203203
// CHECK-LABEL: sil [ossa] @test_self_arg_escape
204-
// CHECK-NEXT: [%0: escape v** => %0.v**]
204+
// CHECK-NEXT: [%0: escape v** -> %0.v**]
205205
// CHECK-NEXT: {{^[^[]}}
206206
sil [ossa] @test_self_arg_escape : $@convention(thin) (@inout Str) -> () {
207207
bb0(%0 : $*Str):
@@ -212,7 +212,7 @@ bb0(%0 : $*Str):
212212
}
213213

214214
// CHECK-LABEL: sil [ossa] @test_self_arg_escape_with_copy
215-
// CHECK-NEXT: [%0: escape v** => %0.s1.0.v**]
215+
// CHECK-NEXT: [%0: escape v** -> %0.s1.0.v**]
216216
// CHECK-NEXT: {{^[^[]}}
217217
sil [ossa] @test_self_arg_escape_with_copy : $@convention(thin) (@inout Str) -> () {
218218
bb0(%0 : $*Str):
@@ -225,7 +225,7 @@ bb0(%0 : $*Str):
225225
}
226226

227227
// CHECK-LABEL: sil [ossa] @test_self_arg_escape_with_bidirectional_copy
228-
// CHECK-NEXT: [%0: escape v** => %0.v**]
228+
// CHECK-NEXT: [%0: escape v** -> %0.v**]
229229
// CHECK-NEXT: {{^[^[]}}
230230
sil [ossa] @test_self_arg_escape_with_bidirectional_copy : $@convention(thin) (@inout Str) -> () {
231231
bb0(%0 : $*Str):
@@ -240,7 +240,7 @@ bb0(%0 : $*Str):
240240

241241
// CHECK-LABEL: sil [ossa] @test_content_to_arg_addr
242242
// CHECK-NEXT: [%0: noescape **]
243-
// CHECK-NEXT: [%1: noescape, escape c*.v** => %0.v**]
243+
// CHECK-NEXT: [%1: noescape, escape c*.v** -> %0.v**]
244244
// CHECK-NEXT: {{^[^[]}}
245245
sil [ossa] @test_content_to_arg_addr : $@convention(thin) (@guaranteed Y) -> @out Str {
246246
bb0(%0 : $*Str, %1 : @guaranteed $Y):

test/SILOptimizer/escape_info.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ sil [ossa] @arg_to_return : $@convention(thin) (@owned X) -> @owned Str {
9393
[%0: escape => %r.s0]
9494
}
9595
sil [ossa] @arg_to_arg : $@convention(thin) (@owned X) -> @out Str {
96-
[%0: noescape]
97-
[%1: escape => %0.s0]
96+
[%0: noescape v**]
97+
[%1: escape -> %0.s0]
9898
}
9999
sil [ossa] @content_of_arg_to_return : $@convention(thin) (@owned Z) -> @owned Y {
100100
[%0: noescape, escape c* => %r]

0 commit comments

Comments
 (0)