1 ; Third example from Doc/Coroutines.rst (two suspend points)
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='default<O2>' -S | FileCheck %s
4 define i8* @f(i32 %n) presplitcoroutine {
6 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
7 %size = call i32 @llvm.coro.size.i32()
8 %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
9 br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
11 %alloc = call i8* @malloc(i32 %size)
14 %phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
15 %hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %phi)
18 %n.val = phi i32 [ %n, %coro.begin ], [ %inc, %loop.resume ]
19 call void @print(i32 %n.val) #4
20 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
21 switch i8 %0, label %suspend [i8 0, label %loop.resume
24 %inc = add nsw i32 %n.val, 1
25 %sub = xor i32 %n.val, -1
26 call void @print(i32 %sub)
27 %1 = call i8 @llvm.coro.suspend(token none, i1 false)
28 switch i8 %1, label %suspend [i8 0, label %loop
31 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
32 call void @free(i8* %mem)
35 call i1 @llvm.coro.end(i8* %hdl, i1 false)
42 %hdl = call i8* @f(i32 4)
43 call void @llvm.coro.resume(i8* %hdl)
44 call void @llvm.coro.resume(i8* %hdl)
45 %c = ptrtoint i8* %hdl to i64
46 %to = icmp eq i64 %c, 0
47 br i1 %to, label %return, label %destroy
49 call void @llvm.coro.destroy(i8* %hdl)
53 ; CHECK-NOT: i8* @malloc
54 ; CHECK: call void @print(i32 4)
55 ; CHECK-NEXT: call void @print(i32 -5)
56 ; CHECK-NEXT: call void @print(i32 5)
60 declare i8* @malloc(i32)
61 declare void @free(i8*)
62 declare void @print(i32)
64 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
65 declare i1 @llvm.coro.alloc(token)
66 declare i32 @llvm.coro.size.i32()
67 declare i8* @llvm.coro.begin(token, i8*)
68 declare i8 @llvm.coro.suspend(token, i1)
69 declare i8* @llvm.coro.free(token, i8*)
70 declare i1 @llvm.coro.end(i8*, i1)
72 declare void @llvm.coro.resume(i8*)
73 declare void @llvm.coro.destroy(i8*)