Skip to content

Commit 6a94bdc

Browse files
authored
Merge pull request #8829 from gottesmm/ome_mark_uninitialized
2 parents 19b1036 + ad7705e commit 6a94bdc

File tree

3 files changed

+1
-92
lines changed

3 files changed

+1
-92
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
8080
P.addDiagnoseStaticExclusivity();
8181
P.addCapturePromotion();
8282
P.addAllocBoxToStack();
83-
P.addMarkUninitializedFixup();
8483
P.addNoReturnFolding();
8584
P.addOwnershipModelEliminator();
85+
P.addMarkUninitializedFixup();
8686
P.addDefiniteInitialization();
8787

8888
P.addAccessEnforcementSelection();

lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct OwnershipModelEliminatorVisitor
7979
bool visitUnmanagedAutoreleaseValueInst(UnmanagedAutoreleaseValueInst *UAVI);
8080
bool visitCheckedCastBranchInst(CheckedCastBranchInst *CBI);
8181
bool visitSwitchEnumInst(SwitchEnumInst *SWI);
82-
bool visitProjectBoxInst(ProjectBoxInst *PBI);
8382
};
8483

8584
} // end anonymous namespace
@@ -247,67 +246,6 @@ bool OwnershipModelEliminatorVisitor::visitSwitchEnumInst(
247246
return true;
248247
}
249248

250-
// Since we are threading through copies, we may have situations like:
251-
//
252-
// let x = alloc_box $Foo
253-
// let y = project_box x
254-
// let z = mark_uninitialized y
255-
// ... use z ...
256-
//
257-
// let y2 = project_box x
258-
//
259-
// let x2 = copy_value x
260-
// let y3 = project_box y
261-
//
262-
// We need to move project_box like y2 and y3 to go through z so that DI can
263-
// reason about them.
264-
//
265-
// Once DI is updated for ownership, this can go away.
266-
bool OwnershipModelEliminatorVisitor::visitProjectBoxInst(ProjectBoxInst *PBI) {
267-
// First if our operand is already a mark_uninitialized, then we do not need
268-
// to do anything.
269-
auto *Use = PBI->getSingleUse();
270-
if (Use && isa<MarkUninitializedInst>(Use->getUser())) {
271-
return false;
272-
}
273-
274-
// Otherwise, lets try to find the alloc_box.
275-
SILValue BoxValue = PBI->getOperand();
276-
while (auto *CVI = dyn_cast<CopyValueInst>(BoxValue)) {
277-
BoxValue = CVI->getOperand();
278-
}
279-
280-
// We were unable to find the alloc_box. This must be an indirect enum box
281-
// pattern.
282-
auto *ABI = dyn_cast<AllocBoxInst>(BoxValue);
283-
if (!ABI)
284-
return false;
285-
286-
// See if we can find (mark_uninitialized (project_box))
287-
SILValue MUI;
288-
for (auto *Use : ABI->getUses()) {
289-
auto *BoxProjection = dyn_cast<ProjectBoxInst>(Use->getUser());
290-
if (!BoxProjection)
291-
continue;
292-
auto *Op = BoxProjection->getSingleUse();
293-
if (!Op || !isa<MarkUninitializedInst>(Op->getUser()))
294-
continue;
295-
MUI = SILValue(Op->getUser());
296-
break;
297-
}
298-
299-
// If we did not find a mark uninitialized inst, then this is not the pattern
300-
// that we are looking for.
301-
if (!MUI)
302-
return false;
303-
304-
// Ok, we found it. Replace all uses of this project box with the
305-
// mark_uninitialized and then erase it.
306-
PBI->replaceAllUsesWith(MUI);
307-
PBI->eraseFromParent();
308-
return true;
309-
}
310-
311249
//===----------------------------------------------------------------------===//
312250
// Top Level Entry Point
313251
//===----------------------------------------------------------------------===//

test/SILOptimizer/ownership_model_eliminator.sil

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -229,32 +229,3 @@ bb3:
229229
%9999 = tuple()
230230
return %9999 : $()
231231
}
232-
233-
// CHECK-LABEL: sil @mark_uninitialized_project_box : $@convention(thin) () -> () {
234-
// CHECK: [[BOX:%.*]] = alloc_box
235-
// CHECK: [[PB_BOX:%.*]] = project_box [[BOX]]
236-
// CHECK: [[MUI:%.*]] = mark_uninitialized [var] [[PB_BOX]]
237-
// CHECK: store {{%.*}} to [[MUI]]
238-
// CHECK: load [[MUI]]
239-
// CHECK: load [[MUI]]
240-
// CHECK: strong_release [[BOX]]
241-
// CHECK: } // end sil function 'mark_uninitialized_project_box'
242-
sil @mark_uninitialized_project_box : $@convention(thin) () -> () {
243-
bb0:
244-
%0 = alloc_box $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
245-
%1 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>, 0
246-
%2 = mark_uninitialized [var] %1 : $*Builtin.Int32
247-
%3 = integer_literal $Builtin.Int32, 0
248-
store %3 to [trivial] %2 : $*Builtin.Int32
249-
250-
%4 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>, 0
251-
%5 = load [trivial] %4 : $*Builtin.Int32
252-
253-
%6 = copy_value %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
254-
%7 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>, 0
255-
%8 = load [trivial] %7 : $*Builtin.Int32
256-
destroy_value %6 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
257-
destroy_value %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
258-
%9999 = tuple()
259-
return %9999 : $()
260-
}

0 commit comments

Comments
 (0)