Skip to content

Commit 71ded28

Browse files
authored
Merge pull request swiftlang#28963 from gottesmm/mark_uninit_fixup_removal
2 parents ed920fe + 28ffcf9 commit 71ded28

12 files changed

+176
-282
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,10 +2206,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
22062206
// outside by the allocating initializer and we pass in the to be
22072207
// initialized value as a SILArgument.
22082208
|| isa<SILArgument>(Src)
2209-
// FIXME: Once the MarkUninitializedFixup pass is eliminated,
2210-
// mark_uninitialized should never be applied to a project_box. So
2211-
// at that point, this should be eliminated.
2212-
|| isa<ProjectBoxInst>(Src)
22132209
// FIXME: We only support pointer to address here to not break LLDB. It is
22142210
// important that long term we get rid of this since this is a situation
22152211
// where LLDB is breaking SILGen/DI invariants by not creating a new

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ constructClonedFunction(SILOptFunctionBuilder &FuncBuilder,
11971197
/// 2. We only see a mark_uninitialized when paired with an (alloc_box,
11981198
/// project_box). e.x.:
11991199
///
1200-
/// (mark_uninitialized (project_box (alloc_box)))
1200+
/// (project_box (mark_uninitialized (alloc_box)))
12011201
///
12021202
/// The asserts are to make sure that if the initial safety condition check
12031203
/// is changed, this code is changed as well.
@@ -1209,15 +1209,16 @@ static SILValue getOrCreateProjectBoxHelper(SILValue PartialOperand) {
12091209
}
12101210

12111211
// Otherwise, handle the alloc_box case. If we have a mark_uninitialized on
1212-
// the box, we create the project value through that.
1212+
// the box, we know that we will have a project_box of that value due to SIL
1213+
// verifier invariants.
12131214
SingleValueInstruction *Box = cast<AllocBoxInst>(PartialOperand);
1214-
if (auto *Op = Box->getSingleUse()) {
1215-
if (auto *MUI = dyn_cast<MarkUninitializedInst>(Op->getUser())) {
1216-
Box = MUI;
1215+
if (auto *MUI = Box->getSingleUserOfType<MarkUninitializedInst>()) {
1216+
if (auto *PBI = MUI->getSingleUserOfType<ProjectBoxInst>()) {
1217+
return PBI;
12171218
}
12181219
}
12191220

1220-
// Just return a project_box.
1221+
// Otherwise, create a new project_box.
12211222
SILBuilderWithScope B(std::next(Box->getIterator()));
12221223
return B.createProjectBox(Box->getLoc(), Box, 0);
12231224
}

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ static void gatherDestroysOfContainer(const DIMemoryObjectInfo &memoryInfo,
5050
//
5151
// TODO: This should really be tracked separately from other destroys so that
5252
// we distinguish the lifetime of the container from the value itself.
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>()) {
53+
assert(isa<ProjectBoxInst>(uninitMemory));
54+
auto *mui = cast<MarkUninitializedInst>(uninitMemory->getOperand(0));
55+
for (auto *user : mui->getUsersOfType<DestroyValueInst>()) {
5756
useInfo.trackDestroy(user);
5857
}
5958
}
@@ -97,7 +96,11 @@ static std::pair<SILType, bool>
9796
computeMemorySILType(MarkUninitializedInst *MemoryInst) {
9897
// Compute the type of the memory object.
9998
auto *MUI = MemoryInst;
100-
SILType MemorySILType = MUI->getType().getObjectType();
99+
SILValue Address = MUI;
100+
if (auto *PBI = Address->getSingleUserOfType<ProjectBoxInst>()) {
101+
Address = PBI;
102+
}
103+
SILType MemorySILType = Address->getType().getObjectType();
101104

102105
// If this is a let variable we're initializing, remember this so we don't
103106
// allow reassignment.
@@ -1712,9 +1715,6 @@ void ClassInitElementUseCollector::collectClassInitSelfUses() {
17121715

17131716
assert(StoresOfArgumentToSelf == 1 &&
17141717
"The 'self' argument should have been stored into the box exactly once");
1715-
1716-
// Gather the uses of the
1717-
gatherDestroysOfContainer(TheMemory, UseInfo);
17181718
}
17191719

17201720
void ClassInitElementUseCollector::collectClassInitSelfLoadUses(
@@ -1818,6 +1818,7 @@ void swift::ownership::collectDIElementUsesFrom(
18181818
if (shouldPerformClassInitSelf(MemoryInfo)) {
18191819
ClassInitElementUseCollector UseCollector(MemoryInfo, UseInfo);
18201820
UseCollector.collectClassInitSelfUses();
1821+
gatherDestroysOfContainer(MemoryInfo, UseInfo);
18211822
return;
18221823
}
18231824

@@ -1829,6 +1830,7 @@ void swift::ownership::collectDIElementUsesFrom(
18291830
"delegating inits only have 1 bit");
18301831
collectDelegatingInitUses(MemoryInfo, UseInfo,
18311832
MemoryInfo.getUninitializedValue());
1833+
gatherDestroysOfContainer(MemoryInfo, UseInfo);
18321834
return;
18331835
}
18341836

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ class DIMemoryObjectInfo {
9898
/// instruction. For alloc_box though it returns the project_box associated
9999
/// with the memory info.
100100
SingleValueInstruction *getUninitializedValue() const {
101+
if (auto *mui = dyn_cast<MarkUninitializedInst>(MemoryInst)) {
102+
if (auto *pbi = mui->getSingleUserOfType<ProjectBoxInst>()) {
103+
return pbi;
104+
}
105+
}
101106
return MemoryInst;
102107
}
103108

@@ -209,10 +214,9 @@ class DIMemoryObjectInfo {
209214

210215
/// Given an element number (in the flattened sense) return a pointer to a
211216
/// leaf element of the specified number.
212-
SILValue
213-
emitElementAddress(unsigned TupleEltNo, SILLocation Loc, SILBuilder &B,
214-
llvm::SmallVectorImpl<std::pair<SILValue, SILValue>>
215-
&EndBorrowList) const;
217+
SILValue emitElementAddress(
218+
unsigned TupleEltNo, SILLocation Loc, SILBuilder &B,
219+
SmallVectorImpl<std::pair<SILValue, SILValue>> &EndBorrowList) const;
216220

217221
/// Return the swift type of the specified element.
218222
SILType getElementType(unsigned EltNo) const;

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,14 @@ namespace {
477477
void processUninitializedRelease(SILInstruction *Release,
478478
bool consumed,
479479
SILBasicBlock::iterator InsertPt);
480-
void processUninitializedReleaseOfBox(AllocBoxInst *ABI,
480+
481+
/// Process a mark_uninitialized of an alloc_box that is uninitialized and
482+
/// needs a dealloc_box.
483+
void processUninitializedReleaseOfBox(MarkUninitializedInst *MUI,
481484
SILInstruction *Release,
482485
bool consumed,
483486
SILBasicBlock::iterator InsertPt);
487+
484488
void deleteDeadRelease(unsigned ReleaseID);
485489

486490
void processNonTrivialRelease(unsigned ReleaseID);
@@ -791,6 +795,7 @@ void LifetimeChecker::doIt() {
791795
// thereof) is not initialized on some path, the bad things happen. Process
792796
// releases to adjust for this.
793797
if (!TheMemory.hasTrivialType()) {
798+
// NOTE: This array may increase in size!
794799
for (unsigned i = 0, e = Destroys.size(); i != e; ++i)
795800
processNonTrivialRelease(i);
796801
}
@@ -1941,12 +1946,13 @@ void LifetimeChecker::updateInstructionForInitState(DIMemoryUse &Use) {
19411946
}
19421947

19431948
void LifetimeChecker::processUninitializedReleaseOfBox(
1944-
AllocBoxInst *ABI, SILInstruction *Release, bool consumed,
1949+
MarkUninitializedInst *MUI, SILInstruction *Release, bool consumed,
19451950
SILBasicBlock::iterator InsertPt) {
1946-
assert(ABI == Release->getOperand(0));
1951+
assert(isa<AllocBoxInst>(MUI->getOperand()));
1952+
assert(MUI == Release->getOperand(0));
19471953
SILBuilderWithScope B(Release);
19481954
B.setInsertionPoint(InsertPt);
1949-
Destroys.push_back(B.createDeallocBox(Release->getLoc(), ABI));
1955+
Destroys.push_back(B.createDeallocBox(Release->getLoc(), MUI));
19501956
}
19511957

19521958
void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
@@ -1956,8 +1962,10 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
19561962
// dealloc_partial_ref to free the memory. If this is a derived class, we
19571963
// may have to do a load of the 'self' box to get the class reference.
19581964
if (!TheMemory.isClassInitSelf()) {
1959-
if (auto *ABI = dyn_cast<AllocBoxInst>(Release->getOperand(0))) {
1960-
return processUninitializedReleaseOfBox(ABI, Release, consumed, InsertPt);
1965+
if (auto *MUI = dyn_cast<MarkUninitializedInst>(Release->getOperand(0))) {
1966+
if (isa<AllocBoxInst>(MUI->getOperand())) {
1967+
return processUninitializedReleaseOfBox(MUI, Release, consumed, InsertPt);
1968+
}
19611969
}
19621970
return;
19631971
}
@@ -1972,9 +1980,14 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
19721980
// If we see an alloc_box as the pointer, then we're deallocating a 'box' for
19731981
// self. Make sure that the box gets deallocated (not released) since the
19741982
// pointer it contains will be manually cleaned up.
1975-
auto *ABI = dyn_cast<AllocBoxInst>(Release->getOperand(0));
1976-
if (ABI)
1977-
Pointer = getOrCreateProjectBox(ABI, 0);
1983+
auto *MUI = dyn_cast<MarkUninitializedInst>(Release->getOperand(0));
1984+
1985+
if (MUI && isa<AllocBoxInst>(MUI->getOperand())) {
1986+
Pointer = MUI->getSingleUserOfType<ProjectBoxInst>();
1987+
assert(Pointer);
1988+
} else {
1989+
MUI = nullptr;
1990+
}
19781991

19791992
if (!consumed) {
19801993
if (Pointer->getType().isAddress())
@@ -1999,8 +2012,8 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
19992012
}
20002013

20012014
// dealloc_box the self box if necessary.
2002-
if (ABI) {
2003-
auto DB = B.createDeallocBox(Loc, ABI);
2015+
if (MUI) {
2016+
auto DB = B.createDeallocBox(Loc, MUI);
20042017
Destroys.push_back(DB);
20052018
}
20062019
}

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ static void addOwnershipModelEliminatorPipeline(SILPassPipelinePlan &P) {
7474
/// Passes for performing definite initialization. Must be run together in this
7575
/// order.
7676
static void addDefiniteInitialization(SILPassPipelinePlan &P) {
77-
P.addMarkUninitializedFixup();
7877
P.addDefiniteInitialization();
7978
P.addRawSILInstLowering();
8079
}

0 commit comments

Comments
 (0)