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
5 ; using this directly (as it would happen under -O2)
6 define i8* @f_direct(i64 %this) "coroutine.presplit"="1" {
8 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
9 %size = call i32 @llvm.coro.size.i32()
10 %alloc = call i8* @myAlloc(i64 %this, i32 %size)
11 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
12 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
13 switch i8 %0, label %suspend [i8 0, label %resume
16 call void @print2(i64 %this)
20 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
21 call void @free(i8* %mem)
24 call i1 @llvm.coro.end(i8* %hdl, i1 0)
28 ; using copy of this (as it would happen under -O0)
29 define i8* @f_copy(i64 %this_arg) "coroutine.presplit"="1" {
31 %this.addr = alloca i64
32 store i64 %this_arg, i64* %this.addr
33 %this = load i64, i64* %this.addr
34 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
35 %size = call i32 @llvm.coro.size.i32()
36 %alloc = call i8* @myAlloc(i64 %this, i32 %size)
37 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
38 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
39 switch i8 %0, label %suspend [i8 0, label %resume
42 call void @print2(i64 %this)
46 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
47 call void @free(i8* %mem)
50 call i1 @llvm.coro.end(i8* %hdl, i1 0)
54 ; See if %this was added to the frame
55 ; CHECK: %f_direct.Frame = type { void (%f_direct.Frame*)*, void (%f_direct.Frame*)*, i1, i1, i64 }
56 ; CHECK: %f_copy.Frame = type { void (%f_copy.Frame*)*, void (%f_copy.Frame*)*, i1, i1, i64 }
58 ; See that %this is spilled into the frame
59 ; CHECK-LABEL: define i8* @f_direct(i64 %this)
60 ; CHECK: %this.spill.addr = getelementptr inbounds %f_direct.Frame, %f_direct.Frame* %FramePtr, i32 0, i32 4
61 ; CHECK: store i64 %this, i64* %this.spill.addr
64 ; See that %this is spilled into the frame
65 ; CHECK-LABEL: define i8* @f_copy(i64 %this_arg)
66 ; CHECK: %this.spill.addr = getelementptr inbounds %f_copy.Frame, %f_copy.Frame* %FramePtr, i32 0, i32 4
67 ; CHECK: store i64 %this_arg, i64* %this.spill.addr
70 ; See that %this was loaded from the frame
71 ; CHECK-LABEL: @f_direct.resume(
72 ; CHECK: %this.reload = load i64, i64* %this.reload.addr
73 ; CHECK: call void @print2(i64 %this.reload)
76 ; See that %this was loaded from the frame
77 ; CHECK-LABEL: @f_copy.resume(
78 ; CHECK: %this.reload = load i64, i64* %this.reload.addr
79 ; CHECK: call void @print2(i64 %this.reload)
82 declare i8* @llvm.coro.free(token, i8*)
83 declare i32 @llvm.coro.size.i32()
84 declare i8 @llvm.coro.suspend(token, i1)
85 declare void @llvm.coro.resume(i8*)
86 declare void @llvm.coro.destroy(i8*)
88 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
89 declare i1 @llvm.coro.alloc(token)
90 declare i8* @llvm.coro.begin(token, i8*)
91 declare i1 @llvm.coro.end(i8*, i1)
93 declare noalias i8* @myAlloc(i64, i32)
94 declare double @print(double)
95 declare void @print2(i64)
96 declare void @free(i8*)