Skip to content

Commit 4e35d25

Browse files
committed
LocalVariableUtils: add store_borrow access tracking.
We sometimes use LocalVariableUtils to analyze temporary storage in which the store_borrow is not already enclosed by an access scope.
1 parent b80bd16 commit 4e35d25

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ extension LifetimeDependenceDefUseWalker {
929929
// Simply a marker that indicates the start of an in-memory dependent value. If this was a mark_dependence, uses
930930
// of its forwarded address has were visited by LocalVariableAccessWalker and recorded as separate local accesses.
931931
return .continueWalk
932-
case .store:
932+
case .store, .storeBorrow:
933933
// A store does not use the previous in-memory value.
934934
return .continueWalk
935935
case .apply:

SwiftCompilerSources/Sources/Optimizer/Utilities/LocalVariableUtils.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct LocalVariableAccess: CustomStringConvertible {
6969
case dependenceSource // A value/address depends on this local here (like a load)
7070
case dependenceDest // This local depends on another value/address here (like a store)
7171
case store // 'var' initialization and destruction
72+
case storeBorrow // scoped initialization of temporaries
7273
case apply // indirect arguments
7374
case escape // alloc_box captures
7475
}
@@ -103,7 +104,7 @@ struct LocalVariableAccess: CustomStringConvertible {
103104
}
104105
case .load, .dependenceSource, .dependenceDest:
105106
return false
106-
case .incomingArgument, .outgoingArgument, .store, .inoutYield:
107+
case .incomingArgument, .outgoingArgument, .store, .storeBorrow, .inoutYield:
107108
return true
108109
case .apply:
109110
let apply = instruction as! FullApplySite
@@ -146,6 +147,8 @@ struct LocalVariableAccess: CustomStringConvertible {
146147
str += "dependenceDest"
147148
case .store:
148149
str += "store"
150+
case .storeBorrow:
151+
str += "storeBorrow"
149152
case .apply:
150153
str += "apply"
151154
case .escape:
@@ -178,9 +181,9 @@ class LocalVariableAccessInfo: CustomStringConvertible {
178181
case .`init`, .modify:
179182
break // lazily compute full assignment
180183
}
181-
case .load, .dependenceSource, .dependenceDest:
184+
case .load, .dependenceSource, .dependenceDest:
182185
self._isFullyAssigned = false
183-
case .store:
186+
case .store, .storeBorrow:
184187
if let store = localAccess.instruction as? StoringInstruction {
185188
self._isFullyAssigned = LocalVariableAccessInfo.isBase(address: store.destination)
186189
} else {
@@ -442,6 +445,9 @@ extension LocalVariableAccessWalker: AddressUseVisitor {
442445
case is LoadBorrowInst:
443446
visit(LocalVariableAccess(.load, operand))
444447
return .continueWalk
448+
case is StoreBorrowInst:
449+
visit(LocalVariableAccess(.storeBorrow, operand))
450+
return .continueWalk
445451
default:
446452
// A StoreBorrow should be guarded by an access scope.
447453
//

0 commit comments

Comments
 (0)