Skip to content

Commit 9447d73

Browse files
committed
Add a BeginBorrowInst::getEndBorrows helper.
1 parent ece096d commit 9447d73

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,11 +3252,20 @@ class BeginBorrowInst
32523252
SingleValueInstruction> {
32533253
friend class SILBuilder;
32543254

3255+
/// Predicate used to filter EndBorrowRange.
3256+
struct UseToEndBorrow;
3257+
32553258
BeginBorrowInst(SILDebugLocation DebugLoc, SILValue LValue)
32563259
: UnaryInstructionBase(DebugLoc, LValue,
32573260
LValue->getType().getObjectType()) {}
32583261

32593262
public:
3263+
using EndBorrowRange =
3264+
OptionalTransformRange<use_range, UseToEndBorrow, use_iterator>;
3265+
3266+
/// Return a range over all EndBorrow instructions for this BeginBorrow.
3267+
EndBorrowRange getEndBorrows() const;
3268+
32603269
/// Return the single use of this BeginBorrowInst, not including any
32613270
/// EndBorrowInst uses, or return nullptr if the borrow is dead or has
32623271
/// multiple uses.
@@ -3355,6 +3364,20 @@ class EndBorrowInst
33553364
}
33563365
};
33573366

3367+
struct BeginBorrowInst::UseToEndBorrow {
3368+
Optional<EndBorrowInst *> operator()(Operand *use) const {
3369+
if (auto borrow = dyn_cast<EndBorrowInst>(use->getUser())) {
3370+
return borrow;
3371+
} else {
3372+
return None;
3373+
}
3374+
}
3375+
};
3376+
3377+
inline auto BeginBorrowInst::getEndBorrows() const -> EndBorrowRange {
3378+
return EndBorrowRange(getUses(), UseToEndBorrow());
3379+
}
3380+
33583381
/// Different kinds of access.
33593382
enum class SILAccessKind : uint8_t {
33603383
/// An access which takes uninitialized memory and initializes it.

0 commit comments

Comments
 (0)