File tree Expand file tree Collapse file tree 3 files changed +24
-25
lines changed Expand file tree Collapse file tree 3 files changed +24
-25
lines changed Original file line number Diff line number Diff line change 14
14
#define SWIFT_SIL_OWNERSHIPUTILS_H
15
15
16
16
#include " swift/Basic/LLVM.h"
17
+ #include " swift/SIL/SILArgument.h"
18
+ #include " swift/SIL/SILInstruction.h"
17
19
#include " swift/SIL/SILValue.h"
18
20
#include " llvm/ADT/SmallPtrSet.h"
19
21
#include " llvm/ADT/SmallVector.h"
@@ -124,6 +126,27 @@ class LinearLifetimeError {
124
126
}
125
127
};
126
128
129
+ struct UseToEndBorrow {
130
+ Optional<EndBorrowInst *> operator ()(Operand *use) const {
131
+ if (auto *ebi = dyn_cast<EndBorrowInst>(use->getUser ())) {
132
+ return ebi;
133
+ }
134
+ return None;
135
+ }
136
+ };
137
+
138
+ using EndBorrowRange =
139
+ OptionalTransformRange<ValueBase::use_range, UseToEndBorrow,
140
+ ValueBase::use_iterator>;
141
+
142
+ // / Given a value \p v that is a "borrow" introducer, return its associated
143
+ // / end_borrow users.
144
+ inline auto makeEndBorrowRange (SILValue v) -> EndBorrowRange {
145
+ assert ((isa<BeginBorrowInst>(v) || isa<LoadBorrowInst>(v)) &&
146
+ " Unhandled borrow introducer" );
147
+ return EndBorrowRange (v->getUses (), UseToEndBorrow ());
148
+ }
149
+
127
150
// / Returns true if:
128
151
// /
129
152
// / 1. No consuming uses are reachable from any other consuming use, from any
Original file line number Diff line number Diff line change @@ -3255,32 +3255,8 @@ class BeginBorrowInst
3255
3255
BeginBorrowInst (SILDebugLocation DebugLoc, SILValue LValue)
3256
3256
: UnaryInstructionBase(DebugLoc, LValue,
3257
3257
LValue->getType ().getObjectType()) {}
3258
-
3259
- private:
3260
- // / Predicate used to filer EndBorrowRange.
3261
- struct UseToEndBorrow ;
3262
-
3263
- public:
3264
- using EndBorrowRange =
3265
- OptionalTransformRange<use_range, UseToEndBorrow, use_iterator>;
3266
-
3267
- // / Find all associated end_borrow instructions for this begin_borrow.
3268
- EndBorrowRange getEndBorrows () const ;
3269
- };
3270
-
3271
- struct BeginBorrowInst ::UseToEndBorrow {
3272
- Optional<EndBorrowInst *> operator ()(Operand *use) const {
3273
- if (auto *ebi = dyn_cast<EndBorrowInst>(use->getUser ())) {
3274
- return ebi;
3275
- }
3276
- return None;
3277
- }
3278
3258
};
3279
3259
3280
- inline auto BeginBorrowInst::getEndBorrows () const -> EndBorrowRange {
3281
- return EndBorrowRange (getUses (), UseToEndBorrow ());
3282
- }
3283
-
3284
3260
// / Represents a store of a borrowed value into an address. Returns the borrowed
3285
3261
// / address. Must be paired with an end_borrow in its use-def list.
3286
3262
class StoreBorrowInst
Original file line number Diff line number Diff line change @@ -331,7 +331,7 @@ bool SILValueOwnershipChecker::gatherUsers(
331
331
for (unsigned i : indices (nonLifetimeEndingUsers)) {
332
332
if (auto *bbi = dyn_cast<BeginBorrowInst>(
333
333
nonLifetimeEndingUsers[i].getInst ())) {
334
- copy (bbi-> getEndBorrows ( ),
334
+ copy (makeEndBorrowRange (bbi ),
335
335
std::back_inserter (implicitRegularUsers));
336
336
}
337
337
}
You can’t perform that action at this time.
0 commit comments