@@ -195,14 +195,9 @@ bool swift::findInnerTransitiveGuaranteedUses(
195
195
return true ;
196
196
}
197
197
198
- // / Like findInnerTransitiveGuaranteedUses except that rather than it being a
199
- // / precondition that the provided value not be a BorrowedValue, it is a [type-
200
- // / system-enforced] precondition that the provided value be a BorrowedValue.
201
- // /
202
- // / TODO: Merge with findInnerTransitiveGuaranteedUses. Note that at the moment
203
- // / the two are _almost_ identical, but not quite because the other has a
204
- // / #if 0 and not just leaf uses but ALL uses are recorded.
205
- bool swift::findInnerTransitiveGuaranteedUsesOfBorrowedValue (
198
+ // / Find all uses in the extended lifetime (i.e. including copies) of a simple
199
+ // / (i.e. not reborrowed) borrow scope and its transitive uses.
200
+ bool swift::findExtendedUsesOfSimpleBorrowedValue (
206
201
BorrowedValue borrowedValue, SmallVectorImpl<Operand *> *usePoints) {
207
202
208
203
auto recordUse = [&](Operand *use) {
@@ -220,21 +215,31 @@ bool swift::findInnerTransitiveGuaranteedUsesOfBorrowedValue(
220
215
// membership check locally in this function (within a borrow scope) because
221
216
// it isn't needed for the immediate uses, only the transitive uses.
222
217
GraphNodeWorklist<Operand *, 8 > worklist;
223
- for (Operand *use : borrowedValue.value ->getUses ()) {
224
- if (use->getOperandOwnership () != OperandOwnership::NonUse)
225
- worklist.insert (use);
226
- }
218
+ auto addUsesToWorklist = [&worklist](SILValue value) {
219
+ for (Operand *use : value->getUses ()) {
220
+ if (use->getOperandOwnership () != OperandOwnership::NonUse)
221
+ worklist.insert (use);
222
+ }
223
+ };
224
+
225
+ addUsesToWorklist (borrowedValue.value );
227
226
228
227
// --- Transitively follow forwarded uses and look for escapes.
229
228
230
229
// usePoints grows in this loop.
231
230
while (Operand *use = worklist.pop ()) {
231
+ if (auto *cvi = dyn_cast<CopyValueInst>(use->getUser ())) {
232
+ addUsesToWorklist (cvi);
233
+ }
232
234
switch (use->getOperandOwnership ()) {
233
235
case OperandOwnership::NonUse:
236
+ break ;
237
+
234
238
case OperandOwnership::TrivialUse:
235
239
case OperandOwnership::ForwardingConsume:
236
240
case OperandOwnership::DestroyingConsume:
237
- llvm_unreachable (" this operand cannot handle an inner guaranteed use" );
241
+ recordUse (use);
242
+ break ;
238
243
239
244
case OperandOwnership::ForwardingUnowned:
240
245
case OperandOwnership::PointerEscape:
@@ -264,6 +269,7 @@ bool swift::findInnerTransitiveGuaranteedUsesOfBorrowedValue(
264
269
AddressUseKind::NonEscaping) {
265
270
return false ;
266
271
}
272
+ recordUse (use);
267
273
break ;
268
274
269
275
case OperandOwnership::ForwardingBorrow: {
0 commit comments