1; Check that we can handle the case when both alloc function and
2; the user body consume the same argument.
3; RUN: opt < %s -coro-split -S | FileCheck %s
4; RUN: opt < %s -passes=coro-split -S | FileCheck %s
5
6; using this directly (as it would happen under -O2)
7define i8* @f_direct(i64 %this) "coroutine.presplit"="1" {
8entry:
9  %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
10  %size = call i32 @llvm.coro.size.i32()
11  %alloc = call i8* @myAlloc(i64 %this, i32 %size)
12  %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
13  %0 = call i8 @llvm.coro.suspend(token none, i1 false)
14  switch i8 %0, label %suspend [i8 0, label %resume
15                                i8 1, label %cleanup]
16resume:
17  call void @print2(i64 %this)
18  br label %cleanup
19
20cleanup:
21  %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
22  call void @free(i8* %mem)
23  br label %suspend
24suspend:
25  call i1 @llvm.coro.end(i8* %hdl, i1 0)
26  ret i8* %hdl
27}
28
29; See if %this was added to the frame
30; CHECK: %f_direct.Frame = type { void (%f_direct.Frame*)*, void (%f_direct.Frame*)*, i64, i1 }
31
32; See that %this is spilled into the frame
33; CHECK-LABEL: define i8* @f_direct(i64 %this)
34; CHECK: %this.spill.addr = getelementptr inbounds %f_direct.Frame, %f_direct.Frame* %FramePtr, i32 0, i32 2
35; CHECK: store i64 %this, i64* %this.spill.addr
36; CHECK: ret i8* %hdl
37
38; See that %this was loaded from the frame
39; CHECK-LABEL: @f_direct.resume(
40; CHECK:  %this.reload = load i64, i64* %this.reload.addr
41; CHECK:  call void @print2(i64 %this.reload)
42; CHECK: ret void
43
44declare i8* @llvm.coro.free(token, i8*)
45declare i32 @llvm.coro.size.i32()
46declare i8  @llvm.coro.suspend(token, i1)
47declare void @llvm.coro.resume(i8*)
48declare void @llvm.coro.destroy(i8*)
49
50declare token @llvm.coro.id(i32, i8*, i8*, i8*)
51declare i1 @llvm.coro.alloc(token)
52declare i8* @llvm.coro.begin(token, i8*)
53declare i1 @llvm.coro.end(i8*, i1)
54
55declare noalias i8* @myAlloc(i64, i32)
56declare double @print(double)
57declare void @print2(i64)
58declare void @free(i8*)
59