Skip to content

Commit f5046f2

Browse files
Merge pull request swiftlang#11047 from swiftlang/jepa-stable2
[stable/21.x] Coro: Add a function attribute for resume from call async functlets
2 parents 6984743 + bfb64aa commit f5046f2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,21 @@ void coro::BaseCloner::create() {
989989
// Transfer the original function's attributes.
990990
auto FnAttrs = OrigF.getAttributes().getFnAttrs();
991991
NewAttrs = NewAttrs.addFnAttributes(Context, AttrBuilder(Context, FnAttrs));
992+
993+
// Mark async funclets that "pop the frame" if the async function is marked
994+
// with the `async_entry` function attribute. Remove the `async_entry`
995+
// attribute from clones.
996+
bool HasAsyncEntryAttribute = OrigF.hasFnAttribute("async_entry");
997+
auto ProjectionFunctionName =
998+
ActiveAsyncSuspend->getAsyncContextProjectionFunction()->getName();
999+
bool IsAsyncFramePop =
1000+
ProjectionFunctionName == "__swift_async_resume_project_context";
1001+
if (HasAsyncEntryAttribute) {
1002+
NewAttrs = NewAttrs.removeFnAttribute(Context, "async_entry");
1003+
if (IsAsyncFramePop) {
1004+
NewAttrs = NewAttrs.addFnAttribute(Context, "async_ret");
1005+
}
1006+
}
9921007
break;
9931008
}
9941009
case coro::ABI::Retcon:

llvm/test/Transforms/Coroutines/coro-async.ll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ entry:
5858
}
5959

6060

61-
define swiftcc void @my_async_function(ptr swiftasync %async.ctxt, ptr %task, ptr %actor) presplitcoroutine !dbg !1 {
61+
define swiftcc void @my_async_function(ptr swiftasync %async.ctxt, ptr %task, ptr %actor) presplitcoroutine "async_entry" !dbg !1 {
6262
entry:
6363
%tmp = alloca { i64, i64 }, align 8
6464
%vector = alloca <4 x double>, align 16
@@ -145,6 +145,7 @@ define void @my_async_function_pa(ptr %ctxt, ptr %task, ptr %actor) {
145145

146146
; CHECK-LABEL: define internal swiftcc void @my_async_functionTQ0_(ptr readonly swiftasync captures(none) %0, ptr %1, ptr readnone captures(none) %2)
147147
; CHECK-O0-LABEL: define internal swiftcc void @my_async_functionTQ0_(ptr swiftasync %0, ptr %1, ptr %2)
148+
; CHECK-SAME: #[[ATTRS:[0-9]+]]
148149
; CHECK-SAME: !dbg ![[SP2:[0-9]+]] {
149150
; CHECK: entryresume.0:
150151
; CHECK: [[CALLER_CONTEXT:%.*]] = load ptr, ptr %0
@@ -514,6 +515,8 @@ declare ptr @hide(ptr)
514515
!llvm.dbg.cu = !{!2}
515516
!llvm.module.flags = !{!0}
516517

518+
; CHECK: #[[ATTRS]] = {{.*}}async_ret
519+
517520
!0 = !{i32 2, !"Debug Info Version", i32 3}
518521
; CHECK: ![[SP1]] = distinct !DISubprogram(name: "my_async_function",
519522
; CHECK-SAME: linkageName: "my_async_function",

0 commit comments

Comments
 (0)