1 ; Tests that coro-split pass splits the coroutine into f, f.resume and f.destroy
2 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4 define ptr @f() presplitcoroutine !func_sanitize !0 {
6 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
7 %need.alloc = call i1 @llvm.coro.alloc(token %id)
8 br i1 %need.alloc, label %dyn.alloc, label %begin
11 %size = call i32 @llvm.coro.size.i32()
12 %alloc = call ptr @malloc(i32 %size)
16 %phi = phi ptr [ null, %entry ], [ %alloc, %dyn.alloc ]
17 %hdl = call ptr @llvm.coro.begin(token %id, ptr %phi)
18 call void @print(i32 0)
19 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
20 switch i8 %0, label %suspend [i8 0, label %resume
23 call void @print(i32 1)
27 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
28 call void @free(ptr %mem)
31 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
35 ; CHECK-LABEL: @f() !func_sanitize !0 {
36 ; CHECK: call ptr @malloc
37 ; CHECK: @llvm.coro.begin(token %id, ptr %phi)
38 ; CHECK: store ptr @f.resume, ptr %hdl
39 ; CHECK: %[[SEL:.+]] = select i1 %need.alloc, ptr @f.destroy, ptr @f.cleanup
40 ; CHECK: store ptr %[[SEL]], ptr %destroy.addr
41 ; CHECK: call void @print(i32 0)
42 ; CHECK-NOT: call void @print(i32 1)
43 ; CHECK-NOT: call void @free(
46 ; CHECK-LABEL: @f.resume({{.*}}) {
47 ; CHECK-NOT: call ptr @malloc
48 ; CHECK-NOT: call void @print(i32 0)
49 ; CHECK: call void @print(i32 1)
50 ; CHECK-NOT: call void @print(i32 0)
51 ; CHECK: call void @free(
54 ; CHECK-LABEL: @f.destroy({{.*}}) {
55 ; CHECK-NOT: call ptr @malloc
56 ; CHECK-NOT: call void @print(
57 ; CHECK: call void @free(
60 ; CHECK-LABEL: @f.cleanup({{.*}}) {
61 ; CHECK-NOT: call ptr @malloc
62 ; CHECK-NOT: call void @print(
63 ; CHECK-NOT: call void @free(
66 declare ptr @llvm.coro.free(token, ptr)
67 declare i32 @llvm.coro.size.i32()
68 declare i8 @llvm.coro.suspend(token, i1)
69 declare void @llvm.coro.resume(ptr)
70 declare void @llvm.coro.destroy(ptr)
72 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
73 declare i1 @llvm.coro.alloc(token)
74 declare ptr @llvm.coro.begin(token, ptr)
75 declare i1 @llvm.coro.end(ptr, i1, token)
77 declare noalias ptr @malloc(i32) allockind("alloc,uninitialized") "alloc-family"="malloc"
78 declare void @print(i32)
79 declare void @free(ptr) willreturn allockind("free") "alloc-family"="malloc"
81 !0 = !{i32 846595819, ptr null}