Skip to content

Commit b5af722

Browse files
committed
DestroyHoisting: support of abort_apply instruction.
This was missing from the previous commit.
1 parent eb8182b commit b5af722

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

lib/SILOptimizer/Transforms/DestroyHoisting.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class DestroyHoisting {
9595

9696
void getUsedLocationsOfAddr(Bits &bits, SILValue addr);
9797

98+
void getUsedLocationsOfOperands(Bits &bits, SILInstruction *I);
99+
98100
void getUsedLocationsOfInst(Bits &bits, SILInstruction *Inst);
99101

100102
void moveDestroys(MemoryDataflow &dataFlow);
@@ -308,6 +310,12 @@ void DestroyHoisting::getUsedLocationsOfAddr(Bits &bits, SILValue addr) {
308310
}
309311
}
310312

313+
void DestroyHoisting::getUsedLocationsOfOperands(Bits &bits, SILInstruction *I) {
314+
for (Operand &op : I->getAllOperands()) {
315+
getUsedLocationsOfAddr(bits, op.get());
316+
}
317+
}
318+
311319
// Set all bits of locations which instruction \p I is using. It's including
312320
// parent and sub-locations (see comment in getUsedLocationsOfAddr).
313321
void DestroyHoisting::getUsedLocationsOfInst(Bits &bits, SILInstruction *I) {
@@ -319,18 +327,20 @@ void DestroyHoisting::getUsedLocationsOfInst(Bits &bits, SILInstruction *I) {
319327
}
320328
break;
321329
case SILInstructionKind::EndApplyInst:
322-
// Operands passed to begin_apply are alive throughout the end_apply.
323-
I = cast<EndApplyInst>(I)->getBeginApply();
324-
LLVM_FALLTHROUGH;
330+
// Operands passed to begin_apply are alive throughout an end_apply ...
331+
getUsedLocationsOfOperands(bits, cast<EndApplyInst>(I)->getBeginApply());
332+
break;
333+
case SILInstructionKind::AbortApplyInst:
334+
// ... or abort_apply.
335+
getUsedLocationsOfOperands(bits, cast<AbortApplyInst>(I)->getBeginApply());
336+
break;
325337
case SILInstructionKind::LoadInst:
326338
case SILInstructionKind::StoreInst:
327339
case SILInstructionKind::CopyAddrInst:
328340
case SILInstructionKind::ApplyInst:
329341
case SILInstructionKind::TryApplyInst:
330342
case SILInstructionKind::YieldInst:
331-
for (Operand &op : I->getAllOperands()) {
332-
getUsedLocationsOfAddr(bits, op.get());
333-
}
343+
getUsedLocationsOfOperands(bits, I);
334344
break;
335345
case SILInstructionKind::DebugValueAddrInst:
336346
case SILInstructionKind::DestroyAddrInst:

test/SILOptimizer/destroy_hoisting.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,21 @@ bb1:
230230
%r = tuple ()
231231
return %r : $()
232232
}
233+
234+
// CHECK-LABEL: sil [ossa] @test_abort_apply
235+
// CHECK: abort_apply
236+
// CHECK-NEXT: destroy_addr %0
237+
// CHECK-NEXT: br bb1
238+
// CHECK: bb1:
239+
// CHECK: return
240+
sil [ossa] @test_abort_apply : $@convention(thin) (@in S, Int) -> () {
241+
bb0(%0 : $*S, %1 : $Int):
242+
%f = function_ref @coro : $@yield_once @convention(thin) (@in S) -> @yields @inout Int
243+
(%i, %t) = begin_apply %f(%0) : $@yield_once @convention(thin) (@in S) -> @yields @inout Int
244+
abort_apply %t
245+
br bb1
246+
bb1:
247+
destroy_addr %0 : $*S
248+
%r = tuple ()
249+
return %r : $()
250+
}

0 commit comments

Comments
 (0)