@@ -47,6 +47,8 @@ class ShrinkBorrowScope {
47
47
48
48
InstructionDeleter &deleter;
49
49
50
+ SmallVectorImpl<CopyValueInst *> &modifiedCopyValueInsts;
51
+
50
52
SmallPtrSet<SILInstruction *, 16 > users;
51
53
llvm::SmallVector<std::pair<SILBasicBlock *, SILInstruction *>>
52
54
barrierInstructions;
@@ -66,8 +68,10 @@ class ShrinkBorrowScope {
66
68
llvm::SmallDenseMap<SILBasicBlock *, SILInstruction *> startingInstructions;
67
69
68
70
public:
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) {}
71
75
72
76
bool run ();
73
77
@@ -156,6 +160,7 @@ class ShrinkBorrowScope {
156
160
auto borrowee = introducer->getOperand ();
157
161
if (auto *cvi = dyn_cast<CopyValueInst>(argument)) {
158
162
cvi->setOperand (borrowee);
163
+ modifiedCopyValueInsts.push_back (cvi);
159
164
} else {
160
165
apply.setArgument (index, borrowee);
161
166
}
@@ -172,6 +177,7 @@ class ShrinkBorrowScope {
172
177
if (canReplaceValueWithBorrowedValue (cvi->getOperand ())) {
173
178
auto borrowee = introducer->getOperand ();
174
179
cvi->setOperand (borrowee);
180
+ modifiedCopyValueInsts.push_back (cvi);
175
181
return true ;
176
182
}
177
183
}
@@ -318,8 +324,9 @@ void ShrinkBorrowScope::createEndBorrow(SILInstruction *insertionPoint) {
318
324
introducer);
319
325
}
320
326
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);
324
331
return borrowShrinker.run ();
325
332
}
0 commit comments