97 lines · plain
1; RUN: opt < %s -O0 -S | FileCheck %s2 3target datalayout = "p:64:64:64"4 5%async.task = type { i64 }6%async.actor = type { i64 }7%async.fp = type <{ i32, i32 }>8 9%async.ctxt = type { ptr, ptr }10 11@my_other_async_function_fp = external global <{ i32, i32 }>12declare void @my_other_async_function(ptr %async.ctxt)13 14@my_async_function_fp = constant <{ i32, i32 }>15 <{ i32 trunc (16 i64 sub (17 i64 ptrtoint (ptr @my_async_function to i64),18 i64 ptrtoint (ptr getelementptr inbounds (<{ i32, i32 }>, ptr @my_async_function_fp, i32 0, i32 1) to i64)19 )20 to i32),21 i32 3222}>23 24declare void @opaque(ptr)25declare ptr @llvm.coro.async.context.alloc(ptr, ptr)26declare void @llvm.coro.async.context.dealloc(ptr)27declare ptr @llvm.coro.async.resume()28declare token @llvm.coro.id.async(i32, i32, i32, ptr)29declare ptr @llvm.coro.begin(token, ptr)30declare void @llvm.coro.end.async(ptr, i1, ...)31declare void @llvm.coro.end(ptr, i1, token)32declare swiftcc void @asyncReturn(ptr)33declare swiftcc void @asyncSuspend(ptr)34declare {ptr} @llvm.coro.suspend.async(i32, ptr, ptr, ...)35 36define swiftcc void @my_async_function.my_other_async_function_fp.apply(ptr %fnPtr, ptr %async.ctxt) {37 tail call swiftcc void %fnPtr(ptr %async.ctxt)38 ret void39}40 41define ptr @__swift_async_resume_project_context(ptr %ctxt) {42entry:43 %resume_ctxt = load ptr, ptr %ctxt, align 844 ret ptr %resume_ctxt45}46 47 48; CHECK: %my_async_function.Frame = type { i64, [48 x i8], i64, i64, [16 x i8], ptr, i64, ptr }49; CHECK: define swiftcc void @my_async_function50; CHECK: [[T0:%.*]] = getelementptr inbounds %my_async_function.Frame, ptr %async.ctx.frameptr, i32 0, i32 351; CHECK: [[T1:%.*]] = ptrtoint ptr [[T0]] to i6452; CHECK: [[T2:%.*]] = add i64 [[T1]], 3153; CHECK: [[T3:%.*]] = and i64 [[T2]], -3254; CHECK: [[T4:%.*]] = inttoptr i64 [[T3]] to ptr55; CHECK: [[FP:%.*]] = getelementptr inbounds %my_async_function.Frame, ptr %async.ctx.frameptr, i32 0, i32 056; CHECK: [[T6:%.*]] = ptrtoint ptr [[FP]] to i6457; CHECK: [[T7:%.*]] = add i64 [[T6]], 6358; CHECK: [[T8:%.*]] = and i64 [[T7]], -6459; CHECK: [[T9:%.*]] = inttoptr i64 [[T8]] to ptr60; CHECK: store i64 2, ptr [[T4]]61; CHECK: store i64 3, ptr [[T9]]62 63define swiftcc void @my_async_function(ptr swiftasync %async.ctxt) presplitcoroutine {64entry:65 %tmp = alloca i64, align 866 %tmp2 = alloca i64, align 1667 %tmp3 = alloca i64, align 3268 %tmp4 = alloca i64, align 6469 70 %id = call token @llvm.coro.id.async(i32 32, i32 16, i32 0,71 ptr @my_async_function_fp)72 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)73 store i64 0, ptr %tmp74 store i64 1, ptr %tmp275 store i64 2, ptr %tmp376 store i64 3, ptr %tmp477 78 %callee_context = call ptr @llvm.coro.async.context.alloc(ptr null, ptr null)79 %callee_context.return_to_caller.addr = getelementptr inbounds %async.ctxt, ptr %callee_context, i32 0, i32 180 %resume.func_ptr = call ptr @llvm.coro.async.resume()81 store ptr %resume.func_ptr, ptr %callee_context.return_to_caller.addr82 83 %res = call {ptr} (i32, ptr, ptr, ...) @llvm.coro.suspend.async(i32 0,84 ptr %resume.func_ptr,85 ptr @__swift_async_resume_project_context,86 ptr @my_async_function.my_other_async_function_fp.apply,87 ptr @asyncSuspend, ptr %callee_context)88 call void @opaque(ptr %tmp)89 call void @opaque(ptr %tmp2)90 call void @opaque(ptr %tmp3)91 call void @opaque(ptr %tmp4)92 call void @llvm.coro.async.context.dealloc(ptr %callee_context)93 tail call swiftcc void @asyncReturn(ptr %async.ctxt)94 call void (ptr, i1, ...) @llvm.coro.end.async(ptr %hdl, i1 0)95 unreachable96}97