@@ -505,63 +505,69 @@ void OwnershipLiveRange::insertEndBorrowsAtDestroys(
505
505
}
506
506
}
507
507
508
- void OwnershipLiveRange::convertOwnedGeneralForwardingUsesToGuaranteed () && {
509
- while (!ownershipForwardingUses.empty ()) {
510
- auto *i = ownershipForwardingUses.back ()->getUser ();
511
- ownershipForwardingUses = ownershipForwardingUses.drop_back ();
512
-
513
- // If this is a term inst, just convert all of its incoming values that are
514
- // owned to be guaranteed.
515
- if (auto *ti = dyn_cast<TermInst>(i)) {
516
- for (auto &succ : ti->getSuccessors ()) {
517
- auto *succBlock = succ.getBB ();
508
+ static void convertInstructionOwnership (SILInstruction *i,
509
+ ValueOwnershipKind oldOwnership,
510
+ ValueOwnershipKind newOwnership) {
511
+ // If this is a term inst, just convert all of its incoming values that are
512
+ // owned to be guaranteed.
513
+ if (auto *ti = dyn_cast<TermInst>(i)) {
514
+ for (auto &succ : ti->getSuccessors ()) {
515
+ auto *succBlock = succ.getBB ();
518
516
519
- // If we do not have any arguments, then continue.
520
- if (succBlock->args_empty ())
521
- continue ;
517
+ // If we do not have any arguments, then continue.
518
+ if (succBlock->args_empty ())
519
+ continue ;
522
520
523
- for (auto *succArg : succBlock->getSILPhiArguments ()) {
524
- // If we have an any value, just continue.
525
- if (succArg->getOwnershipKind () == ValueOwnershipKind::Owned) {
526
- succArg->setOwnershipKind (ValueOwnershipKind::Guaranteed);
527
- }
521
+ for (auto *succArg : succBlock->getSILPhiArguments ()) {
522
+ // If we have an any value, just continue.
523
+ if (succArg->getOwnershipKind () == oldOwnership) {
524
+ succArg->setOwnershipKind (newOwnership);
528
525
}
529
526
}
530
- continue ;
531
527
}
528
+ return ;
529
+ }
532
530
533
- assert (i->hasResults ());
534
- for (SILValue result : i->getResults ()) {
535
- if (auto *svi = dyn_cast<OwnershipForwardingSingleValueInst>(result)) {
536
- if (svi->getOwnershipKind () == ValueOwnershipKind::Owned) {
537
- svi->setOwnershipKind (ValueOwnershipKind::Guaranteed);
538
- }
539
- continue ;
531
+ assert (i->hasResults ());
532
+ for (SILValue result : i->getResults ()) {
533
+ if (auto *svi = dyn_cast<OwnershipForwardingSingleValueInst>(result)) {
534
+ if (svi->getOwnershipKind () == oldOwnership) {
535
+ svi->setOwnershipKind (newOwnership);
540
536
}
537
+ continue ;
538
+ }
541
539
542
- if (auto *ofci = dyn_cast<OwnershipForwardingConversionInst>(result)) {
543
- if (ofci->getOwnershipKind () == ValueOwnershipKind::Owned) {
544
- ofci->setOwnershipKind (ValueOwnershipKind::Guaranteed);
545
- }
546
- continue ;
540
+ if (auto *ofci = dyn_cast<OwnershipForwardingConversionInst>(result)) {
541
+ if (ofci->getOwnershipKind () == oldOwnership) {
542
+ ofci->setOwnershipKind (newOwnership);
547
543
}
544
+ continue ;
545
+ }
548
546
549
- if (auto *sei = dyn_cast<OwnershipForwardingSelectEnumInstBase>(result)) {
550
- if (sei->getOwnershipKind () == ValueOwnershipKind::Owned) {
551
- sei->setOwnershipKind (ValueOwnershipKind::Guaranteed);
552
- }
553
- continue ;
547
+ if (auto *sei = dyn_cast<OwnershipForwardingSelectEnumInstBase>(result)) {
548
+ if (sei->getOwnershipKind () == oldOwnership) {
549
+ sei->setOwnershipKind (newOwnership);
554
550
}
551
+ continue ;
552
+ }
555
553
556
- if (auto *mvir = dyn_cast<MultipleValueInstructionResult>(result)) {
557
- if (mvir->getOwnershipKind () == ValueOwnershipKind::Owned) {
558
- mvir->setOwnershipKind (ValueOwnershipKind::Guaranteed);
559
- }
560
- continue ;
554
+ if (auto *mvir = dyn_cast<MultipleValueInstructionResult>(result)) {
555
+ if (mvir->getOwnershipKind () == oldOwnership) {
556
+ mvir->setOwnershipKind (newOwnership);
561
557
}
562
-
563
- llvm_unreachable (" unhandled forwarding instruction?!" );
558
+ continue ;
564
559
}
560
+
561
+ llvm_unreachable (" unhandled forwarding instruction?!" );
562
+ }
563
+ }
564
+
565
+ void OwnershipLiveRange::convertOwnedGeneralForwardingUsesToGuaranteed () && {
566
+ while (!ownershipForwardingUses.empty ()) {
567
+ auto *i = ownershipForwardingUses.back ()->getUser ();
568
+ ownershipForwardingUses = ownershipForwardingUses.drop_back ();
569
+ convertInstructionOwnership (i, ValueOwnershipKind::Owned,
570
+ ValueOwnershipKind::Guaranteed);
565
571
}
566
572
}
567
573
0 commit comments