@@ -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 ;
@@ -521,11 +510,7 @@ class ElementUseCollector {
521
510
return ;
522
511
}
523
512
524
- if (auto *ABI = TheMemory.getContainer ()) {
525
- collectContainerUses (ABI);
526
- } else {
527
- collectUses (TheMemory.getAddress (), 0 );
528
- }
513
+ collectUses (TheMemory.MemoryInst , 0 );
529
514
}
530
515
531
516
void trackUse (DIMemoryUse Use) { UseInfo.trackUse (Use); }
@@ -538,7 +523,6 @@ class ElementUseCollector {
538
523
539
524
private:
540
525
void collectUses (SILValue Pointer, unsigned BaseEltNo);
541
- void collectContainerUses (AllocBoxInst *ABI);
542
526
void collectClassSelfUses ();
543
527
void collectClassSelfUses (SILValue ClassPointer, SILType MemorySILType,
544
528
llvm::SmallDenseMap<VarDecl *, unsigned > &EN);
@@ -650,29 +634,6 @@ void ElementUseCollector::collectStructElementUses(StructElementAddrInst *SEAI,
650
634
collectUses (SEAI, BaseEltNo);
651
635
}
652
636
653
- void ElementUseCollector::collectContainerUses (AllocBoxInst *ABI) {
654
- for (auto *Op : ABI->getUses ()) {
655
- auto *User = Op->getUser ();
656
-
657
- // Deallocations and retain/release don't affect the value directly.
658
- if (isa<DeallocBoxInst>(User) || isa<StrongRetainInst>(User) ||
659
- isa<StrongReleaseInst>(User) || isa<DestroyValueInst>(User))
660
- continue ;
661
-
662
- if (auto *PBI = dyn_cast<ProjectBoxInst>(User)) {
663
- collectUses (PBI, PBI->getFieldIndex ());
664
- continue ;
665
- }
666
-
667
- // Other uses of the container are considered escapes of the values.
668
- for (unsigned Field : indices (ABI->getBoxType ()->getLayout ()->getFields ())) {
669
- addElementUses (Field,
670
- ABI->getBoxType ()->getFieldType (ABI->getModule (), Field),
671
- User, DIUseKind::Escape);
672
- }
673
- }
674
- }
675
-
676
637
// / Return the underlying accessed pointer value. This peeks through
677
638
// / begin_access patterns such as:
678
639
// /
@@ -1072,10 +1033,9 @@ void ElementUseCollector::collectClassSelfUses() {
1072
1033
1073
1034
// If we are looking at the init method for a root class, just walk the
1074
1035
// MUI use-def chain directly to find our uses.
1075
- auto *MUI = cast<MarkUninitializedInst>(TheMemory.MemoryInst );
1076
- if (MUI->getKind () == MarkUninitializedInst::RootSelf) {
1077
- collectClassSelfUses (TheMemory.getAddress (), TheMemory.MemorySILType ,
1078
- EltNumbering);
1036
+ auto *MemoryInst = TheMemory.MemoryInst ;
1037
+ if (MemoryInst->getKind () == MarkUninitializedInst::RootSelf) {
1038
+ collectClassSelfUses (MemoryInst, TheMemory.MemorySILType , EltNumbering);
1079
1039
return ;
1080
1040
}
1081
1041
@@ -1092,7 +1052,7 @@ void ElementUseCollector::collectClassSelfUses() {
1092
1052
// 4) Potential escapes after super.init, if self is closed over.
1093
1053
//
1094
1054
// Handle each of these in turn.
1095
- SmallVector<Operand *, 8 > Uses (MUI ->getUses ());
1055
+ SmallVector<Operand *, 8 > Uses (MemoryInst ->getUses ());
1096
1056
while (!Uses.empty ()) {
1097
1057
Operand *Op = Uses.pop_back_val ();
1098
1058
SILInstruction *User = Op->getUser ();
@@ -1103,7 +1063,7 @@ void ElementUseCollector::collectClassSelfUses() {
1103
1063
// The initial store of 'self' into the box at the start of the
1104
1064
// function. Ignore it.
1105
1065
if (auto *Arg = dyn_cast<SILArgument>(SI->getSrc ())) {
1106
- if (Arg->getParent () == MUI ->getParent ()) {
1066
+ if (Arg->getParent () == MemoryInst ->getParent ()) {
1107
1067
StoresOfArgumentToSelf++;
1108
1068
continue ;
1109
1069
}
@@ -1118,7 +1078,7 @@ void ElementUseCollector::collectClassSelfUses() {
1118
1078
src = conversion->getConverted ();
1119
1079
1120
1080
if (auto *LI = dyn_cast<LoadInst>(src))
1121
- if (LI->getOperand () == MUI )
1081
+ if (LI->getOperand () == MemoryInst )
1122
1082
continue ;
1123
1083
1124
1084
// Any other store needs to be recorded.
@@ -1528,7 +1488,7 @@ void DelegatingClassInitElementUseCollector::collectClassInitSelfUses() {
1528
1488
// all. Just treat all members of self as uses of the single
1529
1489
// non-field-sensitive value.
1530
1490
assert (TheMemory.NumElements == 1 && " delegating inits only have 1 bit" );
1531
- auto *MUI = cast<MarkUninitializedInst>( TheMemory.MemoryInst ) ;
1491
+ auto *MUI = TheMemory.MemoryInst ;
1532
1492
1533
1493
// The number of stores of the initial 'self' argument into the self box
1534
1494
// that we saw.
@@ -1772,8 +1732,8 @@ void swift::ownership::collectDIElementUsesFrom(
1772
1732
// at all. Just treat all members of self as uses of the single
1773
1733
// non-field-sensitive value.
1774
1734
assert (MemoryInfo.NumElements == 1 && " delegating inits only have 1 bit" );
1775
- auto *MUI = cast<MarkUninitializedInst> (MemoryInfo. MemoryInst );
1776
- collectValueTypeDelegatingInitUses (MemoryInfo, UseInfo, MUI );
1735
+ collectValueTypeDelegatingInitUses (MemoryInfo, UseInfo,
1736
+ MemoryInfo. MemoryInst );
1777
1737
return ;
1778
1738
}
1779
1739
0 commit comments