xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-byval-param.ll (revision 51d5d7bbae92493a5bfa7cc6b519de8a5bb32fdb)
1; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
2%promise_type = type { i8 }
3%struct.A = type <{ i64, i64, i32, [4 x i8] }>
4
5; Function Attrs: noinline ssp uwtable mustprogress
6define ptr @foo(ptr nocapture readonly byval(%struct.A) align 8 %a1) #0 {
7entry:
8  %__promise = alloca %promise_type, align 1
9  %a2 = alloca %struct.A, align 8
10  %0 = call token @llvm.coro.id(i32 16, ptr nonnull %__promise, ptr @foo, ptr null)
11  %1 = call i1 @llvm.coro.alloc(token %0)
12  br i1 %1, label %coro.alloc, label %coro.init
13
14coro.alloc:                                       ; preds = %entry
15  %2 = call i64 @llvm.coro.size.i64()
16  %call = call noalias nonnull ptr @_Znwm(i64 %2) #9
17  br label %coro.init
18
19coro.init:                                        ; preds = %coro.alloc, %entry
20  %3 = phi ptr [ null, %entry ], [ %call, %coro.alloc ]
21  %4 = call ptr @llvm.coro.begin(token %0, ptr %3) #10
22  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %__promise) #2
23  %call2 = call ptr @_ZN4task12promise_type17get_return_objectEv(ptr nonnull dereferenceable(1) %__promise)
24  call void @initial_suspend(ptr nonnull dereferenceable(1) %__promise)
25  %5 = call token @llvm.coro.save(ptr null)
26  call fastcc void @_ZNSt12experimental13coroutines_v116coroutine_handleIN4task12promise_typeEE12from_addressEPv(ptr %4) #2
27  %6 = call i8 @llvm.coro.suspend(token %5, i1 false)
28  switch i8 %6, label %coro.ret [
29    i8 0, label %init.ready
30    i8 1, label %cleanup33
31  ]
32
33init.ready:                                       ; preds = %coro.init
34  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %a2) #2
35  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %a2, ptr align 8 %a1, i64 24, i1 false)
36  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %a2) #2
37  call void @_ZN4task12promise_type13final_suspendEv(ptr nonnull dereferenceable(1) %__promise) #2
38  %7 = call token @llvm.coro.save(ptr null)
39  call fastcc void @_ZNSt12experimental13coroutines_v116coroutine_handleIN4task12promise_typeEE12from_addressEPv(ptr %4) #2
40  %8 = call i8 @llvm.coro.suspend(token %7, i1 true) #10
41  %switch = icmp ult i8 %8, 2
42  br i1 %switch, label %cleanup33, label %coro.ret
43
44cleanup33:                                        ; preds = %init.ready, %coro.init
45  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %__promise) #2
46  %9 = call ptr @llvm.coro.free(token %0, ptr %4)
47  %.not = icmp eq ptr %9, null
48  br i1 %.not, label %coro.ret, label %coro.free
49
50coro.free:                                        ; preds = %cleanup33
51  call void @_ZdlPv(ptr nonnull %9) #2
52  br label %coro.ret
53
54coro.ret:                                         ; preds = %coro.free, %cleanup33, %init.ready, %coro.init
55  %10 = call i1 @llvm.coro.end(ptr null, i1 false, token none) #10
56  ret ptr %call2
57}
58
59; check that the frame contains the entire struct, instead of just the struct pointer
60; CHECK: %foo.Frame = type { ptr, ptr, %promise_type, %struct.A, i1 }
61
62; Function Attrs: argmemonly nounwind readonly
63declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
64
65; Function Attrs: nounwind
66declare i1 @llvm.coro.alloc(token) #2
67
68; Function Attrs: nobuiltin nofree allocsize(0)
69declare nonnull ptr @_Znwm(i64) local_unnamed_addr #3
70
71; Function Attrs: nounwind readnone
72declare i64 @llvm.coro.size.i64() #4
73
74; Function Attrs: nounwind
75declare ptr @llvm.coro.begin(token, ptr writeonly) #2
76
77; Function Attrs: argmemonly nofree nosync nounwind willreturn
78declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #5
79
80; Function Attrs: argmemonly nofree nounwind willreturn
81declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6
82
83; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
84declare ptr @_ZN4task12promise_type17get_return_objectEv(ptr nonnull dereferenceable(1)) local_unnamed_addr #7 align 2
85
86; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
87declare void @initial_suspend(ptr nonnull dereferenceable(1)) local_unnamed_addr #7 align 2
88
89; Function Attrs: nounwind
90declare token @llvm.coro.save(ptr) #2
91
92; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
93declare hidden fastcc void @_ZNSt12experimental13coroutines_v116coroutine_handleIN4task12promise_typeEE12from_addressEPv(ptr) unnamed_addr #7 align 2
94
95; Function Attrs: argmemonly nofree nosync nounwind willreturn
96declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #5
97
98; Function Attrs: nounwind
99declare i8 @llvm.coro.suspend(token, i1) #2
100
101; Function Attrs: noinline nounwind ssp uwtable willreturn mustprogress
102declare void @_ZN4task12promise_type13final_suspendEv(ptr nonnull dereferenceable(1)) local_unnamed_addr #7 align 2
103
104; Function Attrs: nounwind
105declare i1 @llvm.coro.end(ptr, i1, token) #2
106
107; Function Attrs: nobuiltin nounwind
108declare void @_ZdlPv(ptr) local_unnamed_addr #8
109
110; Function Attrs: argmemonly nounwind readonly
111declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
112
113attributes #0 = { noinline ssp uwtable mustprogress presplitcoroutine "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
114attributes #1 = { argmemonly nounwind readonly }
115attributes #2 = { nounwind }
116attributes #3 = { nobuiltin nofree allocsize(0) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
117attributes #4 = { nounwind readnone }
118attributes #5 = { argmemonly nofree nosync nounwind willreturn }
119attributes #6 = { argmemonly nofree nounwind willreturn }
120attributes #7 = { noinline nounwind ssp uwtable willreturn mustprogress "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
121attributes #8 = { nobuiltin nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
122attributes #9 = { allocsize(0) }
123attributes #10 = { noduplicate }
124
125