1 ; Testing elide performed its job for calls to coroutines marked safe.
2 ; RUN: opt < %s -S -passes='cgscc(coro-annotation-elide)' | FileCheck %s
4 %struct.Task = type { ptr }
6 declare void @print(i32) nounwind
8 ; resume part of the coroutine
9 define fastcc void @callee.resume(ptr dereferenceable(1)) {
10 tail call void @print(i32 0)
14 ; destroy part of the coroutine
15 define fastcc void @callee.destroy(ptr) {
16 tail call void @print(i32 1)
20 ; cleanup part of the coroutine
21 define fastcc void @callee.cleanup(ptr) {
22 tail call void @print(i32 2)
26 @callee.resumers = internal constant [3 x ptr] [
27 ptr @callee.resume, ptr @callee.destroy, ptr @callee.cleanup]
29 declare void @alloc(i1) nounwind
31 ; CHECK-LABEL: define ptr @callee
32 define ptr @callee(i8 %arg) {
34 %task = alloca %struct.Task, align 8
35 %id = call token @llvm.coro.id(i32 0, ptr null,
38 %alloc = call i1 @llvm.coro.alloc(token %id)
39 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
40 store ptr %hdl, ptr %task
44 ; CHECK-LABEL: define ptr @callee.noalloc
45 define ptr @callee.noalloc(i8 %arg, ptr dereferenceable(32) align(8) %frame) {
47 %task = alloca %struct.Task, align 8
48 %id = call token @llvm.coro.id(i32 0, ptr null,
51 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
52 store ptr %hdl, ptr %task
56 ; CHECK-LABEL: define ptr @caller()
57 ; Function Attrs: presplitcoroutine
58 define ptr @caller() #0 {
60 %task = call ptr @callee(i8 0) #1
62 ; CHECK: %[[TASK:.+]] = alloca %struct.Task, align 8
63 ; CHECK-NEXT: %[[FRAME:.+]] = alloca [32 x i8], align 8
64 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 8, ptr %[[TASK]])
65 ; CHECK-NEXT: %[[ID:.+]] = call token @llvm.coro.id(i32 0, ptr null, ptr @callee, ptr @callee.resumers)
66 ; CHECK-NEXT: %[[HDL:.+]] = call ptr @llvm.coro.begin(token %[[ID]], ptr null)
67 ; CHECK-NEXT: store ptr %[[HDL]], ptr %[[TASK]], align 8
68 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 8, ptr %[[TASK]])
69 ; CHECK-NEXT: ret ptr %[[TASK]]
72 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
73 declare ptr @llvm.coro.begin(token, ptr)
74 declare ptr @llvm.coro.frame()
75 declare ptr @llvm.coro.subfn.addr(ptr, i8)
76 declare i1 @llvm.coro.alloc(token)
78 attributes #0 = { presplitcoroutine }
79 attributes #1 = { coro_elide_safe }