@@ -192,6 +192,17 @@ struct borrowtodestructure::Implementation {
192
192
// / so that we have an independent owned value.
193
193
SILValue initialValue;
194
194
195
+ using InterestingUser = FieldSensitivePrunedLiveness::InterestingUser;
196
+ SmallFrozenMultiMap<SILBasicBlock *, std::pair<Operand *, InterestingUser>, 8 >
197
+ blocksToUses;
198
+
199
+ // / A frozen multi-map we use to diagnose consuming uses that are used by the
200
+ // / same instruction as another consuming use or non-consuming use.
201
+ SmallFrozenMultiMap<SILInstruction *, Operand *, 8 >
202
+ instToInterestingOperandIndexMap;
203
+
204
+ SmallVector<Operand *, 8 > destructureNeedingUses;
205
+
195
206
Implementation (BorrowToDestructureTransform &interface,
196
207
SmallVectorImpl<SILBasicBlock *> &discoveredBlocks)
197
208
: interface(interface),
@@ -303,12 +314,12 @@ bool Implementation::gatherUses(SILValue value) {
303
314
}
304
315
305
316
LLVM_DEBUG (llvm::dbgs () << " Found non lifetime ending use!\n " );
306
- interface. blocksToUses .insert (
317
+ blocksToUses.insert (
307
318
nextUse->getParentBlock (),
308
319
{nextUse, {*leafRange, false /* is lifetime ending*/ }});
309
320
liveness.updateForUse (nextUse->getUser (), *leafRange,
310
321
false /* is lifetime ending*/ );
311
- interface. instToInterestingOperandIndexMap .insert (nextUse->getUser (),
322
+ instToInterestingOperandIndexMap.insert (nextUse->getUser (),
312
323
nextUse);
313
324
continue ;
314
325
}
@@ -329,13 +340,13 @@ bool Implementation::gatherUses(SILValue value) {
329
340
}
330
341
331
342
LLVM_DEBUG (llvm::dbgs () << " Found lifetime ending use!\n " );
332
- interface. destructureNeedingUses .push_back (nextUse);
333
- interface. blocksToUses .insert (
343
+ destructureNeedingUses.push_back (nextUse);
344
+ blocksToUses.insert (
334
345
nextUse->getParentBlock (),
335
346
{nextUse, {*leafRange, true /* is lifetime ending*/ }});
336
347
liveness.updateForUse (nextUse->getUser (), *leafRange,
337
348
true /* is lifetime ending*/ );
338
- interface. instToInterestingOperandIndexMap .insert (nextUse->getUser (),
349
+ instToInterestingOperandIndexMap.insert (nextUse->getUser (),
339
350
nextUse);
340
351
continue ;
341
352
}
@@ -373,11 +384,11 @@ void Implementation::checkForErrorsOnSameInstruction() {
373
384
// At this point, we have emitted all boundary checks. We also now need to
374
385
// check if any of our consuming uses that are on the boundary are used by the
375
386
// same instruction as a different consuming or non-consuming use.
376
- interface. instToInterestingOperandIndexMap .setFrozen ();
387
+ instToInterestingOperandIndexMap.setFrozen ();
377
388
SmallBitVector usedBits (liveness.getNumSubElements ());
378
389
379
390
for (auto instRangePair :
380
- interface. instToInterestingOperandIndexMap .getRange ()) {
391
+ instToInterestingOperandIndexMap.getRange ()) {
381
392
SWIFT_DEFER { usedBits.reset (); };
382
393
383
394
// First loop through our uses and handle any consuming twice errors. We
@@ -487,7 +498,7 @@ void Implementation::checkDestructureUsesOnBoundary() const {
487
498
// needing uses, make sure that none of our destructure needing uses are
488
499
// within our boundary. If so, we have an automatic error since we have a
489
500
// use-after-free.
490
- for (auto *use : interface. destructureNeedingUses ) {
501
+ for (auto *use : destructureNeedingUses) {
491
502
LLVM_DEBUG (llvm::dbgs ()
492
503
<< " DestructureNeedingUse: " << *use->getUser ());
493
504
@@ -1158,7 +1169,7 @@ dumpIntervalMap(IntervalMapAllocator::Map &map) {
1158
1169
#endif
1159
1170
1160
1171
void Implementation::rewriteUses () {
1161
- interface. blocksToUses .setFrozen ();
1172
+ blocksToUses.setFrozen ();
1162
1173
1163
1174
LLVM_DEBUG (llvm::dbgs ()
1164
1175
<< " Performing BorrowToDestructureTransform::rewriteUses()!\n " );
@@ -1189,7 +1200,7 @@ void Implementation::rewriteUses() {
1189
1200
<< " Visiting block bb" << block->getDebugID () << ' \n ' );
1190
1201
1191
1202
// See if we have any operands that we need to process...
1192
- if (auto operandList = interface. blocksToUses .find (block)) {
1203
+ if (auto operandList = blocksToUses.find (block)) {
1193
1204
// If we do, gather up the bits that we need.
1194
1205
for (auto operand : *operandList) {
1195
1206
auto &subEltSpan = operand.second .subEltSpan ;
0 commit comments