Skip to content

Commit 52cd817

Browse files
committed
Implement InteriorLivenessVisitor::handleInnerBorrow for all BorrowingOperand kinds
Not all BorrowingOperand introduce a BorrowedValue. Add a new api to get the defining value for use in InteriorLivenessVisitor::handleInnerBorrow.
1 parent 6cefbb3 commit 52cd817

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ struct BorrowingOperand {
475475
/// valid BorrowedValue instance.
476476
BorrowedValue getBorrowIntroducingUserResult();
477477

478+
/// Return the borrowing operand's value.
479+
SILValue getIntroducingUserResult();
480+
478481
/// Compute the implicit uses that this borrowing operand "injects" into the
479482
/// set of its operands uses.
480483
///

lib/SIL/Utils/OwnershipLiveness.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ struct InteriorLivenessVisitor :
140140
/// Handles begin_borrow, load_borrow, store_borrow, begin_apply.
141141
bool handleInnerBorrow(BorrowingOperand borrowingOperand) {
142142
if (handleInnerScopeCallback) {
143-
handleInnerScopeCallback(
144-
borrowingOperand.getBorrowIntroducingUserResult().value);
143+
handleInnerScopeCallback(borrowingOperand.getIntroducingUserResult());
145144
}
146145
return true;
147146
}

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,30 @@ BorrowedValue BorrowingOperand::getBorrowIntroducingUserResult() {
751751
llvm_unreachable("covered switch");
752752
}
753753

754+
SILValue BorrowingOperand::getIntroducingUserResult() {
755+
switch (kind) {
756+
case BorrowingOperandKind::Invalid:
757+
case BorrowingOperandKind::Yield:
758+
return SILValue();
759+
760+
case BorrowingOperandKind::Apply:
761+
case BorrowingOperandKind::TryApply:
762+
case BorrowingOperandKind::BeginAsyncLet:
763+
case BorrowingOperandKind::PartialApplyStack:
764+
case BorrowingOperandKind::BeginBorrow:
765+
return cast<SingleValueInstruction>(op->getUser());
766+
767+
case BorrowingOperandKind::BeginApply:
768+
return cast<BeginApplyInst>(op->getUser())->getTokenResult();
769+
770+
case BorrowingOperandKind::Branch: {
771+
PhiOperand phiOp(op);
772+
return phiOp.getValue();
773+
}
774+
}
775+
llvm_unreachable("covered switch");
776+
}
777+
754778
void BorrowingOperand::getImplicitUses(
755779
SmallVectorImpl<Operand *> &foundUses) const {
756780
// FIXME: this visitScopeEndingUses should never return false once dead

0 commit comments

Comments
 (0)