Skip to content

Commit 2619ea9

Browse files
committed
[Coro] [async] Make sure to reprocess non-split async functions
We do this to inline the coro.end.async's tail called function into the non-split async coroutine. rdar://136296219
1 parent cdc8e8b commit 2619ea9

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,10 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C,
22252225
UR.CWorklist.insert(&C);
22262226
for (Function *Clone : Clones)
22272227
UR.CWorklist.insert(CG.lookupSCC(CG.get(*Clone)));
2228+
} else if (Shape.ABI == coro::ABI::Async) {
2229+
// Reprocess the function to inline the tail called return function of
2230+
// coro.async.end.
2231+
UR.CWorklist.insert(&C);
22282232
}
22292233
}
22302234

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,35 @@ entry:
497497
; CHECK: call void @use(ptr null)
498498
; CHECK: ret
499499

500+
@simpleFuncTu = global <{i32, i32}> <{
501+
i32 trunc (i64 sub (i64 ptrtoint (ptr @simpleFunc to i64),
502+
i64 ptrtoint (ptr @simpleFuncTu to i64)) to i32), i32 16 }>
503+
504+
define swifttailcc void @simpleFunc(ptr swiftasync %0) presplitcoroutine {
505+
entry:
506+
%1 = alloca ptr, align 8
507+
%2 = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, ptr @simpleFuncTu)
508+
%3 = call ptr @llvm.coro.begin(token %2, ptr null)
509+
store ptr %0, ptr %1, align 8
510+
%4 = load ptr, ptr %1, align 8
511+
%5 = getelementptr inbounds <{ ptr, ptr }>, ptr %4, i32 0, i32 1
512+
%6 = load ptr, ptr %5, align 8
513+
%7 = load ptr, ptr %1, align 8
514+
%8 = call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %3, i1 false, ptr @simpleFunc.0, ptr %6, ptr %7)
515+
unreachable
516+
}
517+
518+
; CHECK-LABEL: define swifttailcc void @simpleFunc(ptr swiftasync %0) {
519+
; CHECK-NOT: define
520+
; CHECK: [[RESUME:%.*]] = load ptr
521+
; CHECK: musttail call swifttailcc void [[RESUME]]
522+
523+
define internal swifttailcc void @simpleFunc.0(ptr %0, ptr %1) alwaysinline {
524+
entry:
525+
musttail call swifttailcc void %0(ptr swiftasync %1)
526+
ret void
527+
}
528+
500529
declare { ptr, ptr, ptr, ptr } @llvm.coro.suspend.async.sl_p0i8p0i8p0i8p0i8s(i32, ptr, ptr, ...)
501530
declare ptr @llvm.coro.prepare.async(ptr)
502531
declare token @llvm.coro.id.async(i32, i32, i32, ptr)

0 commit comments

Comments
 (0)