1 ; RUN: opt < %s -coro-split -coro-cleanup -S | FileCheck %s
3 define i8* @f(i8* %buffer, i32 %n) "coroutine.presplit"="1" {
5 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i32)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
6 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
7 %value0 = call i32 (...) @llvm.coro.suspend.retcon.i32()
8 %sum0 = call i32 @add(i32 %n, i32 %value0)
9 %value1 = call i32 (...) @llvm.coro.suspend.retcon.i32()
10 %sum1 = call i32 @add(i32 %sum0, i32 %value0)
11 %sum2 = call i32 @add(i32 %sum1, i32 %value1)
12 %value2 = call i32 (...) @llvm.coro.suspend.retcon.i32()
13 %sum3 = call i32 @add(i32 %sum2, i32 %value0)
14 %sum4 = call i32 @add(i32 %sum3, i32 %value1)
15 %sum5 = call i32 @add(i32 %sum4, i32 %value2)
16 call void @print(i32 %sum5)
17 call i1 @llvm.coro.end(i8* %hdl, i1 0)
21 ; CHECK-LABEL: define i8* @f(i8* %buffer, i32 %n)
23 ; CHECK-NEXT: [[ALLOC:%.*]] = call i8* @allocate(i32 20)
24 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %buffer to i8**
25 ; CHECK-NEXT: store i8* [[ALLOC]], i8** [[T0]]
26 ; CHECK-NEXT: [[FRAME:%.*]] = bitcast i8* [[ALLOC]] to [[FRAME_T:%.*]]*
27 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 0
28 ; CHECK-NEXT: store i32 %n, i32* [[T0]]
29 ; CHECK-NEXT: ret i8* bitcast (i8* (i8*, i32)* @f.resume.0 to i8*)
32 ; CHECK-LABEL: define internal i8* @f.resume.0(i8* noalias nonnull %0, i32 %1)
34 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %0 to [[FRAME_T:%.*]]**
35 ; CHECK-NEXT: [[FRAME:%.*]] = load [[FRAME_T]]*, [[FRAME_T]]** [[T0]]
36 ; CHECK-NEXT: [[VFRAME:%.*]] = bitcast [[FRAME_T]]* [[FRAME]] to i8*
37 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 1
38 ; CHECK-NEXT: store i32 %1, i32* [[T0]]
39 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 0
40 ; CHECK-NEXT: [[N:%.*]] = load i32, i32* [[T0]]
41 ; CHECK-NEXT: %sum0 = call i32 @add(i32 [[N]], i32 %1)
42 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 2
43 ; CHECK-NEXT: store i32 %sum0, i32* [[T0]]
44 ; CHECK-NEXT: [[CONT:%.*]] = bitcast i8* (i8*, i32)* @f.resume.1 to i8*
45 ; CHECK-NEXT: ret i8* [[CONT]]
48 ; CHECK-LABEL: define internal i8* @f.resume.1(i8* noalias nonnull %0, i32 %1)
50 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %0 to [[FRAME_T:%.*]]**
51 ; CHECK-NEXT: [[FRAME:%.*]] = load [[FRAME_T]]*, [[FRAME_T]]** [[T0]]
52 ; CHECK-NEXT: [[VFRAME:%.*]] = bitcast [[FRAME_T]]* [[FRAME]] to i8*
53 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 3
54 ; CHECK-NEXT: store i32 %1, i32* [[T0]]
55 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 2
56 ; CHECK-NEXT: [[SUM0:%.*]] = load i32, i32* [[T0]]
57 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 1
58 ; CHECK-NEXT: [[VALUE0:%.*]] = load i32, i32* [[T0]]
59 ; CHECK-NEXT: %sum1 = call i32 @add(i32 [[SUM0]], i32 [[VALUE0]])
60 ; CHECK-NEXT: %sum2 = call i32 @add(i32 %sum1, i32 %1)
61 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 4
62 ; CHECK-NEXT: store i32 %sum2, i32* [[T0]]
63 ; CHECK-NEXT: [[CONT:%.*]] = bitcast i8* (i8*, i32)* @f.resume.2 to i8*
64 ; CHECK-NEXT: ret i8* [[CONT]]
67 ; CHECK-LABEL: define internal i8* @f.resume.2(i8* noalias nonnull %0, i32 %1)
69 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %0 to [[FRAME_T:%.*]]**
70 ; CHECK-NEXT: [[FRAME:%.*]] = load [[FRAME_T]]*, [[FRAME_T]]** [[T0]]
71 ; CHECK-NEXT: [[VFRAME:%.*]] = bitcast [[FRAME_T]]* [[FRAME]] to i8*
72 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 4
73 ; CHECK-NEXT: [[SUM2:%.*]] = load i32, i32* [[T0]]
74 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 3
75 ; CHECK-NEXT: [[VALUE1:%.*]] = load i32, i32* [[T0]]
76 ; CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 1
77 ; CHECK-NEXT: [[VALUE0:%.*]] = load i32, i32* [[T0]]
78 ; CHECK-NEXT: %sum3 = call i32 @add(i32 [[SUM2]], i32 [[VALUE0]])
79 ; CHECK-NEXT: %sum4 = call i32 @add(i32 %sum3, i32 [[VALUE1]])
80 ; CHECK-NEXT: %sum5 = call i32 @add(i32 %sum4, i32 %1)
81 ; CHECK-NEXT: call void @print(i32 %sum5)
82 ; CHECK-NEXT: [[CONT:%.*]] = bitcast [[FRAME_T]]* [[FRAME]] to i8*
83 ; CHECK-NEXT: call void @deallocate(i8* [[CONT]])
84 ; CHECK-NEXT: ret i8* null
87 declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*)
88 declare i8* @llvm.coro.begin(token, i8*)
89 declare i32 @llvm.coro.suspend.retcon.i32(...)
90 declare i1 @llvm.coro.end(i8*, i1)
91 declare i8* @llvm.coro.prepare.retcon(i8*)
93 declare i8* @prototype(i8*, i32)
95 declare noalias i8* @allocate(i32 %size)
96 declare void @deallocate(i8* %ptr)
98 declare i32 @add(i32, i32)
99 declare void @print(i32)