1 ; Fourth example from Doc/Coroutines.rst (coroutine promise)
2 ; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
4 define i8* @f(i32 %n) presplitcoroutine {
7 %pv = bitcast i32* %promise to i8*
8 %id = call token @llvm.coro.id(i32 0, i8* %pv, i8* null, i8* null)
9 %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
10 br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
12 %size = call i32 @llvm.coro.size.i32()
13 %alloc = call i8* @malloc(i32 %size)
16 %phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
17 %hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %phi)
20 %n.val = phi i32 [ %n, %coro.begin ], [ %inc, %loop ]
21 %inc = add nsw i32 %n.val, 1
22 store i32 %n.val, i32* %promise
23 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
24 switch i8 %0, label %suspend [i8 0, label %loop
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 false)
38 %hdl = call i8* @f(i32 4)
39 %promise.addr.raw = call i8* @llvm.coro.promise(i8* %hdl, i32 4, i1 false)
40 %promise.addr = bitcast i8* %promise.addr.raw to i32*
41 %val0 = load i32, i32* %promise.addr
42 call void @print(i32 %val0)
43 call void @llvm.coro.resume(i8* %hdl)
44 %val1 = load i32, i32* %promise.addr
45 call void @print(i32 %val1)
46 call void @llvm.coro.resume(i8* %hdl)
47 %val2 = load i32, i32* %promise.addr
48 call void @print(i32 %val2)
49 call void @llvm.coro.destroy(i8* %hdl)
51 ; CHECK: call void @print(i32 4)
52 ; CHECK-NEXT: call void @print(i32 5)
53 ; CHECK-NEXT: call void @print(i32 6)
57 declare i8* @llvm.coro.promise(i8*, i32, i1)
58 declare i8* @malloc(i32)
59 declare void @free(i8*)
60 declare void @print(i32)
62 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
63 declare i1 @llvm.coro.alloc(token)
64 declare i32 @llvm.coro.size.i32()
65 declare i8* @llvm.coro.begin(token, i8*)
66 declare i8 @llvm.coro.suspend(token, i1)
67 declare i8* @llvm.coro.free(token, i8*)
68 declare i1 @llvm.coro.end(i8*, i1)
70 declare void @llvm.coro.resume(i8*)
71 declare void @llvm.coro.destroy(i8*)