@@ -170,6 +170,15 @@ struct BorrowingOperand {
170170 return *this ;
171171 }
172172
173+ // A set of operators so that a BorrowingOperand can be used like a normal
174+ // operand in a light weight way.
175+ operator const Operand *() const { return op; }
176+ operator Operand *() { return op; }
177+ const Operand *operator *() const { return op; }
178+ Operand *operator *() { return op; }
179+ const Operand *operator ->() const { return op; }
180+ Operand *operator ->() { return op; }
181+
173182 // / If \p op is a borrow introducing operand return it after doing some
174183 // / checks.
175184 static Optional<BorrowingOperand> get (Operand *op) {
@@ -425,7 +434,7 @@ struct BorrowedValue {
425434 // /
426435 // / NOTE: Scratch space is used internally to this method to store the end
427436 // / borrow scopes if needed.
428- bool areUsesWithinScope (ArrayRef<Operand *> instructions ,
437+ bool areUsesWithinScope (ArrayRef<Operand *> uses ,
429438 SmallVectorImpl<Operand *> &scratchSpace,
430439 SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
431440 DeadEndBlocks &deadEndBlocks) const ;
@@ -447,6 +456,24 @@ struct BorrowedValue {
447456 bool visitInteriorPointerOperands (
448457 function_ref<void (const InteriorPointerOperand &)> func) const ;
449458
459+ // / Visit all immediate uses of this borrowed value and if any of them are
460+ // / reborrows, place them in BorrowingOperand form into \p
461+ // / foundReborrows. Returns true if we appended any such reborrows to
462+ // / foundReborrows... false otherwise.
463+ bool
464+ gatherReborrows (SmallVectorImpl<BorrowingOperand> &foundReborrows) const {
465+ bool foundAnyReborrows = false ;
466+ for (auto *op : value->getUses ()) {
467+ if (auto borrowingOperand = BorrowingOperand::get (op)) {
468+ if (borrowingOperand->isReborrow ()) {
469+ foundReborrows.push_back (*borrowingOperand);
470+ foundAnyReborrows = true ;
471+ }
472+ }
473+ }
474+ return foundAnyReborrows;
475+ }
476+
450477private:
451478 // / Internal constructor for failable static constructor. Please do not expand
452479 // / its usage since it assumes the code passed in is well formed.
0 commit comments