1; First example from Doc/Coroutines.rst (two block loop) 2; RUN: opt < %s -enable-coroutines -O2 -preserve-alignment-assumptions-during-inlining=false -S | FileCheck %s 3; RUN: opt < %s -enable-coroutines -aa-pipeline=basic-aa -passes='default<O2>' -preserve-alignment-assumptions-during-inlining=false -S | FileCheck %s 4 5define i8* @f(i32 %n) { 6entry: 7 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null) 8 %size = call i32 @llvm.coro.size.i32() 9 %alloc = call i8* @malloc(i32 %size) 10 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc) 11 br label %loop 12 13loop: 14 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ] 15 call void @print(i32 %n.val) 16 %0 = call i8 @llvm.coro.suspend(token none, i1 false) 17 switch i8 %0, label %suspend [i8 0, label %resume 18 i8 1, label %cleanup] 19resume: 20 %inc = add i32 %n.val, 1 21 br label %loop 22 23cleanup: 24 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl) 25 call void @free(i8* %mem) 26 br label %suspend 27suspend: 28 call i1 @llvm.coro.end(i8* %hdl, i1 0) 29 ret i8* %hdl 30} 31 32; CHECK-LABEL: @main( 33define i32 @main() { 34entry: 35 %hdl = call i8* @f(i32 4) 36 call void @llvm.coro.resume(i8* %hdl) 37 call void @llvm.coro.resume(i8* %hdl) 38 call void @llvm.coro.destroy(i8* %hdl) 39 ret i32 0 40; CHECK: entry: 41; CHECK: call void @print(i32 4) 42; CHECK: call void @print(i32 5) 43; CHECK: call void @print(i32 6) 44; CHECK: ret i32 0 45} 46 47declare token @llvm.coro.id(i32, i8*, i8*, i8*) 48declare i8* @llvm.coro.alloc(token) 49declare i8* @llvm.coro.free(token, i8*) 50declare i32 @llvm.coro.size.i32() 51declare i8 @llvm.coro.suspend(token, i1) 52declare void @llvm.coro.resume(i8*) 53declare void @llvm.coro.destroy(i8*) 54 55declare i8* @llvm.coro.begin(token, i8*) 56declare i1 @llvm.coro.end(i8*, i1) 57 58declare noalias i8* @malloc(i32) 59declare void @print(i32) 60declare void @free(i8*) 61