1 ; Tests that a coroutine is split, inlined into the caller and devirtualized.
2 ; RUN: opt < %s -S -passes='default<O2>' | FileCheck %s
4 define ptr @f() presplitcoroutine {
6 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
7 %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
8 br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
10 %size = call i32 @llvm.coro.size.i32()
11 %alloc = call ptr @malloc(i32 %size)
14 %phi = phi ptr [ null, %entry ], [ %alloc, %dyn.alloc ]
15 %hdl = call ptr @llvm.coro.begin(token %id, ptr %phi)
16 call void @print(i32 0)
17 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
18 switch i8 %0, label %suspend [i8 0, label %resume
21 call void @print(i32 1)
25 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
26 call void @free(ptr %mem)
29 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
35 call void @llvm.coro.resume(ptr %hdl)
38 ; CHECK: call void @print(i32 0)
39 ; CHECK: call void @print(i32 1)
43 declare ptr @llvm.coro.free(token, ptr)
44 declare i32 @llvm.coro.size.i32()
45 declare i8 @llvm.coro.suspend(token, i1)
46 declare void @llvm.coro.resume(ptr)
47 declare void @llvm.coro.destroy(ptr)
49 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
50 declare i1 @llvm.coro.alloc(token)
51 declare ptr @llvm.coro.begin(token, ptr)
52 declare i1 @llvm.coro.end(ptr, i1, token)
54 declare noalias ptr @malloc(i32)
55 declare void @print(i32)
56 declare void @free(ptr)