1 ; Tests that invoke <type> @llvm.coro.await.suspend lowers to invoke @helper
2 ; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split),simplifycfg' -S | FileCheck %s
6 ; CHECK: define {{[^@]*}} @f.resume(ptr {{[^%]*}} %[[HDL:.+]])
7 ; CHECK: %[[AWAITER:.+]] = getelementptr inbounds %f.Frame, ptr %[[HDL]], i32 0, i32 0
8 define void @f() presplitcoroutine personality i32 0 {
10 %awaiter = alloca %Awaiter
11 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
12 %size = call i32 @llvm.coro.size.i32()
13 %alloc = call ptr @malloc(i32 %size)
14 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
15 ; Initial suspend so that all 3 await_suspend invocations are inside f.resume
16 %suspend.init = call i8 @llvm.coro.suspend(token none, i1 false)
17 switch i8 %suspend.init, label %ret [
22 ; CHECK: invoke void @await_suspend_wrapper_void(ptr %[[AWAITER]], ptr %[[HDL]])
23 ; CHECK-NEXT: to label %[[STEP_CONT:[^ ]+]] unwind label %[[PAD:[^ ]+]]
25 %save = call token @llvm.coro.save(ptr null)
26 invoke void @llvm.coro.await.suspend.void(ptr %awaiter, ptr %hdl, ptr @await_suspend_wrapper_void)
27 to label %step.continue unwind label %pad
29 ; CHECK [[STEP_CONT]]:
31 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
32 switch i8 %suspend, label %ret [
37 ; CHECK: %[[RESUME:.+]] = invoke i1 @await_suspend_wrapper_bool(ptr %[[AWAITER]], ptr %[[HDL]])
38 ; CHECK-NEXT: to label %[[STEP1_CONT:[^ ]+]] unwind label %[[PAD]]
40 %save1 = call token @llvm.coro.save(ptr null)
41 %resume.bool = invoke i1 @llvm.coro.await.suspend.bool(ptr %awaiter, ptr %hdl, ptr @await_suspend_wrapper_bool)
42 to label %step1.continue unwind label %pad
44 ; CHECK: [[STEP1_CONT]]:
45 ; CHECK-NEXT: br i1 %[[RESUME]], label %{{[^,]+}}, label %[[STEP2:.+]]
47 br i1 %resume.bool, label %suspend.cond, label %step2
50 %suspend1 = call i8 @llvm.coro.suspend(token %save1, i1 false)
51 switch i8 %suspend1, label %ret [
57 ; CHECK: %[[NEXT_HDL:.+]] = invoke ptr @await_suspend_wrapper_handle(ptr %[[AWAITER]], ptr %[[HDL]])
58 ; CHECK-NEXT: to label %[[STEP2_CONT:[^ ]+]] unwind label %[[PAD]]
60 %save2 = call token @llvm.coro.save(ptr null)
61 invoke void @llvm.coro.await.suspend.handle(ptr %awaiter, ptr %hdl, ptr @await_suspend_wrapper_handle)
62 to label %step2.continue unwind label %pad
64 ; CHECK: [[STEP2_CONT]]:
65 ; CHECK-NEXT: %[[NEXT_RESUME:.+]] = call ptr @llvm.coro.subfn.addr(ptr %[[NEXT_HDL]], i8 0)
66 ; CHECK-NEXT: musttail call {{.*}} void %[[NEXT_RESUME]](ptr %[[NEXT_HDL]])
68 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
69 switch i8 %suspend2, label %ret [
78 %lp = landingpad { ptr, i32 }
80 %exn = extractvalue { ptr, i32 } %lp, 0
81 call ptr @__cxa_begin_catch(ptr %exn)
82 call void @__cxa_end_catch()
86 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
87 call void @free(ptr %mem)
91 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
95 ; check that we were haven't accidentally went out of @f.resume body
96 ; CHECK-LABEL: @f.destroy(
97 ; CHECK-LABEL: @f.cleanup(
99 declare void @await_suspend_wrapper_void(ptr, ptr)
100 declare i1 @await_suspend_wrapper_bool(ptr, ptr)
101 declare ptr @await_suspend_wrapper_handle(ptr, ptr)
103 declare ptr @llvm.coro.free(token, ptr)
104 declare i32 @llvm.coro.size.i32()
105 declare i8 @llvm.coro.suspend(token, i1)
106 declare void @llvm.coro.resume(ptr)
107 declare void @llvm.coro.destroy(ptr)
109 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
110 declare i1 @llvm.coro.alloc(token)
111 declare ptr @llvm.coro.begin(token, ptr)
112 declare void @llvm.coro.await.suspend.void(ptr, ptr, ptr)
113 declare i1 @llvm.coro.await.suspend.bool(ptr, ptr, ptr)
114 declare void @llvm.coro.await.suspend.handle(ptr, ptr, ptr)
115 declare i1 @llvm.coro.end(ptr, i1, token)
117 declare ptr @__cxa_begin_catch(ptr)
118 declare void @use_val(i32)
119 declare void @__cxa_end_catch()
121 declare noalias ptr @malloc(i32)
122 declare void @free(ptr)