1 ; Fifth example from Doc/Coroutines.rst (final suspend)
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='default<O2>' -preserve-alignment-assumptions-during-inlining=false -S | FileCheck %s
4 define ptr @f(i32 %n) presplitcoroutine {
6 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
7 %size = call i32 @llvm.coro.size.i32()
8 %alloc = call ptr @malloc(i32 %size)
9 %hdl = call noalias ptr @llvm.coro.begin(token %id, ptr %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 ptr @llvm.coro.free(token %id, ptr %hdl)
31 call void @free(ptr %mem)
34 call i1 @llvm.coro.end(ptr %hdl, i1 false, token none)
38 declare noalias ptr @malloc(i32)
39 declare void @print(i32)
40 declare void @llvm.trap()
41 declare void @free(ptr nocapture)
43 declare token @llvm.coro.id( i32, ptr, ptr, ptr)
44 declare i32 @llvm.coro.size.i32()
45 declare ptr @llvm.coro.begin(token, ptr)
46 declare token @llvm.coro.save(ptr)
47 declare i8 @llvm.coro.suspend(token, i1)
48 declare ptr @llvm.coro.free(token, ptr)
49 declare i1 @llvm.coro.end(ptr, i1, token)
54 %hdl = call ptr @f(i32 4)
57 call void @llvm.coro.resume(ptr %hdl)
58 %done = call i1 @llvm.coro.done(ptr %hdl)
59 br i1 %done, label %end, label %while
61 call void @llvm.coro.destroy(ptr %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(ptr)
72 declare void @llvm.coro.resume(ptr)
73 declare void @llvm.coro.destroy(ptr)