1 ; RUN: opt < %s -enable-coroutines -passes='default<O0>' -S | FileCheck --check-prefixes=CHECK %s
2 ; RUN: opt < %s -enable-coroutines -O0 -S | FileCheck --check-prefixes=CHECK %s
4 target datalayout = "p:64:64:64"
6 %async.task = type { i64 }
7 %async.actor = type { i64 }
8 %async.fp = type <{ i32, i32 }>
10 %async.ctxt = type { i8*, void (i8*, %async.task*, %async.actor*)* }
13 @my_other_async_function_fp = external global <{ i32, i32 }>
14 declare void @my_other_async_function(i8* %async.ctxt)
16 @my_async_function_fp = constant <{ i32, i32 }>
17 <{ i32 trunc ( ; Relative pointer to async function
19 i64 ptrtoint (void (i8*)* @my_async_function to i64),
20 i64 ptrtoint (i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @my_async_function_fp, i32 0, i32 1) to i64)
23 i32 128 ; Initial async context size without space for frame
26 define swiftcc void @my_other_async_function_fp.apply(i8* %fnPtr, i8* %async.ctxt) {
27 %callee = bitcast i8* %fnPtr to void(i8*)*
28 tail call swiftcc void %callee(i8* %async.ctxt)
32 declare void @escape(i64*)
33 declare void @store_resume(i8*)
34 define i8* @resume_context_projection(i8* %ctxt) {
36 %resume_ctxt_addr = bitcast i8* %ctxt to i8**
37 %resume_ctxt = load i8*, i8** %resume_ctxt_addr, align 8
41 ; The address of alloca escapes but the analysis based on lifetimes fails to see
42 ; that it can't localize this alloca.
43 ; CHECK: define swiftcc void @my_async_function(i8* swiftasync %async.ctxt) {
46 ; CHECK-NOT: [[ESCAPED_ADDR:%.*]] = alloca i64, align 8
48 define swiftcc void @my_async_function(i8* swiftasync %async.ctxt) {
50 %escaped_addr = alloca i64
52 %id = call token @llvm.coro.id.async(i32 128, i32 16, i32 0,
53 i8* bitcast (<{i32, i32}>* @my_async_function_fp to i8*))
54 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
55 %ltb = bitcast i64* %escaped_addr to i8*
56 call void @llvm.lifetime.start.p0i8(i64 4, i8* %ltb)
57 call void @escape(i64* %escaped_addr)
63 %callee_context = call i8* @context_alloc()
65 %resume.func_ptr = call i8* @llvm.coro.async.resume()
66 call void @store_resume(i8* %resume.func_ptr)
67 %resume_proj_fun = bitcast i8*(i8*)* @resume_context_projection to i8*
68 %callee = bitcast void(i8*)* @asyncSuspend to i8*
69 %res = call {i8*, i8*, i8*} (i32, i8*, i8*, ...) @llvm.coro.suspend.async(i32 0,
72 void (i8*, i8*)* @my_other_async_function_fp.apply,
73 i8* %callee, i8* %callee_context)
77 declare { i8*, i8*, i8*, i8* } @llvm.coro.suspend.async.sl_p0i8p0i8p0i8p0i8s(i32, i8*, i8*, ...)
78 declare i8* @llvm.coro.prepare.async(i8*)
79 declare token @llvm.coro.id.async(i32, i32, i32, i8*)
80 declare i8* @llvm.coro.begin(token, i8*)
81 declare i1 @llvm.coro.end.async(i8*, i1, ...)
82 declare i1 @llvm.coro.end(i8*, i1)
83 declare {i8*, i8*, i8*} @llvm.coro.suspend.async(i32, i8*, i8*, ...)
84 declare i8* @context_alloc()
85 declare void @llvm.coro.async.context.dealloc(i8*)
86 declare swiftcc void @asyncSuspend(i8*)
87 declare i8* @llvm.coro.async.resume()
88 declare void @llvm.coro.async.size.replace(i8*, i8*)
89 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
90 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
91 attributes #0 = { argmemonly nofree nosync nounwind willreturn }