@@ -693,59 +693,34 @@ bool BorrowingOperand::visitExtendedScopeEndingUses(
693
693
function_ref<bool (Operand *)> visitor) const {
694
694
695
695
if (hasBorrowIntroducingUser ()) {
696
- return visitBorrowIntroducingUserResults (
697
- [visitor](BorrowedValue borrowedValue) {
698
- return borrowedValue.visitExtendedScopeEndingUses (visitor);
699
- });
696
+ auto borrowedValue = getBorrowIntroducingUserResult ();
697
+ return borrowedValue.visitExtendedScopeEndingUses (visitor);
700
698
}
701
699
return visitScopeEndingUses (visitor);
702
700
}
703
701
704
- bool BorrowingOperand::visitBorrowIntroducingUserResults (
705
- function_ref<bool (BorrowedValue)> visitor) const {
702
+ BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult () const {
706
703
switch (kind) {
707
704
case BorrowingOperandKind::Invalid:
708
- llvm_unreachable (" Using invalid case" );
709
705
case BorrowingOperandKind::Apply:
710
706
case BorrowingOperandKind::TryApply:
711
707
case BorrowingOperandKind::BeginApply:
712
708
case BorrowingOperandKind::Yield:
713
709
case BorrowingOperandKind::PartialApplyStack:
714
710
case BorrowingOperandKind::BeginAsyncLet:
715
- llvm_unreachable (" Never has borrow introducer results!" );
711
+ return BorrowedValue ();
712
+
716
713
case BorrowingOperandKind::BeginBorrow: {
717
714
auto value = BorrowedValue (cast<BeginBorrowInst>(op->getUser ()));
718
715
assert (value);
719
- return visitor ( value) ;
716
+ return value;
720
717
}
721
718
case BorrowingOperandKind::Branch: {
722
719
auto *bi = cast<BranchInst>(op->getUser ());
723
- auto value = BorrowedValue (
724
- bi->getDestBB ()->getArgument (op->getOperandNumber ()));
720
+ auto value =
721
+ BorrowedValue ( bi->getDestBB ()->getArgument (op->getOperandNumber ()));
725
722
assert (value && " guaranteed-to-unowned conversion not allowed on branches" );
726
- return visitor (value);
727
- }
728
- }
729
- llvm_unreachable (" Covered switch isn't covered?!" );
730
- }
731
-
732
- BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult () {
733
- switch (kind) {
734
- case BorrowingOperandKind::Invalid:
735
- case BorrowingOperandKind::Apply:
736
- case BorrowingOperandKind::TryApply:
737
- case BorrowingOperandKind::BeginApply:
738
- case BorrowingOperandKind::Yield:
739
- case BorrowingOperandKind::PartialApplyStack:
740
- case BorrowingOperandKind::BeginAsyncLet:
741
- return BorrowedValue ();
742
-
743
- case BorrowingOperandKind::BeginBorrow:
744
- return BorrowedValue (cast<BeginBorrowInst>(op->getUser ()));
745
-
746
- case BorrowingOperandKind::Branch: {
747
- auto *bi = cast<BranchInst>(op->getUser ());
748
- return BorrowedValue (bi->getDestBB ()->getArgument (op->getOperandNumber ()));
723
+ return value;
749
724
}
750
725
}
751
726
llvm_unreachable (" covered switch" );
@@ -919,11 +894,9 @@ bool BorrowedValue::visitExtendedScopeEndingUses(
919
894
920
895
auto visitEnd = [&](Operand *scopeEndingUse) {
921
896
if (scopeEndingUse->getOperandOwnership () == OperandOwnership::Reborrow) {
922
- BorrowingOperand (scopeEndingUse).visitBorrowIntroducingUserResults (
923
- [&](BorrowedValue borrowedValue) {
924
- reborrows.insert (borrowedValue.value );
925
- return true ;
926
- });
897
+ auto borrowedValue =
898
+ BorrowingOperand (scopeEndingUse).getBorrowIntroducingUserResult ();
899
+ reborrows.insert (borrowedValue.value );
927
900
return true ;
928
901
}
929
902
return visitor (scopeEndingUse);
@@ -948,11 +921,9 @@ bool BorrowedValue::visitTransitiveLifetimeEndingUses(
948
921
949
922
auto visitEnd = [&](Operand *scopeEndingUse) {
950
923
if (scopeEndingUse->getOperandOwnership () == OperandOwnership::Reborrow) {
951
- BorrowingOperand (scopeEndingUse)
952
- .visitBorrowIntroducingUserResults ([&](BorrowedValue borrowedValue) {
953
- reborrows.insert (borrowedValue.value );
954
- return true ;
955
- });
924
+ auto borrowedValue =
925
+ BorrowingOperand (scopeEndingUse).getBorrowIntroducingUserResult ();
926
+ reborrows.insert (borrowedValue.value );
956
927
// visitor on the reborrow
957
928
return visitor (scopeEndingUse);
958
929
}
@@ -1003,16 +974,14 @@ bool BorrowedValue::visitInteriorPointerOperandHelper(
1003
974
break ;
1004
975
}
1005
976
1006
- borrowingOperand.visitBorrowIntroducingUserResults ([&](auto bv) {
1007
- for (auto *use : bv->getUses ()) {
1008
- if (auto intPtrOperand = InteriorPointerOperand (use)) {
1009
- func (intPtrOperand);
1010
- continue ;
1011
- }
1012
- worklist.push_back (use);
977
+ auto bv = borrowingOperand.getBorrowIntroducingUserResult ();
978
+ for (auto *use : bv->getUses ()) {
979
+ if (auto intPtrOperand = InteriorPointerOperand (use)) {
980
+ func (intPtrOperand);
981
+ continue ;
1013
982
}
1014
- return true ;
1015
- });
983
+ worklist. push_back (use) ;
984
+ }
1016
985
continue ;
1017
986
}
1018
987
0 commit comments