Skip to content

[semantic-sil] Update OME for having mark_uninitialized on the alloc_box instead of project_box. #8829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
P.addDiagnoseStaticExclusivity();
P.addCapturePromotion();
P.addAllocBoxToStack();
P.addMarkUninitializedFixup();
P.addNoReturnFolding();
P.addOwnershipModelEliminator();
P.addMarkUninitializedFixup();
P.addDefiniteInitialization();

P.addAccessEnforcementSelection();
Expand Down
62 changes: 0 additions & 62 deletions lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ struct OwnershipModelEliminatorVisitor
bool visitUnmanagedAutoreleaseValueInst(UnmanagedAutoreleaseValueInst *UAVI);
bool visitCheckedCastBranchInst(CheckedCastBranchInst *CBI);
bool visitSwitchEnumInst(SwitchEnumInst *SWI);
bool visitProjectBoxInst(ProjectBoxInst *PBI);
};

} // end anonymous namespace
Expand Down Expand Up @@ -247,67 +246,6 @@ bool OwnershipModelEliminatorVisitor::visitSwitchEnumInst(
return true;
}

// Since we are threading through copies, we may have situations like:
//
// let x = alloc_box $Foo
// let y = project_box x
// let z = mark_uninitialized y
// ... use z ...
//
// let y2 = project_box x
//
// let x2 = copy_value x
// let y3 = project_box y
//
// We need to move project_box like y2 and y3 to go through z so that DI can
// reason about them.
//
// Once DI is updated for ownership, this can go away.
bool OwnershipModelEliminatorVisitor::visitProjectBoxInst(ProjectBoxInst *PBI) {
// First if our operand is already a mark_uninitialized, then we do not need
// to do anything.
auto *Use = PBI->getSingleUse();
if (Use && isa<MarkUninitializedInst>(Use->getUser())) {
return false;
}

// Otherwise, lets try to find the alloc_box.
SILValue BoxValue = PBI->getOperand();
while (auto *CVI = dyn_cast<CopyValueInst>(BoxValue)) {
BoxValue = CVI->getOperand();
}

// We were unable to find the alloc_box. This must be an indirect enum box
// pattern.
auto *ABI = dyn_cast<AllocBoxInst>(BoxValue);
if (!ABI)
return false;

// See if we can find (mark_uninitialized (project_box))
SILValue MUI;
for (auto *Use : ABI->getUses()) {
auto *BoxProjection = dyn_cast<ProjectBoxInst>(Use->getUser());
if (!BoxProjection)
continue;
auto *Op = BoxProjection->getSingleUse();
if (!Op || !isa<MarkUninitializedInst>(Op->getUser()))
continue;
MUI = SILValue(Op->getUser());
break;
}

// If we did not find a mark uninitialized inst, then this is not the pattern
// that we are looking for.
if (!MUI)
return false;

// Ok, we found it. Replace all uses of this project box with the
// mark_uninitialized and then erase it.
PBI->replaceAllUsesWith(MUI);
PBI->eraseFromParent();
return true;
}

//===----------------------------------------------------------------------===//
// Top Level Entry Point
//===----------------------------------------------------------------------===//
Expand Down
29 changes: 0 additions & 29 deletions test/SILOptimizer/ownership_model_eliminator.sil
Original file line number Diff line number Diff line change
Expand Up @@ -229,32 +229,3 @@ bb3:
%9999 = tuple()
return %9999 : $()
}

// CHECK-LABEL: sil @mark_uninitialized_project_box : $@convention(thin) () -> () {
// CHECK: [[BOX:%.*]] = alloc_box
// CHECK: [[PB_BOX:%.*]] = project_box [[BOX]]
// CHECK: [[MUI:%.*]] = mark_uninitialized [var] [[PB_BOX]]
// CHECK: store {{%.*}} to [[MUI]]
// CHECK: load [[MUI]]
// CHECK: load [[MUI]]
// CHECK: strong_release [[BOX]]
// CHECK: } // end sil function 'mark_uninitialized_project_box'
sil @mark_uninitialized_project_box : $@convention(thin) () -> () {
bb0:
%0 = alloc_box $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
%1 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>, 0
%2 = mark_uninitialized [var] %1 : $*Builtin.Int32
%3 = integer_literal $Builtin.Int32, 0
store %3 to [trivial] %2 : $*Builtin.Int32

%4 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>, 0
%5 = load [trivial] %4 : $*Builtin.Int32

%6 = copy_value %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
%7 = project_box %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>, 0
%8 = load [trivial] %7 : $*Builtin.Int32
destroy_value %6 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
destroy_value %0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int32>
%9999 = tuple()
return %9999 : $()
}