Skip to content

Commit 99df40a

Browse files
committed
[AddressLowering] Handle moveonly_to_copyable.
The _value version of the instruction lowers to the _address version.
1 parent 53fc0cb commit 99df40a

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

lib/SIL/Utils/InstWrappers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bool ForwardingOperation::hasSameRepresentation() const {
5151
case SILInstructionKind::OpenExistentialRefInst:
5252
case SILInstructionKind::OpenExistentialValueInst:
5353
case SILInstructionKind::MarkUnresolvedNonCopyableValueInst:
54+
case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
5455
case SILInstructionKind::MarkUninitializedInst:
5556
case SILInstructionKind::StructExtractInst:
5657
case SILInstructionKind::TupleExtractInst:

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ static Operand *getReusedStorageOperand(SILValue value) {
10091009
default:
10101010
break;
10111011

1012+
case ValueKind::MoveOnlyWrapperToCopyableValueInst:
10121013
case ValueKind::OpenExistentialValueInst:
10131014
case ValueKind::OpenExistentialBoxValueInst:
10141015
case ValueKind::UncheckedEnumDataInst:
@@ -3495,6 +3496,19 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
34953496

34963497
void visitMoveValueInst(MoveValueInst *mvi);
34973498

3499+
void visitMoveOnlyWrapperToCopyableValueInst(
3500+
MoveOnlyWrapperToCopyableValueInst *inst) {
3501+
assert(use == getReusedStorageOperand(inst));
3502+
assert(inst->getType().isAddressOnly(*pass.function));
3503+
SILValue srcVal = inst->getOperand();
3504+
SILValue srcAddr = pass.valueStorageMap.getStorage(srcVal).storageAddress;
3505+
3506+
auto destAddr =
3507+
builder.createMoveOnlyWrapperToCopyableAddr(inst->getLoc(), srcAddr);
3508+
3509+
markRewritten(inst, destAddr);
3510+
}
3511+
34983512
void visitReturnInst(ReturnInst *returnInst) {
34993513
// Returns are rewritten for any function with indirect results after
35003514
// opaque value rewriting.

test/SILOptimizer/address_lowering.sil

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,34 @@ entry(%t : @owned $@moveOnly T):
25522552
return %retval : $()
25532553
}
25542554

2555+
// CHECK-LABEL: sil [ossa] @test_moveonlywrapper_to_copyable_1_owned : {{.*}} {
2556+
// CHECK: bb0([[TMO:%[^,]+]] :
2557+
// CHECK: [[T:%[^,]+]] = moveonlywrapper_to_copyable_addr [[TMO]]
2558+
// CHECK: destroy_addr [[T]]
2559+
// CHECK-LABEL: } // end sil function 'test_moveonlywrapper_to_copyable_1_owned'
2560+
sil [ossa] @test_moveonlywrapper_to_copyable_1_owned : $@convention(thin) <T> (@in @moveOnly T) -> () {
2561+
entry(%tmo : @owned $@moveOnly T):
2562+
%t = moveonlywrapper_to_copyable [owned] %tmo : $@moveOnly T
2563+
destroy_value %t : $T
2564+
%retval = tuple ()
2565+
return %retval : $()
2566+
}
2567+
2568+
// CHECK-LABEL: sil [ossa] @test_moveonlywrapper_to_copyable_2_guaranteed : {{.*}} {
2569+
// CHECK: bb0([[TMO:%[^,]+]] :
2570+
// CHECK: [[T:%[^,]+]] = moveonlywrapper_to_copyable_addr [[TMO]]
2571+
// CHECK: [[BORROW_T:%[^,]+]] = function_ref @borrowT
2572+
// CHECK: apply [[BORROW_T]]<T>([[T]])
2573+
// CHECK-LABEL: } // end sil function 'test_moveonlywrapper_to_copyable_2_guaranteed'
2574+
sil [ossa] @test_moveonlywrapper_to_copyable_2_guaranteed : $@convention(thin) <T> (@in_guaranteed @moveOnly T) -> () {
2575+
entry(%tmo : @guaranteed $@moveOnly T):
2576+
%t = moveonlywrapper_to_copyable [guaranteed] %tmo : $@moveOnly T
2577+
%borrowT = function_ref @borrowT : $@convention(thin) <T> (@in_guaranteed T) -> ()
2578+
apply %borrowT<T>(%t) : $@convention(thin) <T> (@in_guaranteed T) -> ()
2579+
%retval = tuple ()
2580+
return %retval : $()
2581+
}
2582+
25552583
// CHECK-LABEL: sil [ossa] @test_open_pack_element_dominance : $@convention(thin) <each T> (@pack_guaranteed Pack{repeat each T}, Builtin.Word) -> () {
25562584
// CHECK: bb0([[PACK:%[^,]+]] :
25572585
// CHECK-SAME: [[RAW_INDEX:%[^,]+]] :

0 commit comments

Comments
 (0)