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
4 ; This file is based on coro-debug-frame-variable.ll.
5 ; CHECK-LABEL: define void @f(
6 ; CHECK: %[[frame:.*]] = call {{.*}} @llvm.coro.begin
7 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame]]
8 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetX:[0-9]*]]))
9 ; ^ No deref at the end, as this variable ("x") is an array;
10 ; its value is its address. The entire array is in the frame.
11 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame]]
12 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetSpill:[0-9]*]], DW_OP_deref))
13 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame]]
14 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetI:[0-9]*]], DW_OP_deref))
15 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame]]
16 ; CHECK-SAME: !DIExpression(DW_OP_plus_uconst, [[OffsetJ:[0-9]*]], DW_OP_deref))
18 ; CHECK-LABEL: void @f.resume(
19 ; CHECK-SAME: ptr {{.*}} %[[frame:.*]])
20 ; CHECK-SAME: !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]
21 ; CHECK: %[[frame_alloca:.*]] = alloca ptr
22 ; CHECK-NEXT: store ptr %[[frame]], ptr %[[frame_alloca]]
24 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame_alloca]], metadata ![[XVAR_RESUME:[0-9]+]],
25 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetX]])
27 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame_alloca]], metadata ![[SPILL_RESUME:[0-9]+]]
28 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetSpill]], DW_OP_deref)
29 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame_alloca]], metadata ![[IVAR_RESUME:[0-9]+]],
30 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetI]], DW_OP_deref)
31 ; CHECK: call void @llvm.dbg.value(metadata ptr %[[frame_alloca]], metadata ![[JVAR_RESUME:[0-9]+]],
32 ; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetJ]], DW_OP_deref)
34 ; CHECK: ![[RESUME_FN_DBG_NUM]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"
35 ; CHECK: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"
36 ; CHECK: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"
37 ; CHECK: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"
38 ; CHECK: ![[SPILL_RESUME]] = !DILocalVariable(name: "produced"
40 declare void @consume(i32)
42 define void @f(i32 %i, i32 %j) presplitcoroutine !dbg !8 {
44 %__promise = alloca i8, align 8
45 %x = alloca [10 x i32], align 16
46 %produced = call i32 @value_producer()
47 %id = call token @llvm.coro.id(i32 16, ptr %__promise, ptr null, ptr null)
48 %alloc = call i1 @llvm.coro.alloc(token %id)
49 br i1 %alloc, label %coro.alloc, label %coro.init
51 coro.alloc: ; preds = %entry
52 %size = call i64 @llvm.coro.size.i64()
53 %memory = call ptr @new(i64 %size)
56 coro.init: ; preds = %coro.alloc, %entry
57 %phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ]
58 %begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc)
59 %ready = call i1 @await_ready()
60 br i1 %ready, label %init.ready, label %init.suspend
62 init.suspend: ; preds = %coro.init
63 %save = call token @llvm.coro.save(ptr null)
64 call void @await_suspend()
65 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
66 switch i8 %suspend, label %coro.ret [
67 i8 0, label %init.ready
68 i8 1, label %init.cleanup
71 init.cleanup: ; preds = %init.suspend
74 init.ready: ; preds = %init.suspend, %coro.init
75 call void @await_resume()
76 call void @llvm.dbg.value(metadata i32 0, metadata !6, metadata !DIExpression()), !dbg !11
77 %i.init.ready.inc = add nsw i32 0, 1
78 call void @llvm.dbg.value(metadata i32 %i.init.ready.inc, metadata !6, metadata !DIExpression()), !dbg !11
79 call void @llvm.dbg.value(metadata ptr %x, metadata !12, metadata !DIExpression()), !dbg !17
80 call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 40, i1 false), !dbg !17
81 call void @print(i32 %i.init.ready.inc)
82 %ready.again = call zeroext i1 @await_ready()
83 br i1 %ready.again, label %await.ready, label %await.suspend
85 await.suspend: ; preds = %init.ready
86 %save.again = call token @llvm.coro.save(ptr null)
87 %from.address = call ptr @from_address(ptr %begin)
88 call void @await_suspend()
89 %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)
90 switch i8 %suspend.again, label %coro.ret [
91 i8 0, label %await.ready
92 i8 1, label %await.cleanup
95 await.cleanup: ; preds = %await.suspend
98 await.ready: ; preds = %await.suspend, %init.ready
99 call void @await_resume()
100 call void @llvm.dbg.value(metadata i32 0, metadata !18, metadata !DIExpression()), !dbg !11
101 store i32 1, ptr %x, align 16, !dbg !20
102 %arrayidx1 = getelementptr inbounds [10 x i32], ptr %x, i64 0, i64 1, !dbg !21
103 store i32 2, ptr %arrayidx1, align 4, !dbg !22
104 %i.await.ready.inc = add nsw i32 %i.init.ready.inc, 1
105 call void @consume(i32 %produced)
106 call void @consume(i32 %i)
107 call void @consume(i32 %j)
108 call void @llvm.dbg.value(metadata i32 %produced, metadata !23, metadata !DIExpression()), !dbg !11
109 call void @llvm.dbg.value(metadata i32 %i, metadata !6, metadata !DIExpression()), !dbg !11
110 call void @llvm.dbg.value(metadata i32 %j, metadata !18, metadata !DIExpression()), !dbg !11
111 call void @print(i32 %i.await.ready.inc)
112 call void @return_void()
115 coro.final: ; preds = %await.ready
116 call void @final_suspend()
117 %coro.final.await_ready = call i1 @await_ready()
118 br i1 %coro.final.await_ready, label %final.ready, label %final.suspend
120 final.suspend: ; preds = %coro.final
121 %final.suspend.coro.save = call token @llvm.coro.save(ptr null)
122 %final.suspend.from_address = call ptr @from_address(ptr %begin)
123 call void @await_suspend()
124 %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)
125 switch i8 %final.suspend.coro.suspend, label %coro.ret [
126 i8 0, label %final.ready
127 i8 1, label %final.cleanup
130 final.cleanup: ; preds = %final.suspend
133 final.ready: ; preds = %final.suspend, %coro.final
134 call void @await_resume()
137 cleanup: ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup
138 %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]
139 %free.memory = call ptr @llvm.coro.free(token %id, ptr %begin)
140 %free = icmp ne ptr %free.memory, null
141 br i1 %free, label %coro.free, label %after.coro.free
143 coro.free: ; preds = %cleanup
144 call void @delete(ptr %free.memory)
145 br label %after.coro.free
147 after.coro.free: ; preds = %coro.free, %cleanup
148 switch i32 %cleanup.dest.slot.0, label %unreachable [
149 i32 0, label %cleanup.cont
150 i32 2, label %coro.ret
153 cleanup.cont: ; preds = %after.coro.free
156 coro.ret: ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend
157 %end = call i1 @llvm.coro.end(ptr null, i1 false, token none)
160 unreachable: ; preds = %after.coro.free
164 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
165 declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
167 ; Function Attrs: argmemonly nounwind readonly
168 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
170 ; Function Attrs: nounwind
171 declare i1 @llvm.coro.alloc(token) #2
173 ; Function Attrs: nounwind readnone
174 declare i64 @llvm.coro.size.i64() #3
176 ; Function Attrs: nounwind
177 declare token @llvm.coro.save(ptr) #2
179 ; Function Attrs: nounwind
180 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
182 ; Function Attrs: nounwind
183 declare i8 @llvm.coro.suspend(token, i1) #2
185 ; Function Attrs: argmemonly nounwind readonly
186 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
188 ; Function Attrs: nounwind
189 declare i1 @llvm.coro.end(ptr, i1, token) #2
191 declare ptr @new(i64)
193 declare void @delete(ptr)
195 declare i1 @await_ready()
197 declare void @await_suspend()
199 declare void @await_resume()
201 declare void @print(i32)
203 declare ptr @from_address(ptr)
205 declare void @return_void()
207 declare void @final_suspend()
209 declare i32 @value_producer()
211 ; Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
212 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4
214 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
215 declare void @llvm.dbg.value(metadata, metadata, metadata) #0
217 attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
218 attributes #1 = { argmemonly nounwind readonly }
219 attributes #2 = { nounwind }
220 attributes #3 = { nounwind readnone }
221 attributes #4 = { argmemonly nofree nosync nounwind willreturn writeonly }
224 !llvm.linker.options = !{}
225 !llvm.module.flags = !{!3, !4}
228 !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)
229 !1 = !DIFile(filename: "repro.cpp", directory: ".")
231 !3 = !{i32 7, !"Dwarf Version", i32 4}
232 !4 = !{i32 2, !"Debug Info Version", i32 3}
233 !5 = !{!"clang version 11.0.0"}
234 !6 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 24, type: !10)
235 !7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
236 !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)
237 !9 = !DISubroutineType(types: !2)
238 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
239 !11 = !DILocation(line: 0, scope: !7)
240 !12 = !DILocalVariable(name: "x", scope: !13, file: !1, line: 34, type: !14)
241 !13 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
242 !14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 320, elements: !15)
244 !16 = !DISubrange(count: 10)
245 !17 = !DILocation(line: 24, column: 7, scope: !7)
246 !18 = !DILocalVariable(name: "j", scope: !7, file: !1, line: 32, type: !10)
247 !19 = !DILocation(line: 42, column: 3, scope: !7)
248 !20 = !DILocation(line: 42, column: 8, scope: !7)
249 !21 = !DILocation(line: 43, column: 3, scope: !7)
250 !22 = !DILocation(line: 43, column: 8, scope: !7)
251 !23 = !DILocalVariable(name: "produced", scope: !7, file: !1, line:24, type: !10)