Skip to content

Commit fe040e5

Browse files
Merge pull request #11012 from nate-chandler/cherrypick/stable/20250601/async_call_ret_metadata
[stable/20250601] Coro: Add a function attribute for resume from call async functlets
2 parents ad50149 + 579b768 commit fe040e5

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
@@ -1002,6 +1002,21 @@ void coro::BaseCloner::create() {
10021002
// Transfer the original function's attributes.
10031003
auto FnAttrs = OrigF.getAttributes().getFnAttrs();
10041004
NewAttrs = NewAttrs.addFnAttributes(Context, AttrBuilder(Context, FnAttrs));
1005+
1006+
// Mark async funclets that "pop the frame" if the async function is marked
1007+
// with the `async_entry` function attribute. Remove the `async_entry`
1008+
// attribute from clones.
1009+
bool HasAsyncEntryAttribute = OrigF.hasFnAttribute("async_entry");
1010+
auto ProjectionFunctionName =
1011+
ActiveAsyncSuspend->getAsyncContextProjectionFunction()->getName();
1012+
bool IsAsyncFramePop =
1013+
ProjectionFunctionName == "__swift_async_resume_project_context";
1014+
if (HasAsyncEntryAttribute) {
1015+
NewAttrs = NewAttrs.removeFnAttribute(Context, "async_entry");
1016+
if (IsAsyncFramePop) {
1017+
NewAttrs = NewAttrs.addFnAttribute(Context, "async_ret");
1018+
}
1019+
}
10051020
break;
10061021
}
10071022
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)