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 1414#define SWIFT_SIL_OWNERSHIPUTILS_H
1515
1616#include " swift/Basic/LLVM.h"
17+ #include " swift/SIL/SILArgument.h"
18+ #include " swift/SIL/SILInstruction.h"
1719#include " swift/SIL/SILValue.h"
1820#include " llvm/ADT/SmallPtrSet.h"
1921#include " llvm/ADT/SmallVector.h"
@@ -124,6 +126,27 @@ class LinearLifetimeError {
124126 }
125127};
126128
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+
127150// / Returns true if:
128151// /
129152// / 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
32553255 BeginBorrowInst (SILDebugLocation DebugLoc, SILValue LValue)
32563256 : UnaryInstructionBase(DebugLoc, LValue,
32573257 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- }
32783258};
32793259
3280- inline auto BeginBorrowInst::getEndBorrows () const -> EndBorrowRange {
3281- return EndBorrowRange (getUses (), UseToEndBorrow ());
3282- }
3283-
32843260// / Represents a store of a borrowed value into an address. Returns the borrowed
32853261// / address. Must be paired with an end_borrow in its use-def list.
32863262class StoreBorrowInst
Original file line number Diff line number Diff line change @@ -331,7 +331,7 @@ bool SILValueOwnershipChecker::gatherUsers(
331331 for (unsigned i : indices (nonLifetimeEndingUsers)) {
332332 if (auto *bbi = dyn_cast<BeginBorrowInst>(
333333 nonLifetimeEndingUsers[i].getInst ())) {
334- copy (bbi-> getEndBorrows ( ),
334+ copy (makeEndBorrowRange (bbi ),
335335 std::back_inserter (implicitRegularUsers));
336336 }
337337 }
You can’t perform that action at this time.
0 commit comments