File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -510,18 +510,22 @@ bool SemanticARCOptVisitor::visitBeginBorrowInst(BeginBorrowInst *bbi) {
510
510
auto kind = bbi->getOperand ().getOwnershipKind ();
511
511
SmallVector<EndBorrowInst *, 16 > endBorrows;
512
512
for (auto *op : bbi->getUses ()) {
513
- auto *user = op->getUser ();
514
- switch (user->getKind ()) {
515
- case SILInstructionKind::EndBorrowInst:
516
- endBorrows.push_back (cast<EndBorrowInst>(user));
517
- break ;
518
- default :
513
+ if (!op->isConsumingUse ()) {
519
514
// Make sure that this operand can accept our arguments kind.
520
515
auto map = op->getOwnershipKindMap ();
521
516
if (map.canAcceptKind (kind))
522
517
continue ;
523
518
return false ;
524
519
}
520
+
521
+ // Otherwise, this borrow is being consumed. See if our consuming inst is an
522
+ // end_borrow. If it isn't, then return false, this scope is
523
+ // needed. Otherwise, add the end_borrow to our list of end borrows.
524
+ auto *ebi = dyn_cast<EndBorrowInst>(op->getUser ());
525
+ if (!ebi) {
526
+ return false ;
527
+ }
528
+ endBorrows.push_back (ebi);
525
529
}
526
530
527
531
// At this point, we know that the begin_borrow's operand can be
Original file line number Diff line number Diff line change @@ -1285,3 +1285,20 @@ bb3:
1285
1285
%9999 = tuple()
1286
1286
return %9999 : $()
1287
1287
}
1288
+
1289
+ // TODO: We can support this with time.
1290
+ //
1291
+ // CHECK-LABEL: sil [ossa] @do_eliminate_begin_borrow_consumed_by_guaranteed_phi : $@convention(thin) (@owned Builtin.NativeObject) -> () {
1292
+ // CHECK: begin_borrow
1293
+ // CHECK: } // end sil function 'do_eliminate_begin_borrow_consumed_by_guaranteed_phi'
1294
+ sil [ossa] @do_eliminate_begin_borrow_consumed_by_guaranteed_phi : $@convention(thin) (@owned Builtin.NativeObject) -> () {
1295
+ bb0(%0 : @owned $Builtin.NativeObject):
1296
+ %1 = begin_borrow %0 : $Builtin.NativeObject
1297
+ br bb1(%1 : $Builtin.NativeObject)
1298
+
1299
+ bb1(%2 : @guaranteed $Builtin.NativeObject):
1300
+ end_borrow %2 : $Builtin.NativeObject
1301
+ destroy_value %0 : $Builtin.NativeObject
1302
+ %9999 = tuple()
1303
+ return %9999 : $()
1304
+ }
You can’t perform that action at this time.
0 commit comments