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 i8* @f() presplitcoroutine {
6 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* 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 i8* @malloc(i32 %size)
14 %phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
15 %hdl = call i8* @llvm.coro.begin(token %id, i8* %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 i8* @llvm.coro.free(token %id, i8* %hdl)
26 call void @free(i8* %mem)
29 call i1 @llvm.coro.end(i8* %hdl, i1 0)
35 call void @llvm.coro.resume(i8* %hdl)
38 ; CHECK: call void @print(i32 0)
39 ; CHECK: call void @print(i32 1)
43 declare i8* @llvm.coro.free(token, i8*)
44 declare i32 @llvm.coro.size.i32()
45 declare i8 @llvm.coro.suspend(token, i1)
46 declare void @llvm.coro.resume(i8*)
47 declare void @llvm.coro.destroy(i8*)
49 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
50 declare i1 @llvm.coro.alloc(token)
51 declare i8* @llvm.coro.begin(token, i8*)
52 declare i1 @llvm.coro.end(i8*, i1)
54 declare noalias i8* @malloc(i32)
55 declare void @print(i32)
56 declare void @free(i8*)