Debian Codegraph @

llvm/test/Transforms/SampleProfile/pseudo-probe-coro-debug-fix.ll

raw
1 ; REQUIRES: x86-registered-target
2 ; RUN: opt < %s -passes='pseudo-probe,cgscc(coro-split),coro-cleanup,always-inline' -mtriple=x86_64 -pass-remarks=inline -S -o %t.ll
3 ; RUN: llc -mtriple=x86_64 -stop-after=pseudo-probe-inserter < %t.ll --filetype=asm -o - | FileCheck -check-prefix=MIR %s
4
5 ; Making sure PseudoProbeInserter is not generating GUID for `_Z3foov.resume`
6 ; MIR-NOT: PSEUDO_PROBE 4448042984153125393,
7 ; Checking the same for `_Z3foov.cleanup`
8 ; MIR-NOT: PSEUDO_PROBE 3532999944647676065,
9 ; Checking the same for `_Z3foov.destroy`
10 ; MIR-NOT: PSEUDO_PROBE -7235034626494519075,
11
12 ; RUN: llc -mtriple=x86_64 < %t.ll --filetype=obj -o %t.obj
13 ; RUN: obj2yaml %t.obj | FileCheck -check-prefix=OBJ --match-full-lines %s
14 ; OBJ: - Name: '.pseudo_probe (1)'{{$}}
15 ; OBJ-NEXT: Type: SHT_PROGBITS{{$}}
16 ; OBJ-NEXT: Flags: [ SHF_LINK_ORDER ]{{$}}
17 ; OBJ-NEXT: Link: .text{{$}}
18 ; OBJ-NEXT: AddressAlign: 0x1{{$}}
19
20 ; Making sure `_Z3foov.resume` is not a top-level function except when its a sentinel probe (i.e. 20{GUID})
21 ; OBJ-NOT: Content: 11921D00879FBA3D{{[0-9A-F]+$}}
22 ; OBJ-NOT: {{([013-9A-F][0-9A-F])|(2[1-9A-F])}}11921D00879FBA3D{{[0-9A-F]+$}}
23 ; Checking the same for `_Z3foov.cleanup`
24 ; OBJ-NOT: Content: A1103324BBBC0731{{[0-9A-F]+$}}
25 ; OBJ-NOT: {{([013-9A-F][0-9A-F])|(2[1-9A-F])}}A1103324BBBC0731{{[0-9A-F]+$}}
26 ; Checking the same for `_Z3foov.destroy`
27 ; OBJ-NOT: Content: DDA8240E57FE979B{{[0-9A-F]+$}}
28 ; OBJ-NOT: {{([013-9A-F][0-9A-F])|(2[1-9A-F])}}DDA8240E57FE979B{{[0-9A-F]+$}}
29
30 ; OBJ: - Name: .pseudo_probe{{$}}
31 ; OBJ-NEXT: Type: SHT_PROGBITS{{$}}
32 ; OBJ-NEXT: Flags: [ SHF_LINK_ORDER, SHF_GROUP ]{{$}}
33 ; OBJ-NEXT: Link: .text.__clang_call_terminate{{$}}
34
35
36 ; Reduced from original source code:
37 ; clang++ -S -g -O0 SampleProfile/Inputs/pseudo-probe-coro-debug-fix.cpp -emit-llvm -Xclang -disable-llvm-passes -std=c++20 -o SampleProfile/pseudo-probe-coro-debug-fix.ll
38 ;
39 ; #include <coroutine>
40 ; struct co_sleep {
41 ; co_sleep(int n) : delay{n} {}
42 ; constexpr bool await_ready() const noexcept { return false; }
43 ; void await_suspend(std::coroutine_handle<> h) const noexcept {}
44 ; void await_resume() const noexcept {}
45 ; int delay;
46 ; };
47 ; struct Task {
48 ; struct promise_type {
49 ; promise_type() = default;
50 ; Task get_return_object() { return {}; }
51 ; std::suspend_never initial_suspend() { return {}; }
52 ; std::suspend_always final_suspend() noexcept { return {}; }
53 ; void unhandled_exception() {}
54 ; };
55 ; };
56 ; Task foo() noexcept {
57 ; co_await co_sleep{10};
58 ; }
59 ;
60 ; int main() {
61 ; foo();
62 ; }
63
64 ; ModuleID = 'pseudo-probe-coro-debug-fix.cpp'
65 source_filename = "pseudo-probe-coro-debug-fix.cpp"
66 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
67 target triple = "x86_64-redhat-linux-gnu"
68
69 %"struct.Task::promise_type" = type { i8 }
70 %struct.Task = type { i8 }
71 %"struct.std::__n4861::suspend_never" = type { i8 }
72 %struct.co_sleep = type { i32 }
73 %"struct.std::__n4861::suspend_always" = type { i8 }
74
75 $__clang_call_terminate = comdat any
76
77 ; Function Attrs: mustprogress noinline nounwind optnone presplitcoroutine uwtable
78 define dso_local void @_Z3foov() #0 personality ptr @__gxx_personality_v0 !dbg !30 {
79 entry:
80 %__promise = alloca %"struct.Task::promise_type", align 1
81 %undef.agg.tmp = alloca %struct.Task, align 1
82 %ref.tmp = alloca %"struct.std::__n4861::suspend_never", align 1
83 %undef.agg.tmp3 = alloca %"struct.std::__n4861::suspend_never", align 1
84 %ref.tmp5 = alloca %struct.co_sleep, align 4
85 %exn.slot = alloca ptr, align 8
86 %ehselector.slot = alloca i32, align 4
87 %ref.tmp13 = alloca %"struct.std::__n4861::suspend_always", align 1
88 %undef.agg.tmp14 = alloca %"struct.std::__n4861::suspend_always", align 1
89 %0 = call token @llvm.coro.id(i32 16, ptr %__promise, ptr null, ptr null), !dbg !33
90 %1 = call i1 @llvm.coro.alloc(token %0), !dbg !33
91 br i1 %1, label %coro.alloc, label %coro.init, !dbg !33
92
93 coro.alloc: ; preds = %entry
94 %2 = call i64 @llvm.coro.size.i64(), !dbg !34
95 %call = invoke noalias noundef nonnull ptr @_Znwm(i64 noundef %2) #12
96 to label %invoke.cont unwind label %terminate.lpad, !dbg !34
97
98 invoke.cont: ; preds = %coro.alloc
99 br label %coro.init, !dbg !33
100
101 coro.init: ; preds = %invoke.cont, %entry
102 %3 = phi ptr [ null, %entry ], [ %call, %invoke.cont ], !dbg !33
103 %4 = call ptr @llvm.coro.begin(token %0, ptr %3), !dbg !33
104 call void @llvm.lifetime.start.p0(ptr %__promise) #2, !dbg !34
105 #dbg_declare(ptr %__promise, !35, !DIExpression(), !41)
106 call void @llvm.lifetime.start.p0(ptr %ref.tmp5) #2, !dbg !42
107 %5 = call token @llvm.coro.save(ptr null), !dbg !44
108 call void @llvm.coro.await.suspend.void(ptr %ref.tmp5, ptr %4, ptr @_Z3foov.__await_suspend_wrapper__await) #2, !dbg !44
109 %6 = call i8 @llvm.coro.suspend(token %5, i1 false), !dbg !44
110 switch i8 %6, label %coro.ret [
111 i8 0, label %cleanup8
112 i8 1, label %await.cleanup
113 ], !dbg !44
114
115 await.cleanup: ; preds = %coro.init
116 br label %cleanup8, !dbg !44
117
118 coro.final: ; preds = %cleanup8
119 call void @llvm.lifetime.start.p0(ptr %ref.tmp13) #2, !dbg !34
120 %7 = call token @llvm.coro.save(ptr null), !dbg !34
121 call void @llvm.coro.await.suspend.void(ptr %ref.tmp13, ptr %4, ptr @_Z3foov.__await_suspend_wrapper__final) #2, !dbg !34
122 %8 = call i8 @llvm.coro.suspend(token %7, i1 true), !dbg !34
123 switch i8 %8, label %coro.ret [
124 i8 0, label %cleanup16
125 i8 1, label %final.cleanup
126 ], !dbg !34
127
128 final.cleanup: ; preds = %coro.final
129 br label %cleanup16, !dbg !34
130
131 cleanup8: ; preds = %await.cleanup, %coro.init
132 %cleanup.dest.slot.1 = phi i32 [ 0, %coro.init ], [ 2, %await.cleanup ]
133 call void @llvm.lifetime.end.p0(ptr %ref.tmp5) #2, !dbg !44
134 switch i32 %cleanup.dest.slot.1, label %cleanup19 [
135 i32 0, label %coro.final
136 ]
137
138 cleanup16: ; preds = %final.cleanup, %coro.final
139 %cleanup.dest.slot.2 = phi i32 [ 0, %coro.final ], [ 2, %final.cleanup ]
140 call void @llvm.lifetime.end.p0(ptr %ref.tmp13) #2, !dbg !34
141 switch i32 %cleanup.dest.slot.2, label %cleanup19 [
142 i32 0, label %cleanup.cont18
143 ]
144
145 cleanup.cont18: ; preds = %cleanup16
146 br label %cleanup19, !dbg !34
147
148 cleanup19: ; preds = %cleanup.cont18, %cleanup16, %cleanup8
149 %cleanup.dest.slot.3 = phi i32 [ %cleanup.dest.slot.1, %cleanup8 ], [ %cleanup.dest.slot.2, %cleanup16 ], [ 0, %cleanup.cont18 ], !dbg !41
150 call void @llvm.lifetime.end.p0(ptr %__promise) #2, !dbg !34
151 %9 = call ptr @llvm.coro.free(token %0, ptr %4), !dbg !34
152 %10 = icmp ne ptr %9, null, !dbg !34
153 br i1 %10, label %coro.free, label %after.coro.free, !dbg !34
154
155 coro.free: ; preds = %cleanup19
156 %11 = call i64 @llvm.coro.size.i64(), !dbg !34
157 call void @_ZdlPvm(ptr noundef %9, i64 noundef %11) #2, !dbg !34
158 br label %after.coro.free, !dbg !34
159
160 after.coro.free: ; preds = %coro.free, %cleanup19
161 switch i32 %cleanup.dest.slot.3, label %unreachable [
162 i32 0, label %cleanup.cont22
163 i32 2, label %coro.ret
164 ]
165
166 cleanup.cont22: ; preds = %after.coro.free
167 br label %coro.ret, !dbg !34
168
169 coro.ret: ; preds = %cleanup.cont22, %after.coro.free, %coro.final, %coro.init
170 call void @llvm.coro.end(ptr null, i1 false, token none), !dbg !34
171 ret void, !dbg !34
172
173 terminate.lpad: ; preds = %coro.alloc
174 %12 = landingpad { ptr, i32 }
175 catch ptr null, !dbg !34
176 %13 = extractvalue { ptr, i32 } %12, 0, !dbg !34
177 call void @__clang_call_terminate(ptr %13) #13, !dbg !34
178 unreachable, !dbg !34
179
180 unreachable: ; preds = %after.coro.free
181 unreachable
182 }
183
184 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
185 declare token @llvm.coro.id(i32, ptr readnone, ptr readonly captures(none), ptr) #1
186
187 ; Function Attrs: nounwind
188 declare i1 @llvm.coro.alloc(token) #2
189
190 ; Function Attrs: nobuiltin allocsize(0)
191 declare dso_local noundef nonnull ptr @_Znwm(i64 noundef) #3
192
193 ; Function Attrs: nounwind memory(none)
194 declare i64 @llvm.coro.size.i64() #4
195
196 declare dso_local i32 @__gxx_personality_v0(...)
197
198 ; Function Attrs: noinline noreturn nounwind uwtable
199 define linkonce_odr hidden void @__clang_call_terminate(ptr noundef %0) #5 comdat {
200 %2 = call ptr @__cxa_begin_catch(ptr %0) #2
201 call void @_ZSt9terminatev() #13
202 unreachable
203 }
204
205 declare dso_local ptr @__cxa_begin_catch(ptr)
206
207 declare dso_local void @_ZSt9terminatev()
208
209 ; Function Attrs: nounwind
210 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
211
212 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
213 declare void @llvm.lifetime.start.p0(ptr captures(none)) #6
214
215 ; Function Attrs: nomerge nounwind
216 declare token @llvm.coro.save(ptr) #7
217
218 ; Function Attrs: alwaysinline mustprogress
219 define internal void @_Z3foov.__await_suspend_wrapper__init(ptr noundef nonnull %0, ptr noundef %1) #8 !dbg !45 {
220 entry:
221 call void @_ZSt9terminatev() #13
222 ret void, !dbg !47
223 }
224
225 declare void @llvm.coro.await.suspend.void(ptr, ptr, ptr)
226
227 ; Function Attrs: nounwind
228 declare i8 @llvm.coro.suspend(token, i1) #2
229
230 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
231 declare void @llvm.lifetime.end.p0(ptr captures(none)) #6
232
233 ; Function Attrs: alwaysinline mustprogress
234 define internal void @_Z3foov.__await_suspend_wrapper__await(ptr noundef nonnull %0, ptr noundef %1) #8 !dbg !48 {
235 entry:
236 call void @_ZSt9terminatev() #13
237 ret void, !dbg !49
238 }
239
240 declare dso_local void @__cxa_end_catch()
241
242 ; Function Attrs: alwaysinline mustprogress
243 define internal void @_Z3foov.__await_suspend_wrapper__final(ptr noundef nonnull %0, ptr noundef %1) #8 !dbg !50 {
244 entry:
245 call void @_ZSt9terminatev() #13
246 ret void, !dbg !51
247 }
248
249 ; Function Attrs: nobuiltin nounwind
250 declare dso_local void @_ZdlPvm(ptr noundef, i64 noundef) #9
251
252 ; Function Attrs: nounwind memory(argmem: read)
253 declare ptr @llvm.coro.free(token, ptr readonly captures(none)) #10
254
255 ; Function Attrs: nounwind
256 declare void @llvm.coro.end(ptr, i1, token) #2
257
258 ; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable
259 define dso_local noundef i32 @main() #11 !dbg !52 {
260 entry:
261 %undef.agg.tmp = alloca %struct.Task, align 1
262 call void @_Z3foov() #2, !dbg !55
263 ret i32 0, !dbg !56
264 }
265
266 attributes #0 = { mustprogress noinline nounwind optnone presplitcoroutine uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
267 attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
268 attributes #2 = { nounwind }
269 attributes #3 = { nobuiltin allocsize(0) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
270 attributes #4 = { nounwind memory(none) }
271 attributes #5 = { noinline noreturn nounwind uwtable "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
272 attributes #6 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
273 attributes #7 = { nomerge nounwind }
274 attributes #8 = { alwaysinline mustprogress "min-legal-vector-width"="0" }
275 attributes #9 = { nobuiltin nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
276 attributes #10 = { nounwind memory(argmem: read) }
277 attributes #11 = { mustprogress noinline norecurse nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
278 attributes #12 = { allocsize(0) }
279 attributes #13 = { noreturn nounwind }
280
281 !llvm.dbg.cu = !{!0}
282 !llvm.module.flags = !{!24, !25, !26, !27, !28}
283 !llvm.ident = !{!29}
284
285 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 22.0.0git (https://github.com/llvm/llvm-project.git fe218aab737d55dfd67f4f84118744003f45958e)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, splitDebugInlining: false, nameTableKind: None)
286 !1 = !DIFile(filename: "pseudo-probe-coro-debug-fix.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "601552fedf6b88dcf699ea9d066126eb")
287 !2 = !{!3, !6, !15, !20}
288 !3 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "promise_type", scope: !4, file: !1, line: 10, size: 8, flags: DIFlagTypePassByValue, elements: !5, identifier: "_ZTSN4Task12promise_typeE")
289 !4 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Task", file: !1, line: 9, size: 8, flags: DIFlagTypePassByValue, elements: !5, identifier: "_ZTS4Task")
290 !5 = !{}
291 !6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "coroutine_handle<void>", scope: !8, file: !7, line: 87, size: 64, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !10, templateParams: !13, identifier: "_ZTSNSt7__n486116coroutine_handleIvEE")
292 !7 = !DIFile(filename: "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/coroutine", directory: "")
293 !8 = !DINamespace(name: "__n4861", scope: !9, exportSymbols: true)
294 !9 = !DINamespace(name: "std", scope: null)
295 !10 = !{!11}
296 !11 = !DIDerivedType(tag: DW_TAG_member, name: "_M_fr_ptr", scope: !6, file: !7, line: 131, baseType: !12, size: 64, flags: DIFlagProtected)
297 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
298 !13 = !{!14}
299 !14 = !DITemplateTypeParameter(name: "_Promise", type: null, defaulted: true)
300 !15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "coroutine_handle<Task::promise_type>", scope: !8, file: !7, line: 182, size: 64, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !16, templateParams: !18, identifier: "_ZTSNSt7__n486116coroutine_handleIN4Task12promise_typeEEE")
301 !16 = !{!17}
302 !17 = !DIDerivedType(tag: DW_TAG_member, name: "_M_fr_ptr", scope: !15, file: !7, line: 244, baseType: !12, size: 64, flags: DIFlagPrivate)
303 !18 = !{!19}
304 !19 = !DITemplateTypeParameter(name: "_Promise", type: !3)
305 !20 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "co_sleep", file: !1, line: 2, size: 32, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !21, identifier: "_ZTS8co_sleep")
306 !21 = !{!22}
307 !22 = !DIDerivedType(tag: DW_TAG_member, name: "delay", scope: !20, file: !1, line: 7, baseType: !23, size: 32)
308 !23 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
309 !24 = !{i32 7, !"Dwarf Version", i32 5}
310 !25 = !{i32 2, !"Debug Info Version", i32 3}
311 !26 = !{i32 1, !"wchar_size", i32 4}
312 !27 = !{i32 7, !"uwtable", i32 2}
313 !28 = !{i32 7, !"frame-pointer", i32 2}
314 !29 = !{!"clang version 22.0.0git (https://github.com/llvm/llvm-project.git fe218aab737d55dfd67f4f84118744003f45958e)"}
315 !30 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 18, type: !31, scopeLine: 18, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !5)
316 !31 = !DISubroutineType(types: !32)
317 !32 = !{!4}
318 !33 = !DILocation(line: 18, column: 21, scope: !30)
319 !34 = !DILocation(line: 18, column: 6, scope: !30)
320 !35 = !DILocalVariable(name: "__promise", scope: !30, type: !36, flags: DIFlagArtificial)
321 !36 = !DIDerivedType(tag: DW_TAG_typedef, name: "promise_type", scope: !37, file: !7, line: 75, baseType: !3)
322 !37 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__coroutine_traits_impl<Task, void>", scope: !8, file: !7, line: 72, size: 8, flags: DIFlagTypePassByValue, elements: !5, templateParams: !38, identifier: "_ZTSNSt7__n486123__coroutine_traits_implI4TaskvEE")
323 !38 = !{!39, !40}
324 !39 = !DITemplateTypeParameter(name: "_Result", type: !4)
325 !40 = !DITemplateTypeParameter(type: null, defaulted: true)
326 !41 = !DILocation(line: 0, scope: !30)
327 !42 = !DILocation(line: 19, column: 12, scope: !43)
328 !43 = distinct !DILexicalBlock(scope: !30, file: !1, line: 18, column: 21)
329 !44 = !DILocation(line: 19, column: 3, scope: !43)
330 !45 = distinct !DISubprogram(linkageName: "_Z3foov.__await_suspend_wrapper__init", scope: !1, file: !1, type: !46, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !5)
331 !46 = !DISubroutineType(types: !5)
332 !47 = !DILocation(line: 18, column: 6, scope: !45)
333 !48 = distinct !DISubprogram(linkageName: "_Z3foov.__await_suspend_wrapper__await", scope: !1, file: !1, type: !46, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !5)
334 !49 = !DILocation(line: 19, column: 12, scope: !48)
335 !50 = distinct !DISubprogram(linkageName: "_Z3foov.__await_suspend_wrapper__final", scope: !1, file: !1, type: !46, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !5)
336 !51 = !DILocation(line: 18, column: 6, scope: !50)
337 !52 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 22, type: !53, scopeLine: 22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
338 !53 = !DISubroutineType(types: !54)
339 !54 = !{!23}
340 !55 = !DILocation(line: 23, column: 3, scope: !52)
341 !56 = !DILocation(line: 24, column: 1, scope: !52)