1 ; Fifth example from Doc/Coroutines.rst (final suspend)
2 ; RUN: opt < %s -O2 -enable-coroutines -S | FileCheck %s
4 define i8* @f(i32 %n) {
6 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
7 %size = call i32 @llvm.coro.size.i32()
8 %alloc = call i8* @malloc(i32 %size)
9 %hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %alloc)
12 %n.val = phi i32 [ %n, %entry ], [ %dec, %while.body ]
13 %cmp = icmp sgt i32 %n.val, 0
14 br i1 %cmp, label %while.body, label %while.end
17 %dec = add nsw i32 %n.val, -1
18 call void @print(i32 %n.val) #4
19 %s = call i8 @llvm.coro.suspend(token none, i1 false)
20 switch i8 %s, label %suspend [i8 0, label %while.cond
23 %s.final = call i8 @llvm.coro.suspend(token none, i1 true)
24 switch i8 %s.final, label %suspend [i8 0, label %trap
27 call void @llvm.trap()
30 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
31 call void @free(i8* %mem)
34 call i1 @llvm.coro.end(i8* %hdl, i1 false)
38 declare noalias i8* @malloc(i32)
39 declare void @print(i32)
40 declare void @llvm.trap()
41 declare void @free(i8* nocapture)
43 declare token @llvm.coro.id( i32, i8*, i8*, i8*)
44 declare i32 @llvm.coro.size.i32()
45 declare i8* @llvm.coro.begin(token, i8*)
46 declare token @llvm.coro.save(i8*)
47 declare i8 @llvm.coro.suspend(token, i1)
48 declare i8* @llvm.coro.free(token, i8*)
49 declare i1 @llvm.coro.end(i8*, i1)
54 %hdl = call i8* @f(i32 4)
57 call void @llvm.coro.resume(i8* %hdl)
58 %done = call i1 @llvm.coro.done(i8* %hdl)
59 br i1 %done, label %end, label %while
61 call void @llvm.coro.destroy(i8* %hdl)
64 ; CHECK: call void @print(i32 4)
65 ; CHECK: call void @print(i32 3)
66 ; CHECK: call void @print(i32 2)
67 ; CHECK: call void @print(i32 1)
71 declare i1 @llvm.coro.done(i8*)
72 declare void @llvm.coro.resume(i8*)
73 declare void @llvm.coro.destroy(i8*)