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 i8* @f() "coroutine.presplit"="1" {
6 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* 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 i8* @malloc(i32 %size)
16 %phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
17 %hdl = call i8* @llvm.coro.begin(token %id, i8* %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 i8* @llvm.coro.free(token %id, i8* %hdl)
28 call void @free(i8* %mem)
31 call i1 @llvm.coro.end(i8* %hdl, i1 0)
36 ; CHECK: call i8* @malloc
37 ; CHECK: @llvm.coro.begin(token %id, i8* %phi)
38 ; CHECK: store void (%f.Frame*)* @f.resume, void (%f.Frame*)** %resume.addr
39 ; CHECK: %[[SEL:.+]] = select i1 %need.alloc, void (%f.Frame*)* @f.destroy, void (%f.Frame*)* @f.cleanup
40 ; CHECK: store void (%f.Frame*)* %[[SEL]], void (%f.Frame*)** %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 i8* @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 i8* @malloc
56 ; CHECK-NOT: call void @print(
57 ; CHECK: call void @free(
60 ; CHECK-LABEL: @f.cleanup(
61 ; CHECK-NOT: call i8* @malloc
62 ; CHECK-NOT: call void @print(
63 ; CHECK-NOT: call void @free(
66 declare i8* @llvm.coro.free(token, i8*)
67 declare i32 @llvm.coro.size.i32()
68 declare i8 @llvm.coro.suspend(token, i1)
69 declare void @llvm.coro.resume(i8*)
70 declare void @llvm.coro.destroy(i8*)
72 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
73 declare i1 @llvm.coro.alloc(token)
74 declare i8* @llvm.coro.begin(token, i8*)
75 declare i1 @llvm.coro.end(i8*, i1)
77 declare noalias i8* @malloc(i32)
78 declare void @print(i32)
79 declare void @free(i8*) willreturn