Skip to content

Commit 79f6504

Browse files
committed
Teach the ownership model eliminator how to lower explicit-copy-addr.
Later parts of the pipeline do not know about the instruction, so we need to lower it there. This is additionally safe since we will not be performing move only checking later in the pipeline.
1 parent 6c922af commit 79f6504

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/SILOptimizer/Mandatory/OwnershipModelEliminator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct OwnershipModelEliminatorVisitor
134134
bool visitStoreBorrowInst(StoreBorrowInst *si);
135135
bool visitCopyValueInst(CopyValueInst *cvi);
136136
bool visitExplicitCopyValueInst(ExplicitCopyValueInst *cvi);
137+
bool visitExplicitCopyAddrInst(ExplicitCopyAddrInst *cai);
137138
bool visitDestroyValueInst(DestroyValueInst *dvi);
138139
bool visitLoadBorrowInst(LoadBorrowInst *lbi);
139140
bool visitMoveValueInst(MoveValueInst *mvi) {
@@ -334,6 +335,18 @@ bool OwnershipModelEliminatorVisitor::visitExplicitCopyValueInst(
334335
return true;
335336
}
336337

338+
bool OwnershipModelEliminatorVisitor::visitExplicitCopyAddrInst(
339+
ExplicitCopyAddrInst *ecai) {
340+
// Now that we have set the unqualified ownership flag, destroy value
341+
// operation will delegate to the appropriate strong_release, etc.
342+
withBuilder<void>(ecai, [&](SILBuilder &b, SILLocation loc) {
343+
b.createCopyAddr(loc, ecai->getSrc(), ecai->getDest(), ecai->isTakeOfSrc(),
344+
ecai->isInitializationOfDest());
345+
});
346+
eraseInstruction(ecai);
347+
return true;
348+
}
349+
337350
bool OwnershipModelEliminatorVisitor::visitUnmanagedRetainValueInst(
338351
UnmanagedRetainValueInst *urvi) {
339352
// Now that we have set the unqualified ownership flag, destroy value

test/SILOptimizer/ownership_model_eliminator.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,16 @@ bb0(%0 : @guaranteed $Builtin.NativeObject):
381381
%9999 = tuple()
382382
return %9999 : $()
383383
}
384+
385+
// CHECK-LABEL: sil @lower_explicit_copy_addr : $@convention(thin) (@in_guaranteed C) -> () {
386+
// CHECK: {{[^_]copy_addr}}
387+
// CHECK: } // end sil function 'lower_explicit_copy_addr'
388+
sil [ossa] @lower_explicit_copy_addr : $@convention(thin) (@in_guaranteed C) -> () {
389+
bb0(%0 : $*C):
390+
%1 = alloc_stack $C
391+
explicit_copy_addr %0 to [init] %1 : $*C
392+
destroy_addr %1 : $*C
393+
dealloc_stack %1 : $*C
394+
%9999 = tuple()
395+
return %9999 : $()
396+
}

0 commit comments

Comments
 (0)