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