@@ -1545,12 +1545,13 @@ bool swift::memInstMustInitialize(Operand *memOper) {
1545
1545
}
1546
1546
}
1547
1547
1548
- bool swift::isSingleInitAllocStack (AllocStackInst *asi,
1549
- SmallVectorImpl<Operand *> &destroyingUses) {
1548
+ Operand *
1549
+ swift::getSingleInitAllocStackUse (AllocStackInst *asi,
1550
+ SmallVectorImpl<Operand *> *destroyingUses) {
1550
1551
// For now, we just look through projections and rely on memInstMustInitialize
1551
1552
// to classify all other uses as init or not.
1552
1553
SmallVector<Operand *, 32 > worklist (asi->getUses ());
1553
- bool foundInit = false ;
1554
+ Operand *singleInit = nullptr ;
1554
1555
1555
1556
while (!worklist.empty ()) {
1556
1557
auto *use = worklist.pop_back_val ();
@@ -1571,14 +1572,15 @@ bool swift::isSingleInitAllocStack(AllocStackInst *asi,
1571
1572
continue ;
1572
1573
}
1573
1574
// Treat load [take] as a write.
1574
- return false ;
1575
+ return nullptr ;
1575
1576
}
1576
1577
1577
1578
switch (user->getKind ()) {
1578
1579
default :
1579
1580
break ;
1580
1581
case SILInstructionKind::DestroyAddrInst:
1581
- destroyingUses.push_back (use);
1582
+ if (destroyingUses)
1583
+ destroyingUses->push_back (use);
1582
1584
continue ;
1583
1585
case SILInstructionKind::DeallocStackInst:
1584
1586
case SILInstructionKind::LoadBorrowInst:
@@ -1589,21 +1591,21 @@ bool swift::isSingleInitAllocStack(AllocStackInst *asi,
1589
1591
// See if we have an initializer and that such initializer is in the same
1590
1592
// block.
1591
1593
if (memInstMustInitialize (use)) {
1592
- if (user->getParent () != asi->getParent () || foundInit ) {
1593
- return false ;
1594
+ if (user->getParent () != asi->getParent () || singleInit ) {
1595
+ return nullptr ;
1594
1596
}
1595
1597
1596
- foundInit = true ;
1598
+ singleInit = use ;
1597
1599
continue ;
1598
1600
}
1599
1601
1600
1602
// Otherwise, if we have found something not in our allowlist, return false.
1601
- return false ;
1603
+ return nullptr ;
1602
1604
}
1603
1605
1604
1606
// We did not find any users that we did not understand. So we can
1605
- // conservatively return true here .
1606
- return true ;
1607
+ // conservatively return the single initializing write that we found .
1608
+ return singleInit ;
1607
1609
}
1608
1610
1609
1611
// / Return true if the given address value is produced by a special address
0 commit comments