@@ -505,63 +505,69 @@ void OwnershipLiveRange::insertEndBorrowsAtDestroys(
505505 }
506506}
507507
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 ();
518516
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 ;
522520
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);
528525 }
529526 }
530- continue ;
531527 }
528+ return ;
529+ }
532530
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);
540536 }
537+ continue ;
538+ }
541539
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);
547543 }
544+ continue ;
545+ }
548546
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);
554550 }
551+ continue ;
552+ }
555553
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);
561557 }
562-
563- llvm_unreachable (" unhandled forwarding instruction?!" );
558+ continue ;
564559 }
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);
565571 }
566572}
567573
0 commit comments