1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; First example from Doc/Coroutines.rst (two block loop) converted to retcon
3 ; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
5 define {ptr, i32} @f(ptr %buffer, i32 %n) {
7 ; CHECK-NEXT: coro.return:
8 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[BUFFER:%.*]], align 4
9 ; CHECK-NEXT: [[TMP0:%.*]] = insertvalue { ptr, i32 } { ptr @f.resume.0, i32 poison }, i32 [[N]], 1
10 ; CHECK-NEXT: ret { ptr, i32 } [[TMP0]]
13 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, ptr %buffer, ptr @prototype, ptr @allocate, ptr @deallocate)
14 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
18 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ]
19 %unwind = call i8 (...) @llvm.coro.suspend.retcon.i8(i32 %n.val)
20 %unwind0 = icmp ne i8 %unwind, 0
21 br i1 %unwind0, label %cleanup, label %resume
24 %inc = add i32 %n.val, 1
28 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
37 ; CHECK-NEXT: call void @print(i32 4)
38 ; CHECK-NEXT: call void @print(i32 5)
39 ; CHECK-NEXT: call void @print(i32 6)
40 ; CHECK-NEXT: ret i32 0
43 %0 = alloca [8 x i8], align 4
44 %prepare = call ptr @llvm.coro.prepare.retcon(ptr @f)
45 %result0 = call {ptr, i32} %prepare(ptr %0, i32 4)
46 %value0 = extractvalue {ptr, i32} %result0, 1
47 call void @print(i32 %value0)
48 %cont0 = extractvalue {ptr, i32} %result0, 0
49 %result1 = call {ptr, i32} %cont0(ptr %0, i8 zeroext 0)
50 %value1 = extractvalue {ptr, i32} %result1, 1
51 call void @print(i32 %value1)
52 %cont1 = extractvalue {ptr, i32} %result1, 0
53 %result2 = call {ptr, i32} %cont1(ptr %0, i8 zeroext 0)
54 %value2 = extractvalue {ptr, i32} %result2, 1
55 call void @print(i32 %value2)
56 %cont2 = extractvalue {ptr, i32} %result2, 0
57 call {ptr, i32} %cont2(ptr %0, i8 zeroext 1)
61 ; Unfortunately, we don't seem to fully optimize this right now due
62 ; to some sort of phase-ordering thing.
64 declare token @llvm.coro.id.retcon(i32, i32, ptr, ptr, ptr, ptr)
65 declare ptr @llvm.coro.begin(token, ptr)
66 declare i8 @llvm.coro.suspend.retcon.i8(...)
67 declare i1 @llvm.coro.end(ptr, i1, token)
68 declare ptr @llvm.coro.prepare.retcon(ptr)
70 declare {ptr, i32} @prototype(ptr, i8 zeroext)
72 declare noalias ptr @allocate(i32 %size)
73 declare void @deallocate(ptr %ptr)
75 declare void @print(i32)