Skip to content

Commit 0989618

Browse files
committed
Add BorrowedFromInst::isReborrow.
borrowed-from instructions have different ownership semantics if the are attached to reborrows vs. guaranteed forwarding phis.
1 parent 0e26cdd commit 0989618

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4782,6 +4782,8 @@ class BorrowedFromInst final : public InstructionBaseWithTrailingOperands<
47824782
OperandValueArrayRef getEnclosingValues() const {
47834783
return OperandValueArrayRef(getEnclosingValueOperands());
47844784
}
4785+
4786+
bool isReborrow() const;
47854787
};
47864788

47874789
inline auto BeginBorrowInst::getEndBorrows() const -> EndBorrowRange {

lib/SIL/IR/SILInstruction.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ Operand *BeginBorrowInst::getSingleNonEndingUse() const {
301301
return singleUse;
302302
}
303303

304+
bool BorrowedFromInst::isReborrow() const {
305+
// The forwarded operand is either a phi or undef.
306+
if (auto *phi = dyn_cast<SILPhiArgument>(getBorrowedValue())) {
307+
return phi->isReborrow();
308+
}
309+
return false;
310+
}
311+
304312
namespace {
305313
class InstructionDestroyer
306314
: public SILInstructionVisitor<InstructionDestroyer> {

0 commit comments

Comments
 (0)