1 ; REQUIRES: x86_64-linux
2 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
3 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
4 ; RUN: llc %t -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
5 ; RUN: llc %t -function-sections -filetype=asm -o %t1
6 ; RUN: FileCheck %s < %t1 --check-prefix=CHECK-ASM
7 ; RUN: llc %t -function-sections -filetype=obj -o %t2
8 ; RUN: llvm-readelf -S -g %t2 | FileCheck %s --check-prefix=CHECK-SEC
9 ; RUN: llvm-mc %t1 -filetype=obj -o %t3
10 ; RUN: llvm-readelf -S -g %t3 | FileCheck %s --check-prefix=CHECK-SEC
12 ; RUN: llc %t -function-sections -unique-section-names=0 -filetype=obj -o %t4
13 ; RUN: llvm-readelf -S %t4 | FileCheck %s --check-prefix=CHECK-SEC2
15 ;; Check the generation of pseudoprobe intrinsic call.
17 @a = dso_local global i32 0, align 4
19 define void @foo(i32 %x) !dbg !3 {
21 %cmp = icmp eq i32 %x, 0
22 ; CHECK-IL-LABEL: void @foo(i32 %x) !dbg ![[#]] {
23 ; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1), !dbg ![[#FAKELINE:]]
24 ; CHECK-MIR: PSEUDO_PROBE [[#GUID:]], 1, 0, 0
25 ; CHECK-ASM: .pseudoprobe [[#GUID:]] 1 0 0 foo
26 br i1 %cmp, label %bb1, label %bb2
29 ; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1), !dbg ![[#FAKELINE]]
30 ; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 3, 0, 0
31 ; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0, 0
32 ; CHECK-ASM: .pseudoprobe [[#GUID]] 3 0 0 foo
33 ; CHECK-ASM: .pseudoprobe [[#GUID]] 4 0 0 foo
34 store i32 6, ptr @a, align 4
38 ; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1), !dbg ![[#FAKELINE]]
39 ; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 2, 0, 0
40 ; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0, 0
41 ; CHECK-ASM: .pseudoprobe [[#GUID]] 2 0 0 foo
42 ; CHECK-ASM: .pseudoprobe [[#GUID]] 4 0 0 foo
43 store i32 8, ptr @a, align 4
47 ; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4, i32 0, i64 -1), !dbg ![[#REALLINE:]]
51 declare void @bar(i32 %x)
53 define internal void @foo2(ptr %f) !dbg !4 {
55 ; CHECK-IL-LABEL: void @foo2(ptr %f) !dbg ![[#]] {
56 ; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1, i32 0, i64 -1)
57 ; CHECK-MIR: PSEUDO_PROBE [[#GUID2:]], 1, 0, 0
58 ; CHECK-ASM: .pseudoprobe [[#GUID2:]] 1 0 0 foo2
59 ; Check pseudo_probe metadata attached to the indirect call instruction.
60 ; CHECK-IL: call void %f(i32 1), !dbg ![[#PROBE0:]]
61 ; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 2, 1, 0
62 ; CHECK-ASM: .pseudoprobe [[#GUID2]] 2 1 0 foo2
63 call void %f(i32 1), !dbg !13
64 ; Check pseudo_probe metadata attached to the direct call instruction.
65 ; CHECK-IL: call void @bar(i32 1), !dbg ![[#PROBE1:]]
66 ; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 3, 2, 0
67 ; CHECK-ASM: .pseudoprobe [[#GUID2]] 3 2 0 foo2
74 define void @foo3(i32 %x) comdat {
79 ; CHECK-IL: Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
80 ; CHECK-IL-NEXT: declare void @llvm.pseudoprobe(i64, i64, i32, i64)
82 ; CHECK-IL: ![[#FOO:]] = distinct !DISubprogram(name: "foo"
83 ; CHECK-IL: ![[#FAKELINE]] = !DILocation(line: 0, scope: ![[#FOO]])
84 ; CHECK-IL: ![[#REALLINE]] = !DILocation(line: 2, scope: ![[#DISC0:]])
85 ; CHECK-IL: ![[#DISC0]] = !DILexicalBlockFile(scope: ![[#FOO]], file: ![[#]], discriminator: 0)
86 ; CHECK-IL: ![[#PROBE0]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE0:]])
87 ;; A discriminator of 67108887 which is 0x7200017 in hexdecimal, stands for a direct call probe
88 ;; with an index of 2.
89 ; CHECK-IL: ![[#SCOPE0]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 119537687)
90 ; CHECK-IL: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
91 ;; A discriminator of 186646559 which is 0xb20001f in hexdecimal, stands for a direct call probe
92 ;; with an index of 3.
93 ; CHECK-IL: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646559)
95 ; Check the generation of .pseudo_probe_desc section
96 ; CHECK-ASM: .section .pseudo_probe_desc,"G",@progbits,.pseudo_probe_desc_foo,comdat
97 ; CHECK-ASM-NEXT: .quad [[#GUID]]
98 ; CHECK-ASM-NEXT: .quad [[#HASH:]]
99 ; CHECK-ASM-NEXT: .byte 3
100 ; CHECK-ASM-NEXT: .ascii "foo"
101 ; CHECK-ASM-NEXT: .section .pseudo_probe_desc,"G",@progbits,.pseudo_probe_desc_foo2,comdat
102 ; CHECK-ASM-NEXT: .quad [[#GUID2]]
103 ; CHECK-ASM-NEXT: .quad [[#HASH2:]]
104 ; CHECK-ASM-NEXT: .byte 4
105 ; CHECK-ASM-NEXT: .ascii "foo2"
107 ; CHECK-SEC: [Nr] Name Type {{.*}} ES Flg Lk Inf Al
108 ; CHECK-SEC: [ 3] .text.foo PROGBITS {{.*}} 00 AX 0 0 16
109 ; CHECK-SEC: [ 5] .text.foo2 PROGBITS {{.*}} 00 AX 0 0 16
110 ; CHECK-SEC: [ 8] .text.foo3 PROGBITS {{.*}} 00 AXG 0 0 16
111 ; CHECK-SEC-COUNT-3: .pseudo_probe_desc PROGBITS
112 ; CHECK-SEC: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1
113 ; CHECK-SEC-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 5 0 1
114 ; CHECK-SEC-NEXT: .pseudo_probe PROGBITS {{.*}} 00 LG 8 0 1
115 ; CHECK-SEC-NOT: .rela.pseudo_probe
117 ; CHECK-SEC: COMDAT group section [ 7] `.group' [foo3] contains 2 sections:
118 ; CHECK-SEC-NEXT: [Index] Name
119 ; CHECK-SEC-NEXT: [ 8] .text.foo3
120 ; CHECK-SEC-NEXT: [ 21] .pseudo_probe
122 ; CHECK-SEC-NEXT: COMDAT group section [ 10] `.group' [.pseudo_probe_desc_foo] contains 1 sections:
123 ; CHECK-SEC-NEXT: [Index] Name
124 ; CHECK-SEC-NEXT: [ 11] .pseudo_probe_desc
126 ; CHECK-SEC-NEXT: COMDAT group section [ 12] `.group' [.pseudo_probe_desc_foo2] contains 1 sections:
127 ; CHECK-SEC-NEXT: [Index] Name
128 ; CHECK-SEC-NEXT: [ 13] .pseudo_probe_desc
130 ; CHECK-SEC-NEXT: COMDAT group section [ 14] `.group' [.pseudo_probe_desc_foo3] contains 1 sections:
131 ; CHECK-SEC-NEXT: [Index] Name
132 ; CHECK-SEC-NEXT: [ 15] .pseudo_probe_desc
135 ; CHECK-SEC2: [Nr] Name Type {{.*}} ES Flg Lk Inf Al
136 ; CHECK-SEC2: [ 3] .text PROGBITS {{.*}} 00 AX 0 0 16
137 ; CHECK-SEC2: [ 5] .text PROGBITS {{.*}} 00 AX 0 0 16
138 ; CHECK-SEC2: [ 8] .text PROGBITS {{.*}} 00 AXG 0 0 16
139 ; CHECK-SEC2-COUNT-3: .pseudo_probe_desc PROGBITS
140 ; CHECK-SEC2: .pseudo_probe PROGBITS {{.*}} 00 L 3 0 1
141 ; CHECK-SEC2-NEXT: .pseudo_probe PROGBITS {{.*}} 00 L 5 0 1
142 ; CHECK-SEC2-NEXT: .pseudo_probe PROGBITS {{.*}} 00 LG 8 0 1
143 ; CHECK-SEC2-NOT: .rela.pseudo_probe
146 !llvm.module.flags = !{!9, !10}
148 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
149 !1 = !DIFile(filename: "test.c", directory: "")
151 !3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
152 !4 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 2, type: !5, unit: !0, retainedNodes: !2)
153 !5 = !DISubroutineType(types: !6)
155 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
156 !9 = !{i32 2, !"Dwarf Version", i32 4}
157 !10 = !{i32 2, !"Debug Info Version", i32 3}
158 !11 = !{!"clang version 3.9.0"}
159 !12 = !DILocation(line: 2, scope: !14)
160 !13 = !DILocation(line: 2, column: 20, scope: !4)
161 !14 = !DILexicalBlockFile(scope: !3, file: !1, discriminator: 1)