@@ -3231,19 +3231,40 @@ class StoreInst
3231
3231
}
3232
3232
};
3233
3233
3234
+ class EndBorrowInst ;
3235
+
3236
+ struct UseToEndBorrow {
3237
+ Optional<EndBorrowInst *> operator ()(Operand *use) const {
3238
+ if (auto endBorrow = dyn_cast<EndBorrowInst>(use->getUser ())) {
3239
+ return endBorrow;
3240
+ } else {
3241
+ return None;
3242
+ }
3243
+ }
3244
+ };
3245
+
3234
3246
// / Represents a load of a borrowed value. Must be paired with an end_borrow
3235
3247
// / instruction in its use-def list.
3236
3248
class LoadBorrowInst :
3237
3249
public UnaryInstructionBase<SILInstructionKind::LoadBorrowInst,
3238
3250
SingleValueInstruction> {
3239
3251
friend class SILBuilder ;
3240
3252
3253
+ public:
3241
3254
LoadBorrowInst (SILDebugLocation DebugLoc, SILValue LValue)
3242
3255
: UnaryInstructionBase(DebugLoc, LValue,
3243
3256
LValue->getType ().getObjectType()) {}
3257
+
3258
+ using EndBorrowRange =
3259
+ OptionalTransformRange<use_range, UseToEndBorrow, use_iterator>;
3260
+
3261
+ // / Return a range over all EndBorrow instructions for this BeginBorrow.
3262
+ EndBorrowRange getEndBorrows () const ;
3244
3263
};
3245
3264
3246
- class EndBorrowInst ;
3265
+ inline auto LoadBorrowInst::getEndBorrows () const -> EndBorrowRange {
3266
+ return EndBorrowRange (getUses (), UseToEndBorrow ());
3267
+ }
3247
3268
3248
3269
// / Represents the begin scope of a borrowed value. Must be paired with an
3249
3270
// / end_borrow instruction in its use-def list.
@@ -3252,9 +3273,6 @@ class BeginBorrowInst
3252
3273
SingleValueInstruction> {
3253
3274
friend class SILBuilder ;
3254
3275
3255
- // / Predicate used to filter EndBorrowRange.
3256
- struct UseToEndBorrow ;
3257
-
3258
3276
BeginBorrowInst (SILDebugLocation DebugLoc, SILValue LValue)
3259
3277
: UnaryInstructionBase(DebugLoc, LValue,
3260
3278
LValue->getType ().getObjectType()) {}
@@ -3275,6 +3293,10 @@ class BeginBorrowInst
3275
3293
Operand *getSingleNonEndingUse () const ;
3276
3294
};
3277
3295
3296
+ inline auto BeginBorrowInst::getEndBorrows () const -> EndBorrowRange {
3297
+ return EndBorrowRange (getUses (), UseToEndBorrow ());
3298
+ }
3299
+
3278
3300
// / Represents a store of a borrowed value into an address. Returns the borrowed
3279
3301
// / address. Must be paired with an end_borrow in its use-def list.
3280
3302
class StoreBorrowInst
@@ -3364,20 +3386,6 @@ class EndBorrowInst
3364
3386
}
3365
3387
};
3366
3388
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
-
3381
3389
// / Different kinds of access.
3382
3390
enum class SILAccessKind : uint8_t {
3383
3391
// / An access which takes uninitialized memory and initializes it.
0 commit comments