Skip to content

Commit 9871adc

Browse files
[coro] [async] Make sure to reprocess non-split async functions (#153419)
We do this to inline the coro.end.async's tail called function into the non-split async coroutine. rdar://136296219
1 parent 7e125b9 commit 9871adc

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
@@ -2252,6 +2252,10 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C,
22522252
UR.CWorklist.insert(CurrentSCC);
22532253
for (Function *Clone : Clones)
22542254
UR.CWorklist.insert(CG.lookupSCC(CG.get(*Clone)));
2255+
} else if (Shape.ABI == coro::ABI::Async) {
2256+
// Reprocess the function to inline the tail called return function of
2257+
// coro.async.end.
2258+
UR.CWorklist.insert(&C);
22552259
}
22562260
}
22572261

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

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

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

0 commit comments

Comments
 (0)