xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-debug-O2.ll (revision 07514fa9b607fd80a72a80270d714e22d842fa39)
1; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split<reuse-storage>),function(sroa)' -S | FileCheck %s
2; RUN: opt --try-experimental-debuginfo-iterators < %s -passes='module(coro-early),cgscc(coro-split<reuse-storage>),function(sroa)' -S | FileCheck %s
3
4; Checks the dbg informations about promise and coroutine frames under O2.
5
6; CHECK-LABEL: define internal fastcc void @f.resume({{.*}})
7; CHECK:       entry.resume:
8; CHECK:        #dbg_value(ptr poison, ![[PROMISEVAR_RESUME:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16
9; CHECK:        #dbg_value(ptr %begin, ![[CORO_FRAME:[0-9]+]], !DIExpression(DW_OP_deref)
10;
11; CHECK: ![[CORO_FRAME]] = !DILocalVariable(name: "__coro_frame"
12; CHECK: ![[PROMISEVAR_RESUME]] = !DILocalVariable(name: "__promise"
13%promise_type = type { i32, i32, double }
14
15define void @f() presplitcoroutine !dbg !8  {
16entry:
17    %__promise = alloca %promise_type, align 8
18    %id = call token @llvm.coro.id(i32 16, ptr %__promise, ptr null, ptr null)
19    %alloc = call i1 @llvm.coro.alloc(token %id)
20    br i1 %alloc, label %coro.alloc, label %coro.init
21
22coro.alloc:                                       ; preds = %entry
23    %size = call i64 @llvm.coro.size.i64()
24    %memory = call ptr @new(i64 %size)
25    br label %coro.init
26
27coro.init:                                        ; preds = %coro.alloc, %entry
28    %phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ]
29    %begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc)
30    call void @llvm.dbg.declare(metadata ptr %__promise, metadata !6, metadata !DIExpression()), !dbg !18
31    store i32 1, ptr %__promise, align 8
32    %j.i = getelementptr inbounds %promise_type, ptr %__promise, i64 0, i32 1
33    store i32 2, ptr %j.i, align 4
34    %k.i = getelementptr inbounds %promise_type, ptr %__promise, i64 0, i32 2
35    store double 3.000000e+00, ptr %k.i, align 8
36    %ready = call i1 @await_ready()
37    br i1 %ready, label %init.ready, label %init.suspend
38
39init.suspend:                                     ; preds = %coro.init
40    %save = call token @llvm.coro.save(ptr null)
41    call void @await_suspend()
42    %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
43    switch i8 %suspend, label %coro.ret [
44        i8 0, label %init.ready
45        i8 1, label %init.cleanup
46    ]
47
48init.cleanup:                                     ; preds = %init.suspend
49    br label %cleanup
50
51init.ready:                                       ; preds = %init.suspend, %coro.init
52    call void @await_resume()
53    %ready.again = call zeroext i1 @await_ready()
54    br i1 %ready.again, label %await.ready, label %await.suspend
55
56await.suspend:                                    ; preds = %init.ready
57    %save.again = call token @llvm.coro.save(ptr null)
58    %from.address = call ptr @from_address(ptr %begin)
59    call void @await_suspend()
60    %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)
61    switch i8 %suspend.again, label %coro.ret [
62        i8 0, label %await.ready
63        i8 1, label %await.cleanup
64    ]
65
66await.cleanup:                                    ; preds = %await.suspend
67    br label %cleanup
68
69await.ready:                                      ; preds = %await.suspend, %init.ready
70    call void @await_resume()
71    call void @return_void()
72    br label %coro.final
73
74coro.final:                                       ; preds = %await.ready
75    call void @final_suspend()
76    %coro.final.await_ready = call i1 @await_ready()
77    br i1 %coro.final.await_ready, label %final.ready, label %final.suspend
78
79final.suspend:                                    ; preds = %coro.final
80    %final.suspend.coro.save = call token @llvm.coro.save(ptr null)
81    %final.suspend.from_address = call ptr @from_address(ptr %begin)
82    call void @await_suspend()
83    %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)
84    switch i8 %final.suspend.coro.suspend, label %coro.ret [
85        i8 0, label %final.ready
86        i8 1, label %final.cleanup
87    ]
88
89final.cleanup:                                    ; preds = %final.suspend
90    br label %cleanup
91
92final.ready:                                      ; preds = %final.suspend, %coro.final
93    call void @await_resume()
94    br label %cleanup
95
96cleanup:                                          ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup
97    %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]
98    %free.memory = call ptr @llvm.coro.free(token %id, ptr %begin)
99    %free = icmp ne ptr %free.memory, null
100    br i1 %free, label %coro.free, label %after.coro.free
101
102coro.free:                                        ; preds = %cleanup
103    call void @delete(ptr %free.memory)
104    br label %after.coro.free
105
106after.coro.free:                                  ; preds = %coro.free, %cleanup
107    switch i32 %cleanup.dest.slot.0, label %unreachable [
108        i32 0, label %cleanup.cont
109        i32 2, label %coro.ret
110    ]
111
112cleanup.cont:                                     ; preds = %after.coro.free
113    br label %coro.ret
114
115coro.ret:                                         ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend
116    %end = call i1 @llvm.coro.end(ptr null, i1 false, token none)
117    ret void
118
119unreachable:                                      ; preds = %after.coro.free
120    unreachable
121
122}
123
124declare void @llvm.dbg.declare(metadata, metadata, metadata)
125declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
126declare i1 @llvm.coro.alloc(token)
127declare i64 @llvm.coro.size.i64()
128declare token @llvm.coro.save(ptr)
129declare ptr @llvm.coro.begin(token, ptr writeonly)
130declare i8 @llvm.coro.suspend(token, i1)
131declare ptr @llvm.coro.free(token, ptr nocapture readonly)
132declare i1 @llvm.coro.end(ptr, i1, token)
133
134declare ptr @new(i64)
135declare void @delete(ptr)
136declare i1 @await_ready()
137declare void @await_suspend()
138declare void @await_resume()
139declare void @print(i32)
140declare ptr @from_address(ptr)
141declare void @return_void()
142declare void @final_suspend()
143
144!llvm.dbg.cu = !{!0}
145!llvm.linker.options = !{}
146!llvm.module.flags = !{!3, !4}
147!llvm.ident = !{!5}
148
149!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)
150!1 = !DIFile(filename: "coro-debug.cpp", directory: ".")
151!2 = !{}
152!3 = !{i32 7, !"Dwarf Version", i32 4}
153!4 = !{i32 2, !"Debug Info Version", i32 3}
154!5 = !{!"clang version 11.0.0"}
155!6 = !DILocalVariable(name: "__promise", scope: !7, file: !1, line: 24, type: !10)
156!7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)
157!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)
158!9 = !DISubroutineType(types: !2)
159!10 = !DIDerivedType(tag: DW_TAG_typedef, name: "promise_type", scope: !8, file: !1, line: 15, baseType: !11)
160!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")
161!12 = !{!13, !14, !15}
162!13 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !8, file: !1, line: 10, baseType: !16, size: 32)
163!14 = !DIDerivedType(tag: DW_TAG_member, name: "j", scope: !8, file: !1, line: 10, baseType: !16, size: 32, offset: 32)
164!15 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !8, file: !1, line: 10, baseType: !17, size: 64, offset: 64)
165!16 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
166!17 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
167!18 = !DILocation(line: 0, scope: !7)
168
169
170
171
172
173
174