1; Tests whether resume function would remain dbg.value infomation.
2; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
3;
4; This file is based on coro-debug-frame-variable.ll.
5; CHECK:  define internal fastcc void @f.resume(%f.Frame* noalias nonnull align 16 dereferenceable(80) %FramePtr) !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]
6; CHECK:       init.ready:
7; CHECK:         call void @llvm.dbg.value(metadata %f.Frame** %FramePtr.debug, metadata ![[XVAR_RESUME:[0-9]+]],
8; CHECK:       await.ready:
9; CHECK:         call void @llvm.dbg.value(metadata %f.Frame** %FramePtr.debug, metadata ![[SPILL_RESUME:[0-9]+]]
10; CHECK:         call void @llvm.dbg.value(metadata %f.Frame** %FramePtr.debug, metadata ![[IVAR_RESUME:[0-9]+]], metadata !DIExpression(
11; CHECK:         call void @llvm.dbg.value(metadata %f.Frame** %FramePtr.debug, metadata ![[JVAR_RESUME:[0-9]+]], metadata !DIExpression(
12;
13; CHECK: ![[RESUME_FN_DBG_NUM]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"
14; CHECK: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"
15; CHECK: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"
16; CHECK: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"
17; CHECK: ![[SPILL_RESUME]] = !DILocalVariable(name: "produced"
18
19source_filename = "../llvm/test/Transforms/Coroutines/coro-debug-dbg.values-O2.ll"
20declare void @consume(i32)
21
22define void @f(i32 %i, i32 %j) presplitcoroutine !dbg !8 {
23entry:
24  %__promise = alloca i8, align 8
25  %x = alloca [10 x i32], align 16
26  %produced = call i32 @value_producer()
27  %id = call token @llvm.coro.id(i32 16, i8* %__promise, i8* null, i8* null)
28  %alloc = call i1 @llvm.coro.alloc(token %id)
29  br i1 %alloc, label %coro.alloc, label %coro.init
30
31coro.alloc:                                       ; preds = %entry
32  %size = call i64 @llvm.coro.size.i64()
33  %memory = call i8* @new(i64 %size)
34  br label %coro.init
35
36coro.init:                                        ; preds = %coro.alloc, %entry
37  %phi.entry.alloc = phi i8* [ null, %entry ], [ %memory, %coro.alloc ]
38  %begin = call i8* @llvm.coro.begin(token %id, i8* %phi.entry.alloc)
39  %ready = call i1 @await_ready()
40  br i1 %ready, label %init.ready, label %init.suspend
41
42init.suspend:                                     ; preds = %coro.init
43  %save = call token @llvm.coro.save(i8* null)
44  call void @await_suspend()
45  %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
46  switch i8 %suspend, label %coro.ret [
47    i8 0, label %init.ready
48    i8 1, label %init.cleanup
49  ]
50
51init.cleanup:                                     ; preds = %init.suspend
52  br label %cleanup
53
54init.ready:                                       ; preds = %init.suspend, %coro.init
55  call void @await_resume()
56  call void @llvm.dbg.value(metadata i32 0, metadata !6, metadata !DIExpression()), !dbg !11
57  %i.init.ready.inc = add nsw i32 0, 1
58  call void @llvm.dbg.value(metadata i32 %i.init.ready.inc, metadata !6, metadata !DIExpression()), !dbg !11
59  call void @llvm.dbg.value(metadata [10 x i32]* %x, metadata !12, metadata !DIExpression()), !dbg !17
60  %memset = bitcast [10 x i32]* %x to i8*, !dbg !17
61  call void @llvm.memset.p0i8.i64(i8* align 16 %memset, i8 0, i64 40, i1 false), !dbg !17
62  call void @print(i32 %i.init.ready.inc)
63  %ready.again = call zeroext i1 @await_ready()
64  br i1 %ready.again, label %await.ready, label %await.suspend
65
66await.suspend:                                    ; preds = %init.ready
67  %save.again = call token @llvm.coro.save(i8* null)
68  %from.address = call i8* @from_address(i8* %begin)
69  call void @await_suspend()
70  %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)
71  switch i8 %suspend.again, label %coro.ret [
72    i8 0, label %await.ready
73    i8 1, label %await.cleanup
74  ]
75
76await.cleanup:                                    ; preds = %await.suspend
77  br label %cleanup
78
79await.ready:                                      ; preds = %await.suspend, %init.ready
80  call void @await_resume()
81  call void @llvm.dbg.value(metadata i32 0, metadata !18, metadata !DIExpression()), !dbg !11
82  %arrayidx0 = getelementptr inbounds [10 x i32], [10 x i32]* %x, i64 0, i64 0, !dbg !19
83  store i32 1, i32* %arrayidx0, align 16, !dbg !20
84  %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* %x, i64 0, i64 1, !dbg !21
85  store i32 2, i32* %arrayidx1, align 4, !dbg !22
86  %i.await.ready.inc = add nsw i32 %i.init.ready.inc, 1
87  call void @consume(i32 %produced)
88  call void @consume(i32 %i)
89  call void @consume(i32 %j)
90  call void @llvm.dbg.value(metadata i32 %produced, metadata !23, metadata !DIExpression()), !dbg !11
91  call void @llvm.dbg.value(metadata i32 %i, metadata !6, metadata !DIExpression()), !dbg !11
92  call void @llvm.dbg.value(metadata i32 %j, metadata !18, metadata !DIExpression()), !dbg !11
93  call void @print(i32 %i.await.ready.inc)
94  call void @return_void()
95  br label %coro.final
96
97coro.final:                                       ; preds = %await.ready
98  call void @final_suspend()
99  %coro.final.await_ready = call i1 @await_ready()
100  br i1 %coro.final.await_ready, label %final.ready, label %final.suspend
101
102final.suspend:                                    ; preds = %coro.final
103  %final.suspend.coro.save = call token @llvm.coro.save(i8* null)
104  %final.suspend.from_address = call i8* @from_address(i8* %begin)
105  call void @await_suspend()
106  %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)
107  switch i8 %final.suspend.coro.suspend, label %coro.ret [
108    i8 0, label %final.ready
109    i8 1, label %final.cleanup
110  ]
111
112final.cleanup:                                    ; preds = %final.suspend
113  br label %cleanup
114
115final.ready:                                      ; preds = %final.suspend, %coro.final
116  call void @await_resume()
117  br label %cleanup
118
119cleanup:                                          ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup
120  %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]
121  %free.memory = call i8* @llvm.coro.free(token %id, i8* %begin)
122  %free = icmp ne i8* %free.memory, null
123  br i1 %free, label %coro.free, label %after.coro.free
124
125coro.free:                                        ; preds = %cleanup
126  call void @delete(i8* %free.memory)
127  br label %after.coro.free
128
129after.coro.free:                                  ; preds = %coro.free, %cleanup
130  switch i32 %cleanup.dest.slot.0, label %unreachable [
131    i32 0, label %cleanup.cont
132    i32 2, label %coro.ret
133  ]
134
135cleanup.cont:                                     ; preds = %after.coro.free
136  br label %coro.ret
137
138coro.ret:                                         ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend
139  %end = call i1 @llvm.coro.end(i8* null, i1 false)
140  ret void
141
142unreachable:                                      ; preds = %after.coro.free
143  unreachable
144}
145
146; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
147declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
148
149; Function Attrs: argmemonly nounwind readonly
150declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1
151
152; Function Attrs: nounwind
153declare i1 @llvm.coro.alloc(token) #2
154
155; Function Attrs: nounwind readnone
156declare i64 @llvm.coro.size.i64() #3
157
158; Function Attrs: nounwind
159declare token @llvm.coro.save(i8*) #2
160
161; Function Attrs: nounwind
162declare i8* @llvm.coro.begin(token, i8* writeonly) #2
163
164; Function Attrs: nounwind
165declare i8 @llvm.coro.suspend(token, i1) #2
166
167; Function Attrs: argmemonly nounwind readonly
168declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1
169
170; Function Attrs: nounwind
171declare i1 @llvm.coro.end(i8*, i1) #2
172
173declare i8* @new(i64)
174
175declare void @delete(i8*)
176
177declare i1 @await_ready()
178
179declare void @await_suspend()
180
181declare void @await_resume()
182
183declare void @print(i32)
184
185declare i8* @from_address(i8*)
186
187declare void @return_void()
188
189declare void @final_suspend()
190
191declare i32 @value_producer()
192
193; Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
194declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #4
195
196; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
197declare void @llvm.dbg.value(metadata, metadata, metadata) #0
198
199attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
200attributes #1 = { argmemonly nounwind readonly }
201attributes #2 = { nounwind }
202attributes #3 = { nounwind readnone }
203attributes #4 = { argmemonly nofree nosync nounwind willreturn writeonly }
204
205!llvm.dbg.cu = !{!0}
206!llvm.linker.options = !{}
207!llvm.module.flags = !{!3, !4}
208!llvm.ident = !{!5}
209
210!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, splitDebugInlining: false, nameTableKind: None)
211!1 = !DIFile(filename: "repro.cpp", directory: ".")
212!2 = !{}
213!3 = !{i32 7, !"Dwarf Version", i32 4}
214!4 = !{i32 2, !"Debug Info Version", i32 3}
215!5 = !{!"clang version 11.0.0"}
216!6 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 24, type: !10)
217!7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
218!8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 23, type: !9, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
219!9 = !DISubroutineType(types: !2)
220!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
221!11 = !DILocation(line: 0, scope: !7)
222!12 = !DILocalVariable(name: "x", scope: !13, file: !1, line: 34, type: !14)
223!13 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
224!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 320, elements: !15)
225!15 = !{!16}
226!16 = !DISubrange(count: 10)
227!17 = !DILocation(line: 24, column: 7, scope: !7)
228!18 = !DILocalVariable(name: "j", scope: !7, file: !1, line: 32, type: !10)
229!19 = !DILocation(line: 42, column: 3, scope: !7)
230!20 = !DILocation(line: 42, column: 8, scope: !7)
231!21 = !DILocation(line: 43, column: 3, scope: !7)
232!22 = !DILocation(line: 43, column: 8, scope: !7)
233!23 = !DILocalVariable(name: "produced", scope: !7, file: !1, line:24, type: !10)
234