@@ -69,6 +69,12 @@ public enum AccessBase : CustomStringConvertible, Hashable {
69
69
/// An indirect result of a `begin_apply`.
70
70
case yield( MultipleValueInstructionResult )
71
71
72
+ /// store_borrow is never the base of a formal access, but calling Value.enclosingScope on an arbitrary address will
73
+ /// return it as the accessBase. A store_borrow always stores into an alloc_stack, but it is handled separately
74
+ /// because it may be useful for clients to know which value was stored in the temporary stack location for the
75
+ /// duration of this borrow scope.
76
+ case storeBorrow( StoreBorrowInst )
77
+
72
78
/// An address which is derived from a `Builtin.RawPointer`.
73
79
case pointer( PointerToAddressInst )
74
80
@@ -90,6 +96,8 @@ public enum AccessBase : CustomStringConvertible, Hashable {
90
96
} else {
91
97
self = . unidentified
92
98
}
99
+ case let sb as StoreBorrowInst :
100
+ self = . storeBorrow( sb)
93
101
default :
94
102
self = . unidentified
95
103
}
@@ -105,6 +113,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
105
113
case . tail( let rta) : return " tail - \( rta. instance) "
106
114
case . argument( let arg) : return " argument - \( arg) "
107
115
case . yield( let result) : return " yield - \( result) "
116
+ case . storeBorrow( let sb) : return " storeBorrow - \( sb) "
108
117
case . pointer( let p) : return " pointer - \( p) "
109
118
}
110
119
}
@@ -114,7 +123,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
114
123
switch self {
115
124
case . class, . tail:
116
125
return true
117
- case . box, . stack, . global, . argument, . yield, . pointer, . unidentified:
126
+ case . box, . stack, . global, . argument, . yield, . storeBorrow , . pointer, . unidentified:
118
127
return false
119
128
}
120
129
}
@@ -125,7 +134,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
125
134
case . box( let pbi) : return pbi. box
126
135
case . class( let rea) : return rea. instance
127
136
case . tail( let rta) : return rta. instance
128
- case . stack, . global, . argument, . yield, . pointer, . unidentified:
137
+ case . stack, . global, . argument, . yield, . storeBorrow , . pointer, . unidentified:
129
138
return nil
130
139
}
131
140
}
@@ -153,7 +162,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
153
162
switch self {
154
163
case . class( let rea) : return rea. fieldIsLet
155
164
case . global( let g) : return g. isLet
156
- case . box, . stack, . tail, . argument, . yield, . pointer, . unidentified:
165
+ case . box, . stack, . tail, . argument, . yield, . storeBorrow , . pointer, . unidentified:
157
166
return false
158
167
}
159
168
}
@@ -164,7 +173,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
164
173
case . box( let pbi) : return pbi. box. referenceRoot is AllocBoxInst
165
174
case . class( let rea) : return rea. instance. referenceRoot is AllocRefInstBase
166
175
case . tail( let rta) : return rta. instance. referenceRoot is AllocRefInstBase
167
- case . stack: return true
176
+ case . stack, . storeBorrow : return true
168
177
case . global, . argument, . yield, . pointer, . unidentified:
169
178
return false
170
179
}
@@ -173,7 +182,7 @@ public enum AccessBase : CustomStringConvertible, Hashable {
173
182
/// True, if the kind of storage of the access is known (e.g. a class property, or global variable).
174
183
public var hasKnownStorageKind : Bool {
175
184
switch self {
176
- case . box, . class, . tail, . stack, . global:
185
+ case . box, . class, . tail, . stack, . storeBorrow , . global:
177
186
return true
178
187
case . argument, . yield, . pointer, . unidentified:
179
188
return false
@@ -203,6 +212,8 @@ public enum AccessBase : CustomStringConvertible, Hashable {
203
212
return arg1 == arg2
204
213
case ( . yield( let baResult1) , . yield( let baResult2) ) :
205
214
return baResult1 == baResult2
215
+ case ( . storeBorrow( let sb1) , . storeBorrow( let sb2) ) :
216
+ return sb1 == sb2
206
217
case ( . pointer( let p1) , . pointer( let p2) ) :
207
218
return p1 == p2
208
219
default :
@@ -260,6 +271,15 @@ public enum AccessBase : CustomStringConvertible, Hashable {
260
271
case ( _, . argument( let otherArg) ) :
261
272
return argIsDistinct ( otherArg, from: self )
262
273
274
+ case ( . storeBorrow( let arg) , . storeBorrow( let otherArg) ) :
275
+ return arg. allocStack != otherArg. allocStack
276
+
277
+ // A StoreBorrow location can only be used by other StoreBorrows.
278
+ case ( . storeBorrow, _) :
279
+ return true
280
+ case ( _, . storeBorrow) :
281
+ return true
282
+
263
283
default :
264
284
// As we already handled pairs of the same kind, here we handle pairs with different kinds.
265
285
// Different storage kinds cannot alias, regardless where the storage comes from.
@@ -591,7 +611,7 @@ extension ValueUseDefWalker where Path == SmallProjectionPath {
591
611
return walkUp ( value: rea. instance, path: path. push ( . classField, index: rea. fieldIndex) ) != . abortWalk
592
612
case . tail( let rta) :
593
613
return walkUp ( value: rta. instance, path: path. push ( . tailElements, index: 0 ) ) != . abortWalk
594
- case . stack, . global, . argument, . yield, . pointer, . unidentified:
614
+ case . stack, . global, . argument, . yield, . storeBorrow , . pointer, . unidentified:
595
615
return false
596
616
}
597
617
}
0 commit comments