1 ; Check that we can spills coro.begin from an inlined inner coroutine.
2 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4 %g.Frame = type { ptr, ptr, i32, i1, i32 }
6 @g.resumers = private constant [3 x ptr] [ptr @g.dummy, ptr @g.dummy, ptr @g.dummy]
8 declare void @g.dummy(ptr)
12 define ptr @f() presplitcoroutine {
14 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
15 %size = call i32 @llvm.coro.size.i32()
16 %alloc = call ptr @malloc(i32 %size)
17 %hdl = call ptr @llvm.coro.begin(token %id, ptr %alloc)
19 %innerid = call token @llvm.coro.id(i32 0, ptr null, ptr @g, ptr @g.resumers)
20 %innerhdl = call noalias nonnull ptr @llvm.coro.begin(token %innerid, ptr null)
22 %tok = call i8 @llvm.coro.suspend(token none, i1 false)
23 switch i8 %tok, label %suspend [i8 0, label %resume
26 %gvar.addr = getelementptr inbounds %g.Frame, ptr %innerhdl, i32 0, i32 4
27 %gvar = load i32, ptr %gvar.addr
28 call void @print.i32(i32 %gvar)
32 %mem = call ptr @llvm.coro.free(token %id, ptr %hdl)
33 call void @free(ptr %mem)
36 call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
40 ; See if the ptr for coro.begin was added to f.Frame
41 ; CHECK-LABEL: %f.Frame = type { ptr, ptr, ptr, i1 }
43 ; See if the g's coro.begin was spilled into the frame
45 ; CHECK: %innerid = call token @llvm.coro.id(i32 0, ptr null, ptr @g, ptr @g.resumers)
46 ; CHECK: %innerhdl = call noalias nonnull ptr @llvm.coro.begin(token %innerid, ptr null)
47 ; CHECK: %[[spilladdr:.+]] = getelementptr inbounds %f.Frame, ptr %hdl, i32 0, i32 2
48 ; CHECK: store ptr %innerhdl, ptr %[[spilladdr]]
50 ; See if the coro.begin was loaded from the frame
51 ; CHECK-LABEL: @f.resume(
52 ; CHECK: %[[innerhdlAddr:.+]] = getelementptr inbounds %f.Frame, ptr %{{.+}}, i32 0, i32 2
53 ; CHECK: %[[innerhdl:.+]] = load ptr, ptr %[[innerhdlAddr]]
54 ; CHECK: %[[gvarAddr:.+]] = getelementptr inbounds %g.Frame, ptr %[[innerhdl]], i32 0, i32 4
55 ; CHECK: %[[gvar:.+]] = load i32, ptr %[[gvarAddr]]
56 ; CHECK: call void @print.i32(i32 %[[gvar]])
58 declare ptr @llvm.coro.free(token, ptr)
59 declare i32 @llvm.coro.size.i32()
60 declare i8 @llvm.coro.suspend(token, i1)
62 declare token @llvm.coro.id(i32, ptr, ptr, ptr)
63 declare i1 @llvm.coro.alloc(token)
64 declare ptr @llvm.coro.begin(token, ptr)
65 declare i1 @llvm.coro.end(ptr, i1, token)
67 declare noalias ptr @malloc(i32)
68 declare void @print.i32(i32)
69 declare void @free(ptr)