Skip to content

Commit 3cd48ec

Browse files
Merge pull request #77715 from nate-chandler/general-coro/20241119/1
[CoroutineAccessors] Rewrite allocs in LoadableByAddress.
2 parents ec85589 + 79c62dd commit 3cd48ec

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,10 @@ void LoadableByAddress::recreateSingleApply(
25902590
// Use the new token result.
25912591
oldApply->getTokenResult()->replaceAllUsesWith(newApply->getTokenResult());
25922592

2593+
if (auto *allocation = oldApply->getCalleeAllocationResult()) {
2594+
allocation->replaceAllUsesWith(newApply->getCalleeAllocationResult());
2595+
}
2596+
25932597
// Rewrite all the yields.
25942598
auto oldYields = oldApply->getOrigCalleeType()->getYields();
25952599
auto oldYieldedValues = oldApply->getYieldedValues();

test/IRGen/loadable_by_address.sil

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %target-swift-frontend %s -Xllvm -sil-print-after=loadable-address -import-objc-header %S/Inputs/large_c.h -c -o %t/t.o 2>&1 | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
struct X {
9+
var x1 : Int
10+
var x2 : Int
11+
var x3 : Int
12+
var x4: Int
13+
var x5: Int
14+
var x6: Int
15+
var x7: Int
16+
var x8: Int
17+
var x9: Int
18+
var x10: Int
19+
var x11: Int
20+
var x12: Int
21+
var x13: Int
22+
var x14: Int
23+
var x15: Int
24+
var x16: Int
25+
}
26+
27+
sil @yield_nothing_take_x : $@convention(thin) @yield_once_2 (@owned X) -> (@yields @in_guaranteed ()) {
28+
entry(%x : $X):
29+
%void_addr = alloc_stack $()
30+
%void = tuple ()
31+
store %void to %void_addr : $*()
32+
yield %void_addr : $*(), resume bb1, unwind bb2
33+
34+
bb1:
35+
dealloc_stack %void_addr : $*()
36+
return %void : $()
37+
38+
bb2:
39+
dealloc_stack %void_addr : $*()
40+
unwind
41+
}
42+
43+
// CHECK-LABEL: sil @begin_apply_x_yielder : {{.*}} {
44+
// CHECK: ({{%[^,]+}}, {{%[^,]+}}, [[ALLOCATION:%[^,]+]]) = begin_apply
45+
// CHECK: dealloc_stack [[ALLOCATION]]
46+
// CHECK-LABEL: } // end sil function 'begin_apply_x_yielder'
47+
sil @begin_apply_x_yielder : $@convention(thin) (@owned X) -> () {
48+
entry(%x : $X):
49+
%fn = function_ref @yield_nothing_take_x : $@convention(thin) @yield_once_2 (@owned X) -> (@yields @in_guaranteed ())
50+
(%void, %token, %allocation) = begin_apply %fn(%x) : $@convention(thin) @yield_once_2 (@owned X) -> (@yields @in_guaranteed ())
51+
end_apply %token as $()
52+
dealloc_stack %allocation : $*Builtin.SILToken
53+
%retval = tuple ()
54+
return %retval : $()
55+
}

0 commit comments

Comments
 (0)