@@ -100,8 +100,8 @@ insertOwnedBaseValueAlongBranchEdge(BranchInst *bi, SILValue innerCopy,
100
100
}
101
101
102
102
static bool findTransitiveBorrowedUses (
103
- SILValue value, SmallVectorImpl<Operand *> &usePoints,
104
- SmallVectorImpl<BorrowingOperand > &reborrowPoints) {
103
+ SILValue value, SmallVectorImpl<Operand *> &usePoints,
104
+ SmallVectorImpl<std::pair<SILBasicBlock *, unsigned > > &reborrowPoints) {
105
105
assert (value.getOwnershipKind () == OwnershipKind::Guaranteed);
106
106
107
107
unsigned firstOffset = usePoints.size ();
@@ -165,7 +165,9 @@ static bool findTransitiveBorrowedUses(
165
165
[&](Operand *scopeEndingUse) {
166
166
if (auto scopeEndingBorrowingOp = BorrowingOperand (scopeEndingUse)) {
167
167
if (scopeEndingBorrowingOp.isReborrow ()) {
168
- reborrowPoints.push_back (scopeEndingUse);
168
+ auto *branch = scopeEndingUse->getUser ();
169
+ reborrowPoints.push_back (
170
+ {branch->getParent (), scopeEndingUse->getOperandNumber ()});
169
171
return true ;
170
172
}
171
173
}
@@ -430,18 +432,20 @@ OwnershipLifetimeExtender::createPlusZeroBorrow(SILValue newValue,
430
432
// ===----------------------------------------------------------------------===//
431
433
432
434
static void eliminateReborrowsOfRecursiveBorrows (
433
- ArrayRef<BorrowingOperand > transitiveReborrows,
435
+ ArrayRef<std::pair<SILBasicBlock *, unsigned > > transitiveReborrows,
434
436
SmallVectorImpl<Operand *> &usePoints, InstModCallbacks &callbacks) {
435
437
SmallVector<std::pair<SILPhiArgument *, SILPhiArgument *>, 8 >
436
438
baseBorrowedValuePair;
437
439
// Ok, we have transitive reborrows.
438
- for (auto borrowingOperand : transitiveReborrows) {
440
+ for (auto it : transitiveReborrows) {
439
441
// We eliminate the reborrow by creating a new copy+borrow at the reborrow
440
442
// edge from the base value and using that for the reborrow instead of the
441
443
// actual value. We of course insert an end_borrow for our original incoming
442
444
// value.
445
+ auto *bi = cast<BranchInst>(it.first ->getTerminator ());
446
+ auto &op = bi->getOperandRef (it.second );
447
+ BorrowingOperand borrowingOperand (&op);
443
448
SILValue value = borrowingOperand->get ();
444
- auto *bi = cast<BranchInst>(borrowingOperand->getUser ());
445
449
SILBuilderWithScope reborrowBuilder (bi);
446
450
// Use an auto-generated location here, because the branch may have an
447
451
// incompatible LocationKind
@@ -501,15 +505,19 @@ static void eliminateReborrowsOfRecursiveBorrows(
501
505
}
502
506
}
503
507
504
- static void rewriteReborrows (SILValue newBorrowedValue,
505
- ArrayRef<BorrowingOperand> foundReborrows,
506
- InstModCallbacks &callbacks) {
508
+ static void
509
+ rewriteReborrows (SILValue newBorrowedValue,
510
+ ArrayRef<std::pair<SILBasicBlock *, unsigned >> foundReborrows,
511
+ InstModCallbacks &callbacks) {
507
512
// Each initial reborrow that we have is a use of oldValue, so we know
508
513
// that copy should be valid at the reborrow.
509
514
SmallVector<std::pair<SILPhiArgument *, SILPhiArgument *>, 8 >
510
515
baseBorrowedValuePair;
511
- for (auto reborrow : foundReborrows) {
512
- auto *bi = cast<BranchInst>(reborrow.op ->getUser ());
516
+ for (auto it : foundReborrows) {
517
+ auto *bi = cast<BranchInst>(it.first ->getTerminator ());
518
+ auto &op = bi->getOperandRef (it.second );
519
+ BorrowingOperand reborrow (&op);
520
+
513
521
SILBuilderWithScope reborrowBuilder (bi);
514
522
// Use an auto-generated location here, because the branch may have an
515
523
// incompatible LocationKind
@@ -713,7 +721,7 @@ SILBasicBlock::iterator OwnershipRAUWUtility::handleGuaranteed() {
713
721
// non-dominating copy value, allowing us to force our borrowing value to
714
722
// need a base phi argument (the one of our choosing).
715
723
if (auto oldValueBorrowedVal = BorrowedValue::get (oldValue)) {
716
- SmallVector<BorrowingOperand , 8 > foundReborrows;
724
+ SmallVector<std::pair<SILBasicBlock *, unsigned > , 8 > foundReborrows;
717
725
if (oldValueBorrowedVal.gatherReborrows (foundReborrows)) {
718
726
rewriteReborrows (newBorrowedValue, foundReborrows, ctx.callbacks );
719
727
}
0 commit comments