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