Skip to content

Commit 61e1afd

Browse files
authored
Merge pull request swiftlang#27926 from eeckstein/destroy-hoisting
DestroyHoisting: support of begin_apply and end_apply instructions
2 parents dc716a2 + fbd41f7 commit 61e1afd

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/SIL/MemoryLifetime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ bool MemoryLocations::analyzeLocationUsesRecursively(SILValue V, unsigned locIdx
297297
case SILInstructionKind::DestroyAddrInst:
298298
case SILInstructionKind::ApplyInst:
299299
case SILInstructionKind::TryApplyInst:
300+
case SILInstructionKind::BeginApplyInst:
300301
case SILInstructionKind::DebugValueAddrInst:
301302
case SILInstructionKind::CopyAddrInst:
302303
case SILInstructionKind::YieldInst:

lib/SILOptimizer/Transforms/DestroyHoisting.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ void DestroyHoisting::getUsedLocationsOfInst(Bits &bits, SILInstruction *I) {
318318
getUsedLocationsOfAddr(bits, LBI->getOperand());
319319
}
320320
break;
321+
case SILInstructionKind::EndApplyInst:
322+
// Operands passed to begin_apply are alive throughout the end_apply.
323+
I = cast<EndApplyInst>(I)->getBeginApply();
324+
LLVM_FALLTHROUGH;
321325
case SILInstructionKind::LoadInst:
322326
case SILInstructionKind::StoreInst:
323327
case SILInstructionKind::CopyAddrInst:

test/SILOptimizer/destroy_hoisting.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,24 @@ bb1:
209209
destroy_addr %0 : $*Mixed
210210
return %v : $Int
211211
}
212+
213+
sil @coro : $@yield_once @convention(thin) (@in S) -> @yields @inout Int
214+
215+
// CHECK-LABEL: sil [ossa] @test_begin_apply
216+
// CHECK: end_apply
217+
// CHECK-NEXT: destroy_addr %0
218+
// CHECK-NEXT: br bb1
219+
// CHECK: bb1:
220+
// CHECK: return
221+
sil [ossa] @test_begin_apply : $@convention(thin) (@in S, Int) -> () {
222+
bb0(%0 : $*S, %1 : $Int):
223+
%f = function_ref @coro : $@yield_once @convention(thin) (@in S) -> @yields @inout Int
224+
(%i, %t) = begin_apply %f(%0) : $@yield_once @convention(thin) (@in S) -> @yields @inout Int
225+
store %1 to [trivial] %i : $*Int
226+
end_apply %t
227+
br bb1
228+
bb1:
229+
destroy_addr %0 : $*S
230+
%r = tuple ()
231+
return %r : $()
232+
}

0 commit comments

Comments
 (0)