1 | // REQUIRES: linux, lld-available |
2 | |
3 | // RUN: %clang_profgen=%t.profraw -fuse-ld=lld -fcoverage-mapping -mllvm -enable-name-compression=false -DCODE=1 -ffunction-sections -fdata-sections -Wl,--gc-sections -o %t %s |
4 | // RUN: %run %t |
5 | // RUN: llvm-profdata merge -o %t.profdata %t.profraw |
6 | // RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s -check-prefix=PROF |
7 | // RUN: llvm-cov show %t -instr-profile %t.profdata | FileCheck %s -check-prefix=COV |
8 | // RUN: llvm-nm %t | FileCheck %s -check-prefix=NM |
9 | // RUN: llvm-readelf -x __llvm_prf_names %t | FileCheck %s -check-prefix=PRF_NAMES |
10 | // RUN: llvm-size -A %t | FileCheck %s -check-prefix=PRF_CNTS |
11 | |
12 | // RUN: %clang_lto_profgen=%t.lto.profraw -fuse-ld=lld -fcoverage-mapping -mllvm -enable-name-compression=false -DCODE=1 -ffunction-sections -fdata-sections -Wl,--gc-sections -flto -o %t.lto %s |
13 | // RUN: %run %t.lto |
14 | // RUN: llvm-profdata merge -o %t.lto.profdata %t.lto.profraw |
15 | // RUN: llvm-profdata show --all-functions %t.lto.profdata | FileCheck %s -check-prefix=PROF |
16 | // RUN: llvm-cov show %t.lto -instr-profile %t.lto.profdata | FileCheck %s -check-prefix=COV |
17 | // RUN: llvm-nm %t.lto | FileCheck %s -check-prefix=NM |
18 | // RUN: llvm-readelf -x __llvm_prf_names %t.lto | FileCheck %s -check-prefix=PRF_NAMES |
19 | // RUN: llvm-size -A %t.lto | FileCheck %s -check-prefix=PRF_CNTS |
20 | |
21 | // Note: We expect foo() and some of the profiling data associated with it to |
22 | // be garbage collected. |
23 | |
24 | // Note: When there is no code in a program, we expect to see the exact same |
25 | // set of external functions provided by the profile runtime. |
26 | |
27 | // Note: We also check the IR instrumentation and expect foo() to be garbage |
28 | // collected as well. |
29 | |
30 | // RUN: %clang_pgogen=%t.pgo.profraw -fuse-ld=lld -DCODE=1 -ffunction-sections -fdata-sections -Wl,--gc-sections -o %t.pgo %s |
31 | // RUN: %run %t.pgo |
32 | // RUN: llvm-profdata merge -o %t.pgo.profdata %t.pgo.profraw |
33 | // RUN: llvm-profdata show --all-functions %t.pgo.profdata | FileCheck %s -check-prefix=PGO |
34 | // RUN: llvm-nm %t.pgo | FileCheck %s -check-prefix=NM |
35 | |
36 | #ifdef CODE |
37 | |
38 | // COV: [[@LINE+1]]{{ *}}|{{ *}}0|void foo() |
39 | void foo() {} |
40 | |
41 | // COV: [[@LINE+1]]{{ *}}|{{ *}}1|int main |
42 | int main() { return 0; } |
43 | |
44 | #endif // CODE |
45 | |
46 | // NM-NOT: foo |
47 | |
48 | // PROF: Counters: |
49 | // PROF-NEXT: main: |
50 | // PROF-NEXT: Hash: |
51 | // PROF-NEXT: Counters: 1 |
52 | // PROF-NEXT: Function count: 1 |
53 | // PROF-NEXT: Instrumentation level: Front-end |
54 | // PROF-NEXT: Functions shown: 1 |
55 | // PROF-NEXT: Total functions: 1 |
56 | // PROF-NEXT: Maximum function count: |
57 | // PROF-NEXT: Maximum internal block count: |
58 | |
59 | // Note: We don't expect the names of garbage collected functions to disappear |
60 | // from __llvm_prf_names, because collectPGOFuncNameStrings() glues the names |
61 | // together. |
62 | |
63 | // PRF_NAMES: Hex dump of section '__llvm_prf_names': |
64 | // PRF_NAMES-NEXT: {{.*}} 0800666f 6f016d61 696e{{.*$}} |
65 | // | | f o o # m a i n |
66 | // | |___________| |
67 | // | | |
68 | // UncompressedLen = 8 | |
69 | // | |
70 | // CompressedLen = 0 |
71 | |
72 | // Note: We expect the profile counters for garbage collected functions to also |
73 | // be garbage collected. |
74 | |
75 | // PRF_CNTS: __llvm_prf_cnts 8 |
76 | |
77 | // PGO: Counters: |
78 | // PGO-NEXT: main: |
79 | // PGO-NEXT: Hash: |
80 | // PGO-NEXT: Counters: 1 |
81 | // PGO-NEXT: Instrumentation level: IR |
82 | // PGO-NEXT: Functions shown: 1 |
83 | // PGO-NEXT: Total functions: 1 |
84 | // PGO-NEXT: Maximum function count: |
85 | // PGO-NEXT: Maximum internal block count: |
86 | |