1 ; Check that we create copy the data from the alloca into the coroutine
2 ; frame slot if it was written to.
3 ; RUN: opt < %s -coro-split -S | FileCheck %s
5 define i8* @f() "coroutine.presplit"="1" {
8 call void @use(i64* %x.addr) ; might write to %x
10 %y = load i64, i64* %y.addr ; cannot modify the value, don't need to copy
11 call void @print(i64 %y)
13 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
14 %size = call i32 @llvm.coro.size.i32()
15 %alloc = call i8* @myAlloc(i64 %y, i32 %size)
16 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
17 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
18 switch i8 %0, label %suspend [i8 0, label %resume
21 call void @use(i64* %x.addr)
22 call void @use(i64* %y.addr)
26 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
27 call void @free(i8* %mem)
30 call i1 @llvm.coro.end(i8* %hdl, i1 0)
34 ; See that we added both x and y to the frame.
35 ; CHECK: %f.Frame = type { void (%f.Frame*)*, void (%f.Frame*)*, i1, i1, i64, i64 }
37 ; See that all of the uses prior to coro-begin stays put.
38 ; CHECK-LABEL: define i8* @f() {
40 ; CHECK-NEXT: %x.addr = alloca i64
41 ; CHECK-NEXT: call void @use(i64* %x.addr)
42 ; CHECK-NEXT: %y.addr = alloca i64
43 ; CHECK-NEXT: %y = load i64, i64* %y.addr
44 ; CHECK-NEXT: call void @print(i64 %y)
46 ; See that we only copy the x as y was not modified prior to coro.begin.
47 ; CHECK: store void (%f.Frame*)* @f.destroy, void (%f.Frame*)** %destroy.addr
48 ; CHECK-NEXT: %0 = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 4
49 ; CHECK-NEXT: %1 = load i64, i64* %x.addr
50 ; CHECK-NEXT: store i64 %1, i64* %0
51 ; CHECK-NEXT: %index.addr1 = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 3
52 ; CHECK-NEXT: store i1 false, i1* %index.addr1
53 ; CHECK-NEXT: ret i8* %hdl
55 declare i8* @llvm.coro.free(token, i8*)
56 declare i32 @llvm.coro.size.i32()
57 declare i8 @llvm.coro.suspend(token, i1)
58 declare void @llvm.coro.resume(i8*)
59 declare void @llvm.coro.destroy(i8*)
61 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
62 declare i1 @llvm.coro.alloc(token)
63 declare i8* @llvm.coro.begin(token, i8*)
64 declare i1 @llvm.coro.end(i8*, i1)
66 declare noalias i8* @myAlloc(i64, i32)
67 declare void @print(i64)
68 declare void @use(i64*)
69 declare void @free(i8*)