@@ -62,19 +62,9 @@ static unsigned getElementCountRec(SILModule &Module, SILType T,
62
62
}
63
63
64
64
static std::pair<SILType, bool >
65
- computeMemorySILType (SILInstruction *MemoryInst) {
65
+ computeMemorySILType (MarkUninitializedInst *MemoryInst) {
66
66
// Compute the type of the memory object.
67
- if (auto *ABI = dyn_cast<AllocBoxInst>(MemoryInst)) {
68
- assert (ABI->getBoxType ()->getLayout ()->getFields ().size () == 1 &&
69
- " analyzing multi-field boxes not implemented" );
70
- return {ABI->getBoxType ()->getFieldType (MemoryInst->getModule (), 0 ), false };
71
- }
72
-
73
- if (auto *ASI = dyn_cast<AllocStackInst>(MemoryInst)) {
74
- return {ASI->getElementType (), false };
75
- }
76
-
77
- auto *MUI = cast<MarkUninitializedInst>(MemoryInst);
67
+ auto *MUI = MemoryInst;
78
68
SILType MemorySILType = MUI->getType ().getObjectType ();
79
69
80
70
// If this is a let variable we're initializing, remember this so we don't
@@ -89,7 +79,7 @@ computeMemorySILType(SILInstruction *MemoryInst) {
89
79
return {MemorySILType, VDecl->isLet ()};
90
80
}
91
81
92
- DIMemoryObjectInfo::DIMemoryObjectInfo (SingleValueInstruction *MI)
82
+ DIMemoryObjectInfo::DIMemoryObjectInfo (MarkUninitializedInst *MI)
93
83
: MemoryInst(MI) {
94
84
auto &Module = MI->getModule ();
95
85
@@ -352,9 +342,8 @@ DIMemoryObjectInfo::getPathStringToElement(unsigned Element,
352
342
353
343
// If we are analyzing a variable, we can generally get the decl associated
354
344
// with it.
355
- if (auto *MUI = dyn_cast<MarkUninitializedInst>(MemoryInst))
356
- if (MUI->isVar ())
357
- return MUI->getLoc ().getAsASTNode <VarDecl>();
345
+ if (MemoryInst->isVar ())
346
+ return MemoryInst->getLoc ().getAsASTNode <VarDecl>();
358
347
359
348
// Otherwise, we can't.
360
349
return nullptr ;
@@ -389,23 +378,6 @@ bool DIMemoryObjectInfo::isElementLetProperty(unsigned Element) const {
389
378
return false ;
390
379
}
391
380
392
- void DIMemoryObjectInfo::collectRetainCountInfo (
393
- DIElementUseInfo &OutVar) const {
394
- if (isa<MarkUninitializedInst>(MemoryInst))
395
- return ;
396
-
397
- // Collect information about the retain count result as well.
398
- for (auto *Op : MemoryInst->getUses ()) {
399
- auto *User = Op->getUser ();
400
-
401
- // If this is a release or dealloc_stack, then remember it as such.
402
- if (isa<StrongReleaseInst>(User) || isa<DeallocStackInst>(User) ||
403
- isa<DeallocBoxInst>(User) || isa<DestroyValueInst>(User)) {
404
- OutVar.trackDestroy (User);
405
- }
406
- }
407
- }
408
-
409
381
// ===----------------------------------------------------------------------===//
410
382
// DIMemoryUse Implementation
411
383
// ===----------------------------------------------------------------------===//
@@ -535,17 +507,10 @@ class ElementUseCollector {
535
507
" Should have been handled outside of here" );
536
508
// If this is a class pointer, we need to look through ref_element_addrs.
537
509
collectClassSelfUses ();
538
- TheMemory.collectRetainCountInfo (UseInfo);
539
510
return ;
540
511
}
541
512
542
- if (auto *ABI = TheMemory.getContainer ()) {
543
- collectContainerUses (ABI);
544
- } else {
545
- collectUses (TheMemory.getAddress (), 0 );
546
- }
547
-
548
- TheMemory.collectRetainCountInfo (UseInfo);
513
+ collectUses (TheMemory.MemoryInst , 0 );
549
514
}
550
515
551
516
void trackUse (DIMemoryUse Use) { UseInfo.trackUse (Use); }
@@ -558,7 +523,6 @@ class ElementUseCollector {
558
523
559
524
private:
560
525
void collectUses (SILValue Pointer, unsigned BaseEltNo);
561
- void collectContainerUses (AllocBoxInst *ABI);
562
526
void collectClassSelfUses ();
563
527
void collectClassSelfUses (SILValue ClassPointer, SILType MemorySILType,
564
528
llvm::SmallDenseMap<VarDecl *, unsigned > &EN);
@@ -670,29 +634,6 @@ void ElementUseCollector::collectStructElementUses(StructElementAddrInst *SEAI,
670
634
collectUses (SEAI, BaseEltNo);
671
635
}
672
636
673
- void ElementUseCollector::collectContainerUses (AllocBoxInst *ABI) {
674
- for (auto *Op : ABI->getUses ()) {
675
- auto *User = Op->getUser ();
676
-
677
- // Deallocations and retain/release don't affect the value directly.
678
- if (isa<DeallocBoxInst>(User) || isa<StrongRetainInst>(User) ||
679
- isa<StrongReleaseInst>(User) || isa<DestroyValueInst>(User))
680
- continue ;
681
-
682
- if (auto *PBI = dyn_cast<ProjectBoxInst>(User)) {
683
- collectUses (PBI, PBI->getFieldIndex ());
684
- continue ;
685
- }
686
-
687
- // Other uses of the container are considered escapes of the values.
688
- for (unsigned Field : indices (ABI->getBoxType ()->getLayout ()->getFields ())) {
689
- addElementUses (Field,
690
- ABI->getBoxType ()->getFieldType (ABI->getModule (), Field),
691
- User, DIUseKind::Escape);
692
- }
693
- }
694
- }
695
-
696
637
// / Return the underlying accessed pointer value. This peeks through
697
638
// / begin_access patterns such as:
698
639
// /
@@ -1092,10 +1033,9 @@ void ElementUseCollector::collectClassSelfUses() {
1092
1033
1093
1034
// If we are looking at the init method for a root class, just walk the
1094
1035
// MUI use-def chain directly to find our uses.
1095
- auto *MUI = cast<MarkUninitializedInst>(TheMemory.MemoryInst );
1096
- if (MUI->getKind () == MarkUninitializedInst::RootSelf) {
1097
- collectClassSelfUses (TheMemory.getAddress (), TheMemory.MemorySILType ,
1098
- EltNumbering);
1036
+ auto *MemoryInst = TheMemory.MemoryInst ;
1037
+ if (MemoryInst->getKind () == MarkUninitializedInst::RootSelf) {
1038
+ collectClassSelfUses (MemoryInst, TheMemory.MemorySILType , EltNumbering);
1099
1039
return ;
1100
1040
}
1101
1041
@@ -1112,7 +1052,7 @@ void ElementUseCollector::collectClassSelfUses() {
1112
1052
// 4) Potential escapes after super.init, if self is closed over.
1113
1053
//
1114
1054
// Handle each of these in turn.
1115
- SmallVector<Operand *, 8 > Uses (MUI ->getUses ());
1055
+ SmallVector<Operand *, 8 > Uses (MemoryInst ->getUses ());
1116
1056
while (!Uses.empty ()) {
1117
1057
Operand *Op = Uses.pop_back_val ();
1118
1058
SILInstruction *User = Op->getUser ();
@@ -1123,7 +1063,7 @@ void ElementUseCollector::collectClassSelfUses() {
1123
1063
// The initial store of 'self' into the box at the start of the
1124
1064
// function. Ignore it.
1125
1065
if (auto *Arg = dyn_cast<SILArgument>(SI->getSrc ())) {
1126
- if (Arg->getParent () == MUI ->getParent ()) {
1066
+ if (Arg->getParent () == MemoryInst ->getParent ()) {
1127
1067
StoresOfArgumentToSelf++;
1128
1068
continue ;
1129
1069
}
@@ -1138,7 +1078,7 @@ void ElementUseCollector::collectClassSelfUses() {
1138
1078
src = conversion->getConverted ();
1139
1079
1140
1080
if (auto *LI = dyn_cast<LoadInst>(src))
1141
- if (LI->getOperand () == MUI )
1081
+ if (LI->getOperand () == MemoryInst )
1142
1082
continue ;
1143
1083
1144
1084
// Any other store needs to be recorded.
@@ -1548,7 +1488,7 @@ void DelegatingClassInitElementUseCollector::collectClassInitSelfUses() {
1548
1488
// all. Just treat all members of self as uses of the single
1549
1489
// non-field-sensitive value.
1550
1490
assert (TheMemory.NumElements == 1 && " delegating inits only have 1 bit" );
1551
- auto *MUI = cast<MarkUninitializedInst>( TheMemory.MemoryInst ) ;
1491
+ auto *MUI = TheMemory.MemoryInst ;
1552
1492
1553
1493
// The number of stores of the initial 'self' argument into the self box
1554
1494
// that we saw.
@@ -1792,16 +1732,14 @@ void swift::ownership::collectDIElementUsesFrom(
1792
1732
// at all. Just treat all members of self as uses of the single
1793
1733
// non-field-sensitive value.
1794
1734
assert (MemoryInfo.NumElements == 1 && " delegating inits only have 1 bit" );
1795
- auto *MUI = cast<MarkUninitializedInst>(MemoryInfo.MemoryInst );
1796
- collectValueTypeDelegatingInitUses (MemoryInfo, UseInfo, MUI);
1797
- MemoryInfo.collectRetainCountInfo (UseInfo);
1735
+ collectValueTypeDelegatingInitUses (MemoryInfo, UseInfo,
1736
+ MemoryInfo.MemoryInst );
1798
1737
return ;
1799
1738
}
1800
1739
1801
1740
if (shouldPerformClassInitSelf (MemoryInfo)) {
1802
1741
DelegatingClassInitElementUseCollector UseCollector (MemoryInfo, UseInfo);
1803
1742
UseCollector.collectClassInitSelfUses ();
1804
- MemoryInfo.collectRetainCountInfo (UseInfo);
1805
1743
return ;
1806
1744
}
1807
1745
0 commit comments