@@ -47,6 +47,8 @@ class ShrinkBorrowScope {
4747
4848 InstructionDeleter &deleter;
4949
50+ SmallVectorImpl<CopyValueInst *> &modifiedCopyValueInsts;
51+
5052 SmallPtrSet<SILInstruction *, 16 > users;
5153 llvm::SmallVector<std::pair<SILBasicBlock *, SILInstruction *>>
5254 barrierInstructions;
@@ -66,8 +68,10 @@ class ShrinkBorrowScope {
6668 llvm::SmallDenseMap<SILBasicBlock *, SILInstruction *> startingInstructions;
6769
6870public:
69- ShrinkBorrowScope (BeginBorrowInst *bbi, InstructionDeleter &deleter)
70- : introducer(bbi), deleter(deleter) {}
71+ ShrinkBorrowScope (BeginBorrowInst *bbi, InstructionDeleter &deleter,
72+ SmallVectorImpl<CopyValueInst *> &modifiedCopyValueInsts)
73+ : introducer(bbi), deleter(deleter),
74+ modifiedCopyValueInsts (modifiedCopyValueInsts) {}
7175
7276 bool run ();
7377
@@ -156,6 +160,7 @@ class ShrinkBorrowScope {
156160 auto borrowee = introducer->getOperand ();
157161 if (auto *cvi = dyn_cast<CopyValueInst>(argument)) {
158162 cvi->setOperand (borrowee);
163+ modifiedCopyValueInsts.push_back (cvi);
159164 } else {
160165 apply.setArgument (index, borrowee);
161166 }
@@ -172,6 +177,7 @@ class ShrinkBorrowScope {
172177 if (canReplaceValueWithBorrowedValue (cvi->getOperand ())) {
173178 auto borrowee = introducer->getOperand ();
174179 cvi->setOperand (borrowee);
180+ modifiedCopyValueInsts.push_back (cvi);
175181 return true ;
176182 }
177183 }
@@ -318,8 +324,9 @@ void ShrinkBorrowScope::createEndBorrow(SILInstruction *insertionPoint) {
318324 introducer);
319325}
320326
321- bool swift::shrinkBorrowScope (BeginBorrowInst *bbi,
322- InstructionDeleter &deleter) {
323- ShrinkBorrowScope borrowShrinker (bbi, deleter);
327+ bool swift::shrinkBorrowScope (
328+ BeginBorrowInst *bbi, InstructionDeleter &deleter,
329+ SmallVectorImpl<CopyValueInst *> &modifiedCopyValueInsts) {
330+ ShrinkBorrowScope borrowShrinker (bbi, deleter, modifiedCopyValueInsts);
324331 return borrowShrinker.run ();
325332}
0 commit comments