Skip to content

Commit 29e830a

Browse files
asavonicasl
authored andcommitted
Handle begin_apply in PartialApplyCombiner
1 parent e4bd286 commit 29e830a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/SILOptimizer/Utils/PartialApplyCombiner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ void PartialApplyCombiner::processSingleApply(FullApplySite paiAI) {
206206
builder.createTryApply(paiAI.getLoc(), callee, subs, argList,
207207
tai->getNormalBB(), tai->getErrorBB(),
208208
tai->getApplyOptions());
209+
} else if (auto *bai = dyn_cast<BeginApplyInst>(paiAI)) {
210+
auto *newBAI = builder.createBeginApply(paiAI.getLoc(), callee, subs,
211+
argList, bai->getApplyOptions());
212+
callbacks.replaceAllInstUsesPairwiseWith(bai, newBAI);
209213
} else {
210214
auto *apply = cast<ApplyInst>(paiAI);
211215
auto *newAI = builder.createApply(paiAI.getLoc(), callee, subs, argList,

test/SILOptimizer/sil_combine_apply_ossa.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,3 +1175,33 @@ bb0(%0 : $Int):
11751175

11761176
sil [ossa] @closure2 : $@convention(thin) (Int) -> ()
11771177

1178+
sil [ossa] @yield1 : $@yield_once(Float) -> (@yields Float) {
1179+
bb0(%0 : $Float):
1180+
yield (%0 : $Float), resume bb1, unwind bb2
1181+
1182+
bb1:
1183+
%r = tuple ()
1184+
return %r : $()
1185+
1186+
bb2:
1187+
unwind
1188+
}
1189+
1190+
// CHECK-LABEL: sil [ossa] @coro_apply1
1191+
// CHECK: %[[REF:.*]] = function_ref @yield1 : $@yield_once @convention(thin) (Float) -> @yields Float
1192+
// CHECK: (%{{.*}}, %[[CONT:.*]]) = begin_apply %[[REF]](%{{.*}}) : $@yield_once @convention(thin) (Float) -> @yields Float
1193+
// CHECK: %{{.*}} = end_apply %[[CONT]] as $()
1194+
// CHECK-LABEL: } // end sil function 'coro_apply1'
1195+
sil [ossa] @coro_apply1 : $(Float) -> () {
1196+
bb0(%0 : $Float):
1197+
%coro = function_ref @yield1 : $@convention(thin) @yield_once (Float) -> (@yields Float)
1198+
%pa = partial_apply [callee_guaranteed] %coro(%0) : $@convention(thin) @yield_once (Float) -> (@yields Float)
1199+
1200+
(%float, %token) = begin_apply %pa() : $@callee_guaranteed @yield_once () -> (@yields Float)
1201+
1202+
end_apply %token as $()
1203+
destroy_value %pa : $@callee_guaranteed @yield_once () -> (@yields Float)
1204+
1205+
%r = tuple ()
1206+
return %r : $()
1207+
}

0 commit comments

Comments
 (0)