1 ; RUN: opt < %s -O0 -S | FileCheck --check-prefixes=CHECK %s
3 target datalayout = "p:64:64:64"
5 %async.task = type { i64 }
6 %async.actor = type { i64 }
7 %async.fp = type <{ i32, i32 }>
9 %async.ctxt = type { ptr, ptr }
12 @my_other_async_function_fp = external global <{ i32, i32 }>
13 declare void @my_other_async_function(ptr %async.ctxt)
15 @my_async_function_fp = constant <{ i32, i32 }>
16 <{ i32 trunc ( ; Relative pointer to async function
18 i64 ptrtoint (ptr @my_async_function to i64),
19 i64 ptrtoint (ptr getelementptr inbounds (<{ i32, i32 }>, ptr @my_async_function_fp, i32 0, i32 1) to i64)
22 i32 128 ; Initial async context size without space for frame
25 define swiftcc void @my_other_async_function_fp.apply(ptr %fnPtr, ptr %async.ctxt) {
26 tail call swiftcc void %fnPtr(ptr %async.ctxt)
30 declare void @escape(ptr)
31 declare void @store_resume(ptr)
32 define ptr @resume_context_projection(ptr %ctxt) {
34 %resume_ctxt = load ptr, ptr %ctxt, align 8
38 ; The address of alloca escapes but the analysis based on lifetimes fails to see
39 ; that it can't localize this alloca.
40 ; CHECK: define swiftcc void @my_async_function(ptr swiftasync %async.ctxt) {
43 ; CHECK-NOT: [[ESCAPED_ADDR:%.*]] = alloca i64, align 8
45 define swiftcc void @my_async_function(ptr swiftasync %async.ctxt) {
47 %escaped_addr = alloca i64
49 %id = call token @llvm.coro.id.async(i32 128, i32 16, i32 0,
50 ptr @my_async_function_fp)
51 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
52 call void @llvm.lifetime.start.p0(i64 4, ptr %escaped_addr)
53 call void @escape(ptr %escaped_addr)
59 %callee_context = call ptr @context_alloc()
61 %resume.func_ptr = call ptr @llvm.coro.async.resume()
62 call void @store_resume(ptr %resume.func_ptr)
63 %res = call {ptr, ptr, ptr} (i32, ptr, ptr, ...) @llvm.coro.suspend.async(i32 0,
65 ptr @resume_context_projection,
66 ptr @my_other_async_function_fp.apply,
67 ptr @asyncSuspend, ptr %callee_context)
71 declare { ptr, ptr, ptr, ptr } @llvm.coro.suspend.async.sl_p0i8p0i8p0i8p0i8s(i32, ptr, ptr, ...)
72 declare ptr @llvm.coro.prepare.async(ptr)
73 declare token @llvm.coro.id.async(i32, i32, i32, ptr)
74 declare ptr @llvm.coro.begin(token, ptr)
75 declare i1 @llvm.coro.end.async(ptr, i1, ...)
76 declare i1 @llvm.coro.end(ptr, i1, token)
77 declare {ptr, ptr, ptr} @llvm.coro.suspend.async(i32, ptr, ptr, ...)
78 declare ptr @context_alloc()
79 declare void @llvm.coro.async.context.dealloc(ptr)
80 declare swiftcc void @asyncSuspend(ptr)
81 declare ptr @llvm.coro.async.resume()
82 declare void @llvm.coro.async.size.replace(ptr, ptr)
83 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0
84 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0
85 attributes #0 = { argmemonly nofree nosync nounwind willreturn }