@@ -3252,11 +3252,20 @@ class BeginBorrowInst
3252
3252
SingleValueInstruction> {
3253
3253
friend class SILBuilder ;
3254
3254
3255
+ // / Predicate used to filter EndBorrowRange.
3256
+ struct UseToEndBorrow ;
3257
+
3255
3258
BeginBorrowInst (SILDebugLocation DebugLoc, SILValue LValue)
3256
3259
: UnaryInstructionBase(DebugLoc, LValue,
3257
3260
LValue->getType ().getObjectType()) {}
3258
3261
3259
3262
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
+
3260
3269
// / Return the single use of this BeginBorrowInst, not including any
3261
3270
// / EndBorrowInst uses, or return nullptr if the borrow is dead or has
3262
3271
// / multiple uses.
@@ -3355,6 +3364,20 @@ class EndBorrowInst
3355
3364
}
3356
3365
};
3357
3366
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
+
3358
3381
// / Different kinds of access.
3359
3382
enum class SILAccessKind : uint8_t {
3360
3383
// / An access which takes uninitialized memory and initializes it.
0 commit comments