1 ; Fourth example from Doc/Coroutines.rst (coroutine promise)
2 ; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
4 define ptr @f(i32 %n) presplitcoroutine {
7 %id = call token @llvm.coro.id(i32 0, ptr %promise, ptr null, ptr null)
8 %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
9 br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
11 %size = call i32 @llvm.coro.size.i32()
12 %alloc = call ptr @malloc(i32 %size)
15 %phi = phi ptr [ null, %entry ], [ %alloc, %dyn.alloc ]
16 %hdl = call noalias ptr @llvm.coro.begin(token %id, ptr %phi)
19 %n.val = phi i32 [ %n, %coro.begin ], [ %inc, %loop ]
20 %inc = add nsw i32 %n.val, 1
21 store i32 %n.val, ptr %promise
22 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
23 switch i8 %0, label %suspend [i8 0, label %loop
26 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
27 call void @free(ptr %mem)
30 call i1 @llvm.coro.end(ptr %hdl, i1 false, token none)
37 %hdl = call ptr @f(i32 4)
38 %promise.addr.raw = call ptr @llvm.coro.promise(ptr %hdl, i32 4, i1 false)
39 %val0 = load i32, ptr %promise.addr.raw
40 call void @print(i32 %val0)
41 call void @llvm.coro.resume(ptr %hdl)
42 %val1 = load i32, ptr %promise.addr.raw
43 call void @print(i32 %val1)
44 call void @llvm.coro.resume(ptr %hdl)
45 %val2 = load i32, ptr %promise.addr.raw
46 call void @print(i32 %val2)
47 call void @llvm.coro.destroy(ptr %hdl)
49 ; CHECK: call void @print(i32 4)
50 ; CHECK-NEXT: call void @print(i32 5)
51 ; CHECK-NEXT: call void @print(i32 6)
55 declare ptr @llvm.coro.promise(ptr, i32, i1)
56 declare ptr @malloc(i32)
57 declare void @free(ptr)
58 declare void @print(i32)
60 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
61 declare i1 @llvm.coro.alloc(token)
62 declare i32 @llvm.coro.size.i32()
63 declare ptr @llvm.coro.begin(token, ptr)
64 declare i8 @llvm.coro.suspend(token, i1)
65 declare ptr @llvm.coro.free(token, ptr)
66 declare i1 @llvm.coro.end(ptr, i1, token)
68 declare void @llvm.coro.resume(ptr)
69 declare void @llvm.coro.destroy(ptr)