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 { i8*, void (i8*, %async.task*, %async.actor*)* }
12 @my_other_async_function_fp = external global <{ i32, i32 }>
13 declare void @my_other_async_function(i8* %async.ctxt)
15 @my_async_function_fp = constant <{ i32, i32 }>
16 <{ i32 trunc ( ; Relative pointer to async function
18 i64 ptrtoint (void (i8*)* @my_async_function to i64),
19 i64 ptrtoint (i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @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(i8* %fnPtr, i8* %async.ctxt) {
26 %callee = bitcast i8* %fnPtr to void(i8*)*
27 tail call swiftcc void %callee(i8* %async.ctxt)
31 declare void @escape(i64*)
32 declare void @store_resume(i8*)
33 declare i1 @exitLoop()
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 define swiftcc void @my_async_function(i8* swiftasync %async.ctxt) {
43 %escaped_addr = alloca i64
45 %id = call token @llvm.coro.id.async(i32 128, i32 16, i32 0,
46 i8* bitcast (<{i32, i32}>* @my_async_function_fp to i8*))
47 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
48 %ltb = bitcast i64* %escaped_addr to i8*
49 call void @llvm.lifetime.start.p0i8(i64 4, i8* %ltb)
55 %callee_context = call i8* @context_alloc()
57 %resume.func_ptr = call i8* @llvm.coro.async.resume()
58 call void @store_resume(i8* %resume.func_ptr)
59 %resume_proj_fun = bitcast i8*(i8*)* @resume_context_projection to i8*
60 %callee = bitcast void(i8*)* @asyncSuspend to i8*
61 %res = call {i8*, i8*, i8*} (i32, i8*, i8*, ...) @llvm.coro.suspend.async(i32 0,
64 void (i8*, i8*)* @my_other_async_function_fp.apply,
65 i8* %callee, i8* %callee_context)
66 call void @escape(i64* %escaped_addr)
67 %exitCond = call i1 @exitLoop()
69 ;; We used to move the lifetime.start intrinsic here =>
70 ;; This exposes two bugs:
71 ; 1.) The code should use the basic block start not end as insertion point
72 ; More problematically:
73 ; 2.) The code marks the stack object as not alive for part of the loop.
75 br i1 %exitCond, label %loop_exit, label %loop
76 %res2 = call {i8*, i8*, i8*} (i32, i8*, i8*, ...) @llvm.coro.suspend.async(i32 0,
79 void (i8*, i8*)* @my_other_async_function_fp.apply,
80 i8* %callee, i8* %callee_context)
82 %exitCond2 = call i1 @exitLoop()
83 br i1 %exitCond2, label %loop_exit, label %loop
89 call void @llvm.lifetime.end.p0i8(i64 4, i8* %ltb)
90 call i1 (i8*, i1, ...) @llvm.coro.end.async(i8* %hdl, i1 false)
94 ; CHECK: define {{.*}} void @my_async_function.resume.0(
95 ; CHECK-NOT: call void @llvm.lifetime.start.p0i8(i64 4, i8* %3)
96 ; CHECK: br i1 %exitCond, label %loop_exit, label %loop
100 declare { i8*, i8*, i8*, i8* } @llvm.coro.suspend.async.sl_p0i8p0i8p0i8p0i8s(i32, i8*, i8*, ...)
101 declare i8* @llvm.coro.prepare.async(i8*)
102 declare token @llvm.coro.id.async(i32, i32, i32, i8*)
103 declare i8* @llvm.coro.begin(token, i8*)
104 declare i1 @llvm.coro.end.async(i8*, i1, ...)
105 declare i1 @llvm.coro.end(i8*, i1)
106 declare {i8*, i8*, i8*} @llvm.coro.suspend.async(i32, i8*, i8*, ...)
107 declare i8* @context_alloc()
108 declare void @llvm.coro.async.context.dealloc(i8*)
109 declare swiftcc void @asyncSuspend(i8*)
110 declare i8* @llvm.coro.async.resume()
111 declare void @llvm.coro.async.size.replace(i8*, i8*)
112 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
113 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
114 attributes #0 = { argmemonly nofree nosync nounwind willreturn }