@@ -28,34 +28,33 @@ using namespace ownership;
28
28
// Utility
29
29
// ===----------------------------------------------------------------------===//
30
30
31
- static void gatherDestroysOfContainer (const MarkUninitializedInst *MUI,
32
- DIElementUseInfo &UseInfo) {
33
- // The MUI must be used on an alloc_box, alloc_stack, or global_addr. If we
34
- // have an alloc_stack or a global_addr, there is nothing further to do.
35
- if (isa<AllocStackInst>(MUI->getOperand ()) ||
36
- isa<GlobalAddrInst>(MUI->getOperand ()) ||
37
- isa<SILArgument>(MUI->getOperand ()) ||
31
+ static void gatherDestroysOfContainer (const DIMemoryObjectInfo &memoryInfo,
32
+ DIElementUseInfo &useInfo) {
33
+ auto *uninitMemory = memoryInfo.getUninitializedValue ();
34
+
35
+ // The uninitMemory must be used on an alloc_box, alloc_stack, or global_addr.
36
+ // If we have an alloc_stack or a global_addr, there is nothing further to do.
37
+ if (isa<AllocStackInst>(uninitMemory->getOperand (0 )) ||
38
+ isa<GlobalAddrInst>(uninitMemory->getOperand (0 )) ||
39
+ isa<SILArgument>(uninitMemory->getOperand (0 )) ||
38
40
// FIXME: We only support pointer to address here to not break LLDB. It is
39
41
// important that long term we get rid of this since this is a situation
40
42
// where LLDB is breaking SILGen/DI invariants by not creating a new
41
43
// independent stack location for the pointer to address.
42
- isa<PointerToAddressInst>(MUI ->getOperand ()))
44
+ isa<PointerToAddressInst>(uninitMemory ->getOperand (0 ))) {
43
45
return ;
46
+ }
44
47
45
- // Otherwise, we assume that we have a project_box. This is a hard cast to
46
- // ensure that we catch any new patterns emitted by SILGen and assert.
47
- auto *PBI = cast<ProjectBoxInst>(MUI->getOperand ());
48
- auto *ABI = cast<AllocBoxInst>(PBI->getOperand ());
49
-
50
- // Treat destroys of the container as load+destroys of the original value.
48
+ // Otherwise, we assume that we have an alloc_box. Treat destroys of the
49
+ // alloc_box as load+destroys of the value stored in the box.
51
50
//
52
51
// TODO: This should really be tracked separately from other destroys so that
53
52
// we distinguish the lifetime of the container from the value itself.
54
- for ( auto *Op : ABI-> getUses ()) {
55
- SILInstruction *User = Op-> getUser ( );
56
- if (isa<StrongReleaseInst>(User) || isa<DestroyValueInst>(User)) {
57
- UseInfo. trackDestroy (User);
58
- }
53
+ assert (isa<MarkUninitializedInst>(uninitMemory));
54
+ auto *pbi = cast<ProjectBoxInst>(uninitMemory-> getOperand ( 0 ) );
55
+ auto *abi = cast<AllocBoxInst>(pbi-> getOperand ());
56
+ for ( auto *user : abi-> getUsersOfType <DestroyValueInst>()) {
57
+ useInfo. trackDestroy (user);
59
58
}
60
59
}
61
60
@@ -215,7 +214,7 @@ SILType DIMemoryObjectInfo::getElementType(unsigned EltNo) const {
215
214
SILValue DIMemoryObjectInfo::emitElementAddress (
216
215
unsigned EltNo, SILLocation Loc, SILBuilder &B,
217
216
llvm::SmallVectorImpl<std::pair<SILValue, SILValue>> &EndBorrowList) const {
218
- SILValue Ptr = getAddress ();
217
+ SILValue Ptr = getUninitializedValue ();
219
218
bool IsSelf = isNonDelegatingInit ();
220
219
auto &Module = MemoryInst->getModule ();
221
220
@@ -535,8 +534,7 @@ class ElementUseCollector {
535
534
public:
536
535
ElementUseCollector (const DIMemoryObjectInfo &TheMemory,
537
536
DIElementUseInfo &UseInfo)
538
- : Module(TheMemory.MemoryInst->getModule ()), TheMemory(TheMemory),
539
- UseInfo(UseInfo) {}
537
+ : Module(TheMemory.getModule()), TheMemory(TheMemory), UseInfo(UseInfo) {}
540
538
541
539
// / This is the main entry point for the use walker. It collects uses from
542
540
// / the address and the refcount result of the allocation.
@@ -553,8 +551,8 @@ class ElementUseCollector {
553
551
return ;
554
552
}
555
553
556
- collectUses (TheMemory.MemoryInst , 0 );
557
- gatherDestroysOfContainer (TheMemory. MemoryInst , UseInfo);
554
+ collectUses (TheMemory.getUninitializedValue () , 0 );
555
+ gatherDestroysOfContainer (TheMemory, UseInfo);
558
556
}
559
557
560
558
void trackUse (DIMemoryUse Use) { UseInfo.trackUse (Use); }
@@ -564,8 +562,6 @@ class ElementUseCollector {
564
562
// / Return the raw number of elements including the 'super.init' value.
565
563
unsigned getNumMemoryElements () const { return TheMemory.getNumElements (); }
566
564
567
- SILInstruction *getMemoryInst () const { return TheMemory.MemoryInst ; }
568
-
569
565
private:
570
566
void collectUses (SILValue Pointer, unsigned BaseEltNo);
571
567
void collectClassSelfUses ();
@@ -867,7 +863,7 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
867
863
// inout use.
868
864
DIUseKind Kind;
869
865
if (TheMemory.isStructInitSelf () &&
870
- getAccessedPointer (Pointer) == TheMemory.getAddress ()) {
866
+ getAccessedPointer (Pointer) == TheMemory.getUninitializedValue ()) {
871
867
Kind = DIUseKind::Escape;
872
868
} else if (Apply.hasSelfArgument () &&
873
869
Op == &Apply.getSelfArgumentOperand ()) {
@@ -1089,8 +1085,7 @@ void ElementUseCollector::collectClassSelfUses() {
1089
1085
unsigned NumElements = 0 ;
1090
1086
for (auto *VD : NTD->getStoredProperties ()) {
1091
1087
EltNumbering[VD] = NumElements;
1092
- auto expansionContext =
1093
- TypeExpansionContext (*TheMemory.MemoryInst ->getFunction ());
1088
+ auto expansionContext = TypeExpansionContext (TheMemory.getFunction ());
1094
1089
NumElements += getElementCountRec (
1095
1090
expansionContext, Module,
1096
1091
T.getFieldType (VD, Module, expansionContext), false );
@@ -1099,9 +1094,9 @@ void ElementUseCollector::collectClassSelfUses() {
1099
1094
1100
1095
// If we are looking at the init method for a root class, just walk the
1101
1096
// MUI use-def chain directly to find our uses.
1102
- auto *MemoryInst = TheMemory.MemoryInst ;
1103
- if (MemoryInst-> getKind () == MarkUninitializedInst::RootSelf) {
1104
- collectClassSelfUses (MemoryInst, TheMemory. getType (), EltNumbering);
1097
+ if ( TheMemory.isRootSelf ()) {
1098
+ collectClassSelfUses (TheMemory. getUninitializedValue (), TheMemory. getType (),
1099
+ EltNumbering);
1105
1100
return ;
1106
1101
}
1107
1102
@@ -1118,7 +1113,7 @@ void ElementUseCollector::collectClassSelfUses() {
1118
1113
// 4) Potential escapes after super.init, if self is closed over.
1119
1114
//
1120
1115
// Handle each of these in turn.
1121
- SmallVector<Operand *, 8 > Uses (MemoryInst ->getUses ());
1116
+ SmallVector<Operand *, 8 > Uses (TheMemory. getUninitializedValue () ->getUses ());
1122
1117
while (!Uses.empty ()) {
1123
1118
Operand *Op = Uses.pop_back_val ();
1124
1119
SILInstruction *User = Op->getUser ();
@@ -1129,7 +1124,7 @@ void ElementUseCollector::collectClassSelfUses() {
1129
1124
// The initial store of 'self' into the box at the start of the
1130
1125
// function. Ignore it.
1131
1126
if (auto *Arg = dyn_cast<SILArgument>(SI->getSrc ())) {
1132
- if (Arg->getParent () == MemoryInst-> getParent ()) {
1127
+ if (Arg->getParent () == TheMemory. getParentBlock ()) {
1133
1128
StoresOfArgumentToSelf++;
1134
1129
continue ;
1135
1130
}
@@ -1144,7 +1139,7 @@ void ElementUseCollector::collectClassSelfUses() {
1144
1139
src = conversion->getConverted ();
1145
1140
1146
1141
if (auto *LI = dyn_cast<LoadInst>(src))
1147
- if (LI->getOperand () == MemoryInst )
1142
+ if (LI->getOperand () == TheMemory. getUninitializedValue () )
1148
1143
continue ;
1149
1144
1150
1145
// Any other store needs to be recorded.
@@ -1583,7 +1578,7 @@ class ClassInitElementUseCollector {
1583
1578
1584
1579
// *NOTE* Even though this takes a SILInstruction it actually only accepts
1585
1580
// load_borrow and load instructions. This is enforced via an assert.
1586
- void collectClassInitSelfLoadUses (MarkUninitializedInst *MUI,
1581
+ void collectClassInitSelfLoadUses (SingleValueInstruction *MUI,
1587
1582
SingleValueInstruction *LI);
1588
1583
};
1589
1584
@@ -1596,21 +1591,21 @@ void ClassInitElementUseCollector::collectClassInitSelfUses() {
1596
1591
// all. Just treat all members of self as uses of the single
1597
1592
// non-field-sensitive value.
1598
1593
assert (TheMemory.getNumElements () == 1 && " delegating inits only have 1 bit" );
1599
- auto *MUI = TheMemory.MemoryInst ;
1594
+ auto *uninitMemory = TheMemory.getUninitializedValue () ;
1600
1595
1601
1596
// The number of stores of the initial 'self' argument into the self box
1602
1597
// that we saw.
1603
1598
unsigned StoresOfArgumentToSelf = 0 ;
1604
1599
1605
- // We walk the use chains of the self MUI to find any accesses to it. The
1606
- // possible uses are:
1600
+ // We walk the use chains of the self uninitMemory to find any accesses to it.
1601
+ // The possible uses are:
1607
1602
// 1) The initialization store.
1608
1603
// 2) Loads of the box, which have uses of self hanging off of them.
1609
1604
// 3) An assign to the box, which happens at super.init.
1610
1605
// 4) Potential escapes after super.init, if self is closed over.
1611
1606
// Handle each of these in turn.
1612
1607
//
1613
- SmallVector<Operand *, 8 > Uses (MUI ->getUses ());
1608
+ SmallVector<Operand *, 8 > Uses (uninitMemory ->getUses ());
1614
1609
while (!Uses.empty ()) {
1615
1610
Operand *Op = Uses.pop_back_val ();
1616
1611
SILInstruction *User = Op->getUser ();
@@ -1634,7 +1629,7 @@ void ClassInitElementUseCollector::collectClassInitSelfUses() {
1634
1629
// A store of 'self' into the box at the start of the
1635
1630
// function. Ignore it.
1636
1631
if (auto *Arg = dyn_cast<SILArgument>(SI->getSrc ())) {
1637
- if (Arg->getParent () == MUI ->getParent ()) {
1632
+ if (Arg->getParent () == uninitMemory ->getParent ()) {
1638
1633
StoresOfArgumentToSelf++;
1639
1634
continue ;
1640
1635
}
@@ -1649,7 +1644,7 @@ void ClassInitElementUseCollector::collectClassInitSelfUses() {
1649
1644
src = conversion->getConverted ();
1650
1645
1651
1646
if (auto *LI = dyn_cast<LoadInst>(src))
1652
- if (LI->getOperand () == MUI )
1647
+ if (LI->getOperand () == uninitMemory )
1653
1648
continue ;
1654
1649
1655
1650
// Any other store needs to be recorded.
@@ -1699,7 +1694,8 @@ void ClassInitElementUseCollector::collectClassInitSelfUses() {
1699
1694
1700
1695
// Loads of the box produce self, so collect uses from them.
1701
1696
if (isa<LoadInst>(User) || isa<LoadBorrowInst>(User)) {
1702
- collectClassInitSelfLoadUses (MUI, cast<SingleValueInstruction>(User));
1697
+ collectClassInitSelfLoadUses (uninitMemory,
1698
+ cast<SingleValueInstruction>(User));
1703
1699
continue ;
1704
1700
}
1705
1701
@@ -1718,12 +1714,12 @@ void ClassInitElementUseCollector::collectClassInitSelfUses() {
1718
1714
" The 'self' argument should have been stored into the box exactly once" );
1719
1715
1720
1716
// Gather the uses of the
1721
- gatherDestroysOfContainer (MUI , UseInfo);
1717
+ gatherDestroysOfContainer (TheMemory , UseInfo);
1722
1718
}
1723
1719
1724
- void ClassInitElementUseCollector::
1725
- collectClassInitSelfLoadUses (MarkUninitializedInst *MUI,
1726
- SingleValueInstruction *LI) {
1720
+ void ClassInitElementUseCollector::collectClassInitSelfLoadUses (
1721
+ SingleValueInstruction *MUI, SingleValueInstruction *LI) {
1722
+ assert (isa<ProjectBoxInst>(MUI) || isa<MarkUninitializedInst>(MUI));
1727
1723
assert (isa<LoadBorrowInst>(LI) || isa<LoadInst>(LI));
1728
1724
1729
1725
// If we have a load, then this is a use of the box. Look at the uses of
@@ -1805,7 +1801,7 @@ collectClassInitSelfLoadUses(MarkUninitializedInst *MUI,
1805
1801
// ===----------------------------------------------------------------------===//
1806
1802
1807
1803
static bool shouldPerformClassInitSelf (const DIMemoryObjectInfo &MemoryInfo) {
1808
- if (MemoryInfo.MemoryInst -> isDelegatingSelfAllocated ())
1804
+ if (MemoryInfo.isDelegatingSelfAllocated ())
1809
1805
return true ;
1810
1806
1811
1807
return MemoryInfo.isNonDelegatingInit () &&
@@ -1831,7 +1827,8 @@ void swift::ownership::collectDIElementUsesFrom(
1831
1827
// non-field-sensitive value.
1832
1828
assert (MemoryInfo.getNumElements () == 1 &&
1833
1829
" delegating inits only have 1 bit" );
1834
- collectDelegatingInitUses (MemoryInfo, UseInfo, MemoryInfo.MemoryInst );
1830
+ collectDelegatingInitUses (MemoryInfo, UseInfo,
1831
+ MemoryInfo.getUninitializedValue ());
1835
1832
return ;
1836
1833
}
1837
1834
0 commit comments