@@ -137,8 +137,18 @@ struct borrowtodestructure::Implementation {
137
137
138
138
Optional<AvailableValueStore> blockToAvailableValues;
139
139
140
- Implementation (BorrowToDestructureTransform &interface)
141
- : interface(interface) {}
140
+ // Temporarily optional as this code is refactored.
141
+ FieldSensitiveSSAPrunedLiveRange liveness;
142
+
143
+ Implementation (BorrowToDestructureTransform &interface,
144
+ SmallVectorImpl<SILBasicBlock *> &discoveredBlocks)
145
+ : interface(interface),
146
+ liveness (interface.mmci->getFunction (), &discoveredBlocks) {}
147
+
148
+ void init (SILValue rootAddress) {
149
+ liveness.init (rootAddress);
150
+ liveness.initializeDef (rootAddress, TypeTreeLeafTypeRange (rootAddress));
151
+ }
142
152
143
153
bool gatherUses (SILValue value);
144
154
@@ -236,8 +246,8 @@ bool Implementation::gatherUses(SILValue value) {
236
246
interface.blocksToUses .insert (
237
247
nextUse->getParentBlock (),
238
248
{nextUse, {*leafRange, false /* is lifetime ending*/ }});
239
- interface. liveness -> updateForUse (nextUse->getUser (), *leafRange,
240
- false /* is lifetime ending*/ );
249
+ liveness. updateForUse (nextUse->getUser (), *leafRange,
250
+ false /* is lifetime ending*/ );
241
251
interface.instToInterestingOperandIndexMap .insert (nextUse->getUser (),
242
252
nextUse);
243
253
continue ;
@@ -263,8 +273,8 @@ bool Implementation::gatherUses(SILValue value) {
263
273
interface.blocksToUses .insert (
264
274
nextUse->getParentBlock (),
265
275
{nextUse, {*leafRange, true /* is lifetime ending*/ }});
266
- interface. liveness -> updateForUse (nextUse->getUser (), *leafRange,
267
- true /* is lifetime ending*/ );
276
+ liveness. updateForUse (nextUse->getUser (), *leafRange,
277
+ true /* is lifetime ending*/ );
268
278
interface.instToInterestingOperandIndexMap .insert (nextUse->getUser (),
269
279
nextUse);
270
280
continue ;
@@ -304,7 +314,7 @@ void Implementation::checkForErrorsOnSameInstruction() {
304
314
// check if any of our consuming uses that are on the boundary are used by the
305
315
// same instruction as a different consuming or non-consuming use.
306
316
interface.instToInterestingOperandIndexMap .setFrozen ();
307
- SmallBitVector usedBits (interface. liveness -> getNumSubElements ());
317
+ SmallBitVector usedBits (liveness. getNumSubElements ());
308
318
309
319
for (auto instRangePair :
310
320
interface.instToInterestingOperandIndexMap .getRange ()) {
@@ -423,8 +433,7 @@ void Implementation::checkDestructureUsesOnBoundary() const {
423
433
424
434
auto destructureUseSpan =
425
435
*TypeTreeLeafTypeRange::get (use->get (), getRootValue ());
426
- if (!interface.liveness ->isWithinBoundary (use->getUser (),
427
- destructureUseSpan)) {
436
+ if (!liveness.isWithinBoundary (use->getUser (), destructureUseSpan)) {
428
437
LLVM_DEBUG (llvm::dbgs ()
429
438
<< " On boundary or within boundary! No error!\n " );
430
439
continue ;
@@ -439,9 +448,8 @@ void Implementation::checkDestructureUsesOnBoundary() const {
439
448
// TODO: Fix diagnostic to use destructure needing use and boundary
440
449
// uses.
441
450
LLVM_DEBUG (llvm::dbgs () << " Within boundary! Emitting error!\n " );
442
- FieldSensitivePrunedLivenessBoundary boundary (
443
- interface.liveness ->getNumSubElements ());
444
- interface.liveness ->computeBoundary (boundary);
451
+ FieldSensitivePrunedLivenessBoundary boundary (liveness.getNumSubElements ());
452
+ liveness.computeBoundary (boundary);
445
453
getDiagnostics ().emitObjectDestructureNeededWithinBorrowBoundary (
446
454
getMarkedValue (), use->getUser (), destructureUseSpan, boundary);
447
455
}
@@ -1096,7 +1104,7 @@ void Implementation::rewriteUses() {
1096
1104
<< " Performing BorrowToDestructureTransform::rewriteUses()!\n " );
1097
1105
1098
1106
llvm::SmallPtrSet<Operand *, 8 > seenOperands;
1099
- SmallBitVector bitsNeededInBlock (interface. liveness -> getNumSubElements ());
1107
+ SmallBitVector bitsNeededInBlock (liveness. getNumSubElements ());
1100
1108
IntervalMapAllocator::Map typeSpanToValue (getAllocator ());
1101
1109
1102
1110
auto *fn = getMarkedValue ()->getFunction ();
@@ -1590,7 +1598,9 @@ bool BorrowToDestructureTransform::transform() {
1590
1598
1591
1599
// Attempt to gather uses. Return false if we saw something that we did not
1592
1600
// understand.
1593
- Implementation impl (*this );
1601
+ SmallVector<SILBasicBlock *, 8 > discoveredBlocks;
1602
+ Implementation impl (*this , discoveredBlocks);
1603
+ impl.init (mmci);
1594
1604
for (auto *bbi : borrowWorklist) {
1595
1605
if (!impl.gatherUses (bbi))
1596
1606
return false ;
@@ -1623,7 +1633,7 @@ bool BorrowToDestructureTransform::transform() {
1623
1633
1624
1634
// At this point, we know that all of our destructure requiring uses are on
1625
1635
// the boundary of our live range. Now we need to do the rewriting.
1626
- impl.blockToAvailableValues .emplace (* liveness);
1636
+ impl.blockToAvailableValues .emplace (impl. liveness );
1627
1637
impl.rewriteUses ();
1628
1638
1629
1639
// Now that we have done our rewritting, we need to do a few cleanups.
0 commit comments