@@ -30,12 +30,11 @@ let computeEffects = FunctionPass(name: "compute-effects", {
30
30
( function: Function , context: PassContext ) in
31
31
var argsWithDefinedEffects = getArgIndicesWithDefinedEffects ( of: function)
32
32
33
- struct IgnoreRecursiveCallVisitor : EscapeInfoVisitor {
33
+ struct IgnoreRecursiveCallVisitor : EscapeVisitor {
34
34
func visitUse( operand: Operand , path: EscapePath ) -> UseResult {
35
35
return isOperandOfRecursiveCall ( operand) ? . ignore : . continueWalk
36
36
}
37
37
}
38
- var escapeInfo = EscapeInfo ( calleeAnalysis: context. calleeAnalysis, visitor: IgnoreRecursiveCallVisitor ( ) )
39
38
var newEffects = Stack < ArgumentEffect > ( context)
40
39
let returnInst = function. returnInstruction
41
40
@@ -47,7 +46,8 @@ let computeEffects = FunctionPass(name: "compute-effects", {
47
46
if argsWithDefinedEffects. contains ( arg. index) { continue }
48
47
49
48
// First check: is the argument (or a projected value of it) escaping at all?
50
- if !escapeInfo. isEscapingWhenWalkingDown ( object: arg, path: SmallProjectionPath ( . anything) ) {
49
+ if !arg. at ( . anything) . isEscaping ( using: IgnoreRecursiveCallVisitor ( ) ,
50
+ startWalkingDown: true , context) {
51
51
newEffects. push ( ArgumentEffect ( . notEscaping, argumentIndex: arg. index, pathPattern: SmallProjectionPath ( . anything) ) )
52
52
continue
53
53
}
@@ -78,7 +78,7 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
78
78
// containing one or more references.
79
79
let argPath = arg. type. isClass ? ap : ap. push ( . anyValueFields)
80
80
81
- struct ArgEffectsVisitor : EscapeInfoVisitor {
81
+ struct ArgEffectsVisitor : EscapeVisitorWithResult {
82
82
enum EscapeDestination {
83
83
case notSet
84
84
case toReturn( SmallProjectionPath )
@@ -131,8 +131,8 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
131
131
}
132
132
}
133
133
134
- var walker = EscapeInfo ( calleeAnalysis : context . calleeAnalysis , visitor : ArgEffectsVisitor ( ) )
135
- if walker . isEscapingWhenWalkingDown ( object : arg , path : argPath ) {
134
+ guard let result = arg . at ( argPath ) . visit ( using : ArgEffectsVisitor ( ) ,
135
+ startWalkingDown : true , context ) else {
136
136
return false
137
137
}
138
138
@@ -142,7 +142,7 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
142
142
}
143
143
144
144
let effect : ArgumentEffect
145
- switch walker . visitor . result {
145
+ switch result {
146
146
case . notSet:
147
147
effect = ArgumentEffect ( . notEscaping, argumentIndex: arg. index, pathPattern: argPath)
148
148
case . toReturn( let toPath) :
@@ -200,7 +200,7 @@ private
200
200
func isExclusiveEscapeToReturn( fromArgument: Argument , fromPath: SmallProjectionPath ,
201
201
toPath: SmallProjectionPath ,
202
202
returnInst: ReturnInst , _ context: PassContext ) -> Bool {
203
- struct IsExclusiveReturnEscapeVisitor : EscapeInfoVisitor {
203
+ struct IsExclusiveReturnEscapeVisitor : EscapeVisitor {
204
204
let fromArgument : Argument
205
205
let fromPath : SmallProjectionPath
206
206
let toPath : SmallProjectionPath
@@ -228,14 +228,13 @@ func isExclusiveEscapeToReturn(fromArgument: Argument, fromPath: SmallProjection
228
228
}
229
229
}
230
230
let visitor = IsExclusiveReturnEscapeVisitor ( fromArgument: fromArgument, fromPath: fromPath, toPath: toPath)
231
- var walker = EscapeInfo ( calleeAnalysis: context. calleeAnalysis, visitor: visitor)
232
- return !walker. isEscaping ( object: returnInst. operand, path: toPath)
231
+ return !returnInst. operand. at ( toPath) . isEscaping ( using: visitor, context)
233
232
}
234
233
235
234
private
236
235
func isExclusiveEscapeToArgument( fromArgument: Argument , fromPath: SmallProjectionPath ,
237
236
toArgumentIndex: Int , toPath: SmallProjectionPath , _ context: PassContext ) -> Bool {
238
- struct IsExclusiveArgumentEscapeVisitor : EscapeInfoVisitor {
237
+ struct IsExclusiveArgumentEscapeVisitor : EscapeVisitor {
239
238
let fromArgument : Argument
240
239
let fromPath : SmallProjectionPath
241
240
let toArgumentIndex : Int
@@ -253,8 +252,7 @@ func isExclusiveEscapeToArgument(fromArgument: Argument, fromPath: SmallProjecti
253
252
}
254
253
let visitor = IsExclusiveArgumentEscapeVisitor ( fromArgument: fromArgument, fromPath: fromPath,
255
254
toArgumentIndex: toArgumentIndex, toPath: toPath)
256
- var walker = EscapeInfo ( calleeAnalysis: context. calleeAnalysis, visitor: visitor)
257
255
let toArg = fromArgument. function. arguments [ toArgumentIndex]
258
- return !walker . isEscaping ( object : toArg , path : toPath )
256
+ return !toArg . at ( toPath ) . isEscaping ( using : visitor , startWalkingDown : true , context )
259
257
}
260
258
0 commit comments