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