1 ; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
3 ; Checks whether the dbg.declare for `__coro_frame` are created.
5 ; CHECK-LABEL: define void @f(
7 ; CHECK: %[[begin:.*]] = call noalias nonnull i8* @llvm.coro.begin(
8 ; CHECK: %[[FramePtr:.*]] = bitcast i8* %[[begin]] to
9 ; CHECK: call void @llvm.dbg.declare(metadata %f.Frame* %[[FramePtr]], metadata ![[CORO_FRAME:[0-9]+]], metadata !DIExpression())
11 ; CHECK: define internal fastcc void @f.resume(
12 ; CHECK: entry.resume:
13 ; CHECK: call void @llvm.dbg.declare(metadata %f.Frame** %[[FramePtr_RESUME:.*]], metadata ![[CORO_FRAME_IN_RESUME:[0-9]+]], metadata !DIExpression()
15 ; CHECK: ![[FILE:[0-9]+]] = !DIFile(filename: "coro-debug.cpp"
16 ; CHECK: ![[RAMP:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov",
17 ; CHECK: ![[RAMP_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[RAMP]], file: ![[FILE]], line: 23
18 ; CHECK: ![[CORO_FRAME]] = !DILocalVariable(name: "__coro_frame", scope: ![[RAMP_SCOPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE:[0-9]+]], type: ![[FRAME_TYPE:[0-9]+]], flags: DIFlagArtificial)
19 ; CHECK: ![[FRAME_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "__coro_frame_ty", scope: ![[RAMP]], {{.*}}elements: ![[ELEMENTS:[0-9]+]]
20 ; CHECK: ![[ELEMENTS]] = !{![[RESUME_FN:[0-9]+]], ![[DESTROY_FN:[0-9]+]], ![[PROMISE:[0-9]+]], ![[INT64_0:[0-9]+]], ![[DOUBLE_1:[0-9]+]], ![[INT32_2:[0-9]+]], ![[INT32_3:[0-9]+]], ![[STRUCT_4:[0-9]+]], ![[CORO_INDEX:[0-9]+]]
21 ; CHECK: ![[RESUME_FN]] = !DIDerivedType(tag: DW_TAG_member, name: "__resume_fn"{{.*}}, flags: DIFlagArtificial
22 ; CHECK: ![[DESTROY_FN]] = !DIDerivedType(tag: DW_TAG_member, name: "__destroy_fn"{{.*}}, flags: DIFlagArtificial
23 ; CHECK: ![[PROMISE]] = !DIDerivedType(tag: DW_TAG_member, name: "__promise",{{.*}}baseType: ![[PROMISE_BASE:[0-9]+]]
24 ; CHECK: ![[PROMISE_BASE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "promise_type"
25 ; CHECK: ![[INT64_0]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_64_0", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[I64_BASE:[0-9]+]],{{.*}}, flags: DIFlagArtificial
26 ; CHECK: ![[I64_BASE]] = !DIBasicType(name: "__int_64", size: 64, encoding: DW_ATE_signed, flags: DIFlagArtificial)
27 ; CHECK: ![[DOUBLE_1]] = !DIDerivedType(tag: DW_TAG_member, name: "__double__1", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[DOUBLE_BASE:[0-9]+]]{{.*}}, flags: DIFlagArtificial
28 ; CHECK: ![[DOUBLE_BASE]] = !DIBasicType(name: "__double_", size: 64, encoding: DW_ATE_float, flags: DIFlagArtificial)
29 ; CHECK: ![[INT32_2]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_32_2", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[I32_BASE:[0-9]+]]{{.*}}, flags: DIFlagArtificial
30 ; CHECK: ![[I32_BASE]] = !DIBasicType(name: "__int_32", size: 32, encoding: DW_ATE_signed, flags: DIFlagArtificial)
31 ; CHECK: ![[INT32_3]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_32_3", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[I32_BASE]]
32 ; CHECK: ![[STRUCT_4]] = !DIDerivedType(tag: DW_TAG_member, name: "struct_big_structure_4", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[STRUCT_BASE:[0-9]+]]
33 ; CHECK: ![[STRUCT_BASE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "struct_big_structure"{{.*}}elements: ![[STRUCT_ELEMENTS:[0-9]+]]
34 ; CHECK: ![[STRUCT_ELEMENTS]] = !{![[MEM_TYPE:[0-9]+]]}
35 ; CHECK: ![[MEM_TYPE]] = !DIDerivedType(tag: DW_TAG_member, name: "UnknownType_4000"
36 ; CHECK: ![[CORO_INDEX]] = !DIDerivedType(tag: DW_TAG_member, name: "__coro_index"
37 ; CHECK: ![[PROMISE_VAR:[0-9]+]] = !DILocalVariable(name: "__promise", scope: ![[RAMP_SCOPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]]
38 ; CHECK: ![[BAR_FUNC:[0-9]+]] = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv",
39 ; CHECK: ![[BAR_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[BAR_FUNC]], file: !1
40 ; CHECK: ![[FRAME_TYPE_IN_BAR:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "__coro_frame_ty", scope: ![[BAR_FUNC]], file: ![[FILE]], line: [[BAR_LINE:[0-9]+]]{{.*}}elements: ![[ELEMENTS_IN_BAR:[0-9]+]]
41 ; CHECK: ![[ELEMENTS_IN_BAR]] = !{![[RESUME_FN_IN_BAR:[0-9]+]], ![[DESTROY_FN_IN_BAR:[0-9]+]], ![[PROMISE_IN_BAR:[0-9]+]], ![[INT64_0_IN_BAR:[0-9]+]], ![[DOUBLE_1_IN_BAR:[0-9]+]], ![[INT32_2_IN_BAR:[0-9]+]], ![[STRUCT_3_IN_BAR:[0-9]+]], ![[CORO_INDEX_IN_BAR:[0-9]+]]
42 ; CHECK: ![[PROMISE_IN_BAR]] = !DIDerivedType(tag: DW_TAG_member, name: "__promise",{{.*}}baseType: ![[PROMISE_BASE]]
43 ; CHECK: ![[INT64_0_IN_BAR]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_64_0", scope: ![[FRAME_TYPE_IN_BAR]], file: ![[FILE]], line: [[BAR_LINE]], baseType: ![[I64_BASE]]
44 ; CHECK: ![[DOUBLE_1_IN_BAR]] = !DIDerivedType(tag: DW_TAG_member, name: "__double__1", scope: ![[FRAME_TYPE_IN_BAR]], file: ![[FILE]], line: [[BAR_LINE]], baseType: ![[DOUBLE_BASE]]
45 ; CHECK: ![[INT32_2_IN_BAR]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_32_2", scope: ![[FRAME_TYPE_IN_BAR]], file: ![[FILE]], line: [[BAR_LINE]], baseType: ![[I32_BASE]]
46 ; CHECK: ![[STRUCT_3_IN_BAR]] = !DIDerivedType(tag: DW_TAG_member, name: "struct_big_structure_3", scope: ![[FRAME_TYPE_IN_BAR]], file: ![[FILE]], line: [[BAR_LINE]], baseType: ![[STRUCT_BASE_IN_BAR:[0-9]+]]
47 ; CHECK: ![[STRUCT_BASE_IN_BAR]] = !DICompositeType(tag: DW_TAG_structure_type, name: "struct_big_structure", scope: ![[FRAME_TYPE_IN_BAR]], file: ![[FILE]], line: [[BAR_LINE]],{{.*}}
48 ; CHECK: ![[CORO_FRAME_IN_RESUME]] = !DILocalVariable(name: "__coro_frame",{{.*}}type: ![[FRAME_TYPE]]
51 %promise_type = type { i32, i32, double }
52 %struct.big_structure = type { [500 x i8] }
53 declare void @produce(%struct.big_structure*)
54 declare void @consume(%struct.big_structure*)
55 declare void @pi32(i32*)
56 declare void @pi64(i64*)
57 declare void @pdouble(double*)
59 define void @f(i32 %a, i32 %b, i64 %c, double %d) !dbg !8 {
61 %__promise = alloca %promise_type, align 8
62 %0 = bitcast %promise_type* %__promise to i8*
63 %a.alloc = alloca i32, align 4
64 %b.alloc = alloca i32, align 4
65 %c.alloc = alloca i64, align 4
66 %d.alloc = alloca double, align 4
67 store i32 %a, i32* %a.alloc
68 store i32 %b, i32* %b.alloc
69 store i64 %c, i64* %c.alloc
70 store double %d, double* %d.alloc
71 %struct.data = alloca %struct.big_structure, align 1
72 call void @produce(%struct.big_structure* %struct.data)
73 %id = call token @llvm.coro.id(i32 16, i8* %0, i8* null, i8* null)
74 %alloc = call i1 @llvm.coro.alloc(token %id)
75 br i1 %alloc, label %coro.alloc, label %coro.init
77 coro.alloc: ; preds = %entry
78 %size = call i64 @llvm.coro.size.i64()
79 %memory = call i8* @new(i64 %size)
82 coro.init: ; preds = %coro.alloc, %entry
83 %phi.entry.alloc = phi i8* [ null, %entry ], [ %memory, %coro.alloc ]
84 %begin = call i8* @llvm.coro.begin(token %id, i8* %phi.entry.alloc)
85 call void @llvm.dbg.declare(metadata %promise_type* %__promise, metadata !6, metadata !DIExpression()), !dbg !18
86 %ready = call i1 @await_ready()
87 br i1 %ready, label %init.ready, label %init.suspend
89 init.suspend: ; preds = %coro.init
90 %save = call token @llvm.coro.save(i8* null)
91 call void @await_suspend()
92 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
93 switch i8 %suspend, label %coro.ret [
94 i8 0, label %init.ready
95 i8 1, label %init.cleanup
98 init.cleanup: ; preds = %init.suspend
101 init.ready: ; preds = %init.suspend, %coro.init
102 call void @await_resume()
103 %ready.again = call zeroext i1 @await_ready()
104 br i1 %ready.again, label %await.ready, label %await.suspend
106 await.suspend: ; preds = %init.ready
107 %save.again = call token @llvm.coro.save(i8* null)
108 %from.address = call i8* @from_address(i8* %begin)
109 call void @await_suspend()
110 %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)
111 switch i8 %suspend.again, label %coro.ret [
112 i8 0, label %await.ready
113 i8 1, label %await.cleanup
116 await.cleanup: ; preds = %await.suspend
119 await.ready: ; preds = %await.suspend, %init.ready
120 call void @await_resume()
121 %i.i = getelementptr inbounds %promise_type, %promise_type* %__promise, i64 0, i32 0
122 store i32 1, i32* %i.i, align 8
123 %j.i = getelementptr inbounds %promise_type, %promise_type* %__promise, i64 0, i32 1
124 store i32 2, i32* %j.i, align 4
125 %k.i = getelementptr inbounds %promise_type, %promise_type* %__promise, i64 0, i32 2
126 store double 3.000000e+00, double* %k.i, align 8
127 call void @consume(%struct.big_structure* %struct.data)
128 call void @pi32(i32* %a.alloc)
129 call void @pi32(i32* %b.alloc)
130 call void @pi64(i64* %c.alloc)
131 call void @pdouble(double* %d.alloc)
132 call void @return_void()
135 coro.final: ; preds = %await.ready
136 call void @final_suspend()
137 %coro.final.await_ready = call i1 @await_ready()
138 br i1 %coro.final.await_ready, label %final.ready, label %final.suspend
140 final.suspend: ; preds = %coro.final
141 %final.suspend.coro.save = call token @llvm.coro.save(i8* null)
142 %final.suspend.from_address = call i8* @from_address(i8* %begin)
143 call void @await_suspend()
144 %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)
145 switch i8 %final.suspend.coro.suspend, label %coro.ret [
146 i8 0, label %final.ready
147 i8 1, label %final.cleanup
150 final.cleanup: ; preds = %final.suspend
153 final.ready: ; preds = %final.suspend, %coro.final
154 call void @await_resume()
157 cleanup: ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup
158 %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]
159 %free.memory = call i8* @llvm.coro.free(token %id, i8* %begin)
160 %free = icmp ne i8* %free.memory, null
161 br i1 %free, label %coro.free, label %after.coro.free
163 coro.free: ; preds = %cleanup
164 call void @delete(i8* %free.memory)
165 br label %after.coro.free
167 after.coro.free: ; preds = %coro.free, %cleanup
168 switch i32 %cleanup.dest.slot.0, label %unreachable [
169 i32 0, label %cleanup.cont
170 i32 2, label %coro.ret
173 cleanup.cont: ; preds = %after.coro.free
176 coro.ret: ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend
177 %end = call i1 @llvm.coro.end(i8* null, i1 false)
180 unreachable: ; preds = %after.coro.free
185 define void @bar(i32 %a, i64 %c, double %d) !dbg !19 {
187 %__promise = alloca %promise_type, align 8
188 %0 = bitcast %promise_type* %__promise to i8*
189 %a.alloc = alloca i32, align 4
190 %c.alloc = alloca i64, align 4
191 %d.alloc = alloca double, align 4
192 store i32 %a, i32* %a.alloc
193 store i64 %c, i64* %c.alloc
194 store double %d, double* %d.alloc
195 %struct.data = alloca %struct.big_structure, align 1
196 call void @produce(%struct.big_structure* %struct.data)
197 %id = call token @llvm.coro.id(i32 16, i8* %0, i8* null, i8* null)
198 %alloc = call i1 @llvm.coro.alloc(token %id)
199 br i1 %alloc, label %coro.alloc, label %coro.init
201 coro.alloc: ; preds = %entry
202 %size = call i64 @llvm.coro.size.i64()
203 %memory = call i8* @new(i64 %size)
206 coro.init: ; preds = %coro.alloc, %entry
207 %phi.entry.alloc = phi i8* [ null, %entry ], [ %memory, %coro.alloc ]
208 %begin = call i8* @llvm.coro.begin(token %id, i8* %phi.entry.alloc)
209 call void @llvm.dbg.declare(metadata %promise_type* %__promise, metadata !21, metadata !DIExpression()), !dbg !22
210 %ready = call i1 @await_ready()
211 br i1 %ready, label %init.ready, label %init.suspend
213 init.suspend: ; preds = %coro.init
214 %save = call token @llvm.coro.save(i8* null)
215 call void @await_suspend()
216 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
217 switch i8 %suspend, label %coro.ret [
218 i8 0, label %init.ready
219 i8 1, label %init.cleanup
222 init.cleanup: ; preds = %init.suspend
225 init.ready: ; preds = %init.suspend, %coro.init
226 call void @await_resume()
227 %ready.again = call zeroext i1 @await_ready()
228 br i1 %ready.again, label %await.ready, label %await.suspend
230 await.suspend: ; preds = %init.ready
231 %save.again = call token @llvm.coro.save(i8* null)
232 %from.address = call i8* @from_address(i8* %begin)
233 call void @await_suspend()
234 %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)
235 switch i8 %suspend.again, label %coro.ret [
236 i8 0, label %await.ready
237 i8 1, label %await.cleanup
240 await.cleanup: ; preds = %await.suspend
243 await.ready: ; preds = %await.suspend, %init.ready
244 call void @await_resume()
245 %i.i = getelementptr inbounds %promise_type, %promise_type* %__promise, i64 0, i32 0
246 store i32 1, i32* %i.i, align 8
247 %j.i = getelementptr inbounds %promise_type, %promise_type* %__promise, i64 0, i32 1
248 store i32 2, i32* %j.i, align 4
249 %k.i = getelementptr inbounds %promise_type, %promise_type* %__promise, i64 0, i32 2
250 store double 3.000000e+00, double* %k.i, align 8
251 call void @consume(%struct.big_structure* %struct.data)
252 call void @pi32(i32* %a.alloc)
253 call void @pi64(i64* %c.alloc)
254 call void @pdouble(double* %d.alloc)
255 call void @return_void()
258 coro.final: ; preds = %await.ready
259 call void @final_suspend()
260 %coro.final.await_ready = call i1 @await_ready()
261 br i1 %coro.final.await_ready, label %final.ready, label %final.suspend
263 final.suspend: ; preds = %coro.final
264 %final.suspend.coro.save = call token @llvm.coro.save(i8* null)
265 %final.suspend.from_address = call i8* @from_address(i8* %begin)
266 call void @await_suspend()
267 %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)
268 switch i8 %final.suspend.coro.suspend, label %coro.ret [
269 i8 0, label %final.ready
270 i8 1, label %final.cleanup
273 final.cleanup: ; preds = %final.suspend
276 final.ready: ; preds = %final.suspend, %coro.final
277 call void @await_resume()
280 cleanup: ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup
281 %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]
282 %free.memory = call i8* @llvm.coro.free(token %id, i8* %begin)
283 %free = icmp ne i8* %free.memory, null
284 br i1 %free, label %coro.free, label %after.coro.free
286 coro.free: ; preds = %cleanup
287 call void @delete(i8* %free.memory)
288 br label %after.coro.free
290 after.coro.free: ; preds = %coro.free, %cleanup
291 switch i32 %cleanup.dest.slot.0, label %unreachable [
292 i32 0, label %cleanup.cont
293 i32 2, label %coro.ret
296 cleanup.cont: ; preds = %after.coro.free
299 coro.ret: ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend
300 %end = call i1 @llvm.coro.end(i8* null, i1 false)
303 unreachable: ; preds = %after.coro.free
308 declare void @llvm.dbg.declare(metadata, metadata, metadata)
309 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
310 declare i1 @llvm.coro.alloc(token)
311 declare i64 @llvm.coro.size.i64()
312 declare token @llvm.coro.save(i8*)
313 declare i8* @llvm.coro.begin(token, i8* writeonly)
314 declare i8 @llvm.coro.suspend(token, i1)
315 declare i8* @llvm.coro.free(token, i8* nocapture readonly)
316 declare i1 @llvm.coro.end(i8*, i1)
318 declare i8* @new(i64)
319 declare void @delete(i8*)
320 declare i1 @await_ready()
321 declare void @await_suspend()
322 declare void @await_resume()
323 declare void @print(i32)
324 declare i8* @from_address(i8*)
325 declare void @return_void()
326 declare void @final_suspend()
329 !llvm.linker.options = !{}
330 !llvm.module.flags = !{!3, !4}
333 !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)
334 !1 = !DIFile(filename: "coro-debug.cpp", directory: ".")
336 !3 = !{i32 7, !"Dwarf Version", i32 4}
337 !4 = !{i32 2, !"Debug Info Version", i32 3}
338 !5 = !{!"clang version 11.0.0"}
339 !6 = !DILocalVariable(name: "__promise", scope: !7, file: !1, line: 24, type: !10)
340 !7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
341 !8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !8, file: !1, line: 23, type: !9, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
342 !9 = !DISubroutineType(types: !2)
343 !10 = !DIDerivedType(tag: DW_TAG_typedef, name: "promise_type", scope: !8, file: !1, line: 15, baseType: !11)
344 !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "promise_type", scope: !8, file: !1, line: 10, size: 128, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !12, identifier: "_ZTSN4coro12promise_typeE")
345 !12 = !{!13, !14, !15}
346 !13 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !8, file: !1, line: 10, baseType: !16, size: 32)
347 !14 = !DIDerivedType(tag: DW_TAG_member, name: "j", scope: !8, file: !1, line: 10, baseType: !16, size: 32, offset: 32)
348 !15 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !8, file: !1, line: 10, baseType: !17, size: 64, offset: 64)
349 !16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
350 !17 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
351 !18 = !DILocation(line: 8, scope: !7)
352 !19 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !19, file: !1, line: 54, type: !9, scopeLine: 54, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
353 !20 = distinct !DILexicalBlock(scope: !19, file: !1, line: 23, column: 12)
354 !21 = !DILocalVariable(name: "__promise", scope: !20, file: !1, line: 55, type: !10)
355 !22 = !DILocation(line: 10, scope: !20)