@@ -643,6 +643,12 @@ struct OwnershipLifetimeExtender {
643
643
SILBasicBlock::iterator borrowPoint,
644
644
RangeTy guaranteedUsePoints);
645
645
646
+ template <typename RangeTy>
647
+ BeginBorrowInst *
648
+ borrowCopyOverGuaranteedUsers (SILValue newValue,
649
+ SILBasicBlock::iterator borrowPoint,
650
+ RangeTy guaranteedUsers);
651
+
646
652
// / Borrow \p newValue over the lifetime of \p guaranteedValue. Return the
647
653
// / new guaranteed value.
648
654
SILValue borrowOverValue (SILValue newValue, SILValue guaranteedValue);
@@ -654,6 +660,10 @@ struct OwnershipLifetimeExtender {
654
660
// / the BorrowedValue that begins the scope.
655
661
SILValue borrowOverSingleUse (SILValue newValue,
656
662
Operand *singleGuaranteedUse);
663
+
664
+ SILValue
665
+ borrowOverSingleNonLifetimeEndingUser (SILValue newValue,
666
+ SILInstruction *nonLifetimeEndingUser);
657
667
};
658
668
659
669
} // end anonymous namespace
@@ -780,9 +790,9 @@ OwnershipLifetimeExtender::borrowCopyOverScope(SILValue newValue,
780
790
// /
781
791
// / Precondition: None of \p guaranteedUses are lifetime ending.
782
792
template <typename RangeTy>
783
- BeginBorrowInst *OwnershipLifetimeExtender::borrowCopyOverGuaranteedUses (
793
+ BeginBorrowInst *OwnershipLifetimeExtender::borrowCopyOverGuaranteedUsers (
784
794
SILValue newValue, SILBasicBlock::iterator borrowPoint,
785
- RangeTy guaranteedUsePoints ) {
795
+ RangeTy guaranteedUsers ) {
786
796
787
797
auto loc = RegularLocation::getAutoGeneratedLocation (borrowPoint->getLoc ());
788
798
@@ -794,12 +804,11 @@ BeginBorrowInst *OwnershipLifetimeExtender::borrowCopyOverGuaranteedUses(
794
804
795
805
// Create end_borrows at the end of the borrow's lifetime.
796
806
{
797
- // We don't expect an empty guaranteedUsePoints . If it happens, then the
807
+ // We don't expect an empty guaranteedUsers . If it happens, then the
798
808
// newly created copy will never be destroyed.
799
- assert (!guaranteedUsePoints .empty ());
809
+ assert (!guaranteedUsers .empty ());
800
810
801
- auto opRange = makeUserRange (guaranteedUsePoints);
802
- ValueLifetimeAnalysis lifetimeAnalysis (borrow, opRange);
811
+ ValueLifetimeAnalysis lifetimeAnalysis (borrow, guaranteedUsers);
803
812
ValueLifetimeBoundary borrowBoundary;
804
813
lifetimeAnalysis.computeLifetimeBoundary (borrowBoundary);
805
814
@@ -834,6 +843,14 @@ BeginBorrowInst *OwnershipLifetimeExtender::borrowCopyOverGuaranteedUses(
834
843
return borrow;
835
844
}
836
845
846
+ template <typename RangeTy>
847
+ BeginBorrowInst *OwnershipLifetimeExtender::borrowCopyOverGuaranteedUses (
848
+ SILValue newValue, SILBasicBlock::iterator borrowPoint,
849
+ RangeTy guaranteedUsePoints) {
850
+ return borrowCopyOverGuaranteedUsers (newValue, borrowPoint,
851
+ makeUserRange (guaranteedUsePoints));
852
+ }
853
+
837
854
// Return the borrow position when replacing guaranteedValue with newValue.
838
855
//
839
856
// Precondition: newValue's block dominates and reaches guaranteedValue's block.
@@ -944,6 +961,18 @@ OwnershipLifetimeExtender::borrowOverSingleUse(SILValue newValue,
944
961
return newBeginBorrow;
945
962
}
946
963
964
+ SILValue OwnershipLifetimeExtender::borrowOverSingleNonLifetimeEndingUser (
965
+ SILValue newValue, SILInstruction *nonLifetimeEndingUser) {
966
+ // Avoid borrowing guaranteed function arguments.
967
+ if (isa<SILFunctionArgument>(newValue) &&
968
+ newValue.getOwnershipKind () == OwnershipKind::Guaranteed) {
969
+ return newValue;
970
+ }
971
+ auto borrowPt = newValue->getNextInstruction ()->getIterator ();
972
+ return borrowCopyOverGuaranteedUsers (
973
+ newValue, borrowPt, ArrayRef<SILInstruction *>(nonLifetimeEndingUser));
974
+ }
975
+
947
976
// ===----------------------------------------------------------------------===//
948
977
// OwnershipRAUWUtility - RAUW + fix ownership
949
978
// ===----------------------------------------------------------------------===//
0 commit comments