Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,21 @@ void CoroCloner::create() {
// Transfer the original function's attributes.
auto FnAttrs = OrigF.getAttributes().getFnAttrs();
NewAttrs = NewAttrs.addFnAttributes(Context, AttrBuilder(Context, FnAttrs));

// Mark async funclets that "pop the frame" if the async function is marked
// with the `async_entry` function attribute. Remove the `async_entry`
// attribute from clones.
bool HasAsyncEntryAttribute = OrigF.hasFnAttribute("async_entry");
auto ProjectionFunctionName =
ActiveAsyncSuspend->getAsyncContextProjectionFunction()->getName();
bool IsAsyncFramePop =
ProjectionFunctionName.equals("__swift_async_resume_project_context");
if (HasAsyncEntryAttribute) {
NewAttrs = NewAttrs.removeFnAttribute(Context, "async_entry");
if (IsAsyncFramePop) {
NewAttrs = NewAttrs.addFnAttribute(Context, "async_ret");
}
}
break;
}
case coro::ABI::Retcon:
Expand Down
5 changes: 4 additions & 1 deletion llvm/test/Transforms/Coroutines/coro-async.ll
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ entry:
}


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

; CHECK-LABEL: define internal swifttailcc void @my_async_functionTQ0_(ptr nocapture readonly swiftasync %0, ptr %1, ptr nocapture readnone %2)
; CHECK-O0-LABEL: define internal swifttailcc void @my_async_functionTQ0_(ptr swiftasync %0, ptr %1, ptr %2)
; CHECK-SAME: #[[ATTRS:[0-9]+]]
; CHECK-SAME: !dbg ![[SP2:[0-9]+]] {
; CHECK: entryresume.0:
; CHECK: [[CALLER_CONTEXT:%.*]] = load ptr, ptr %0
Expand Down Expand Up @@ -514,6 +515,8 @@ declare ptr @hide(ptr)
!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!0}

; CHECK: #[[ATTRS]] = {{.*}}async_ret

!0 = !{i32 2, !"Debug Info Version", i32 3}
; CHECK: ![[SP1]] = distinct !DISubprogram(name: "my_async_function",
; CHECK-SAME: linkageName: "my_async_function",
Expand Down