Skip to content
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 include/swift/SIL/SILNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ NON_VALUE_INST(FixLifetimeInst, fix_lifetime,
SILInstruction, MayHaveSideEffects, DoesNotRelease)

NON_VALUE_INST(HopToExecutorInst, hop_to_executor,
SILInstruction, MayHaveSideEffects, DoesNotRelease)
SILInstruction, MayHaveSideEffects, MayRelease)

NON_VALUE_INST(DestroyValueInst, destroy_value,
SILInstruction, MayHaveSideEffects, MayRelease)
Expand Down
1 change: 1 addition & 0 deletions lib/SIL/IR/SILInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ bool SILInstruction::mayRelease() const {
return true;

case SILInstructionKind::DestroyValueInst:
case SILInstructionKind::HopToExecutorInst:
return true;

case SILInstructionKind::UnconditionalCheckedCastAddrInst:
Expand Down
28 changes: 28 additions & 0 deletions test/SILOptimizer/retain_release_code_motion.sil
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class C2 {
init()
}

class Y {
@_hasStorage public var c: C2 { get }
}

actor Act {
}

struct S {
var ptr : Builtin.NativeObject
}
Expand Down Expand Up @@ -1078,3 +1085,24 @@ bb0:
%12 = tuple ()
return %12 : $()
}

// CHECK-LABEL: sil @test_hop_to_executor :
// CHECK: strong_retain
// CHECK: hop_to_executor
// CHECK: strong_release
// CHECK: } // end sil function 'test_hop_to_executor'
sil @test_hop_to_executor : $@convention(thin) @async (@guaranteed Y, @guaranteed Act) -> A {
bb0(%0 : $Y, %1 : $Act):
%2 = ref_element_addr %0 : $Y, #Y.c
%3 = load %2 : $*C2
strong_retain %3 : $C2

// This is a synchronization point and any kind of other code might run here,
// which potentially can release C2.
hop_to_executor %1 : $Act

%6 = ref_element_addr %3 : $C2, #C2.current
%7 = load %6 : $*A
strong_release %3 : $C2
return %7 : $A
}