1 ; First example from Doc/Coroutines.rst (one block loop)
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 ], [ %inc, %loop ]
13 %inc = add nsw i32 %n.val, 1
14 call void @print(i32 %n.val)
15 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
16 switch i8 %0, label %suspend [i8 0, label %loop
19 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
20 call void @free(ptr %mem)
23 call i1 @llvm.coro.end(ptr %hdl, i1 false, token none)
30 %hdl = call ptr @f(i32 4)
31 call void @llvm.coro.resume(ptr %hdl)
32 call void @llvm.coro.resume(ptr %hdl)
33 call void @llvm.coro.destroy(ptr %hdl)
36 ; CHECK: call void @print(i32 4)
37 ; CHECK: call void @print(i32 5)
38 ; CHECK: call void @print(i32 6)
42 declare ptr @malloc(i32)
43 declare void @free(ptr)
44 declare void @print(i32)
46 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
47 declare i32 @llvm.coro.size.i32()
48 declare ptr @llvm.coro.begin(token, ptr)
49 declare i8 @llvm.coro.suspend(token, i1)
50 declare ptr @llvm.coro.free(token, ptr)
51 declare i1 @llvm.coro.end(ptr, i1, token)
53 declare void @llvm.coro.resume(ptr)
54 declare void @llvm.coro.destroy(ptr)