File: instrprof-gc-sections.c

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (88 lines) | stat: -rw-r--r-- 3,571 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// REQUIRES: linux, lld-available

// RUN: rm -rf %t.profraw
// 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
// RUN: %run %t
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
// RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s -check-prefix=PROF
// RUN: llvm-cov show %t -instr-profile %t.profdata | FileCheck %s -check-prefix=COV
// RUN: llvm-nm %t | FileCheck %s -check-prefix=NM
// RUN: llvm-readelf -x __llvm_prf_names %t | FileCheck %s -check-prefix=PRF_NAMES
// RUN: llvm-size -A %t | FileCheck %s -check-prefix=PRF_CNTS

// RUN: rm -rf %t.lto.profraw
// 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
// RUN: %run %t.lto
// RUN: llvm-profdata merge -o %t.lto.profdata %t.lto.profraw
// RUN: llvm-profdata show --all-functions %t.lto.profdata | FileCheck %s -check-prefix=PROF
// RUN: llvm-cov show %t.lto -instr-profile %t.lto.profdata | FileCheck %s -check-prefix=COV
// RUN: llvm-nm %t.lto | FileCheck %s -check-prefix=NM
// RUN: llvm-readelf -x __llvm_prf_names %t.lto | FileCheck %s -check-prefix=PRF_NAMES
// RUN: llvm-size -A %t.lto | FileCheck %s -check-prefix=PRF_CNTS

// Note: We expect foo() and some of the profiling data associated with it to
// be garbage collected.

// Note: When there is no code in a program, we expect to see the exact same
// set of external functions provided by the profile runtime.

// Note: We also check the IR instrumentation and expect foo() to be garbage
// collected as well.

// RUN: rm -rf %t.pgo.profraw
// RUN: %clang_pgogen=%t.pgo.profraw -fuse-ld=lld -DCODE=1 -ffunction-sections -fdata-sections -Wl,--gc-sections -o %t.pgo %s
// RUN: %run %t.pgo
// RUN: llvm-profdata merge -o %t.pgo.profdata %t.pgo.profraw
// RUN: llvm-profdata show --all-functions %t.pgo.profdata | FileCheck %s -check-prefix=PGO
// RUN: llvm-nm %t.pgo | FileCheck %s -check-prefix=NM

#ifdef CODE

// COV: [[@LINE+1]]{{ *}}|{{ *}}0|void foo()
void foo() {}

// COV: [[@LINE+1]]{{ *}}|{{ *}}1|int main
int main() { return 0; }

#endif // CODE

// NM-NOT: foo

// PROF: Counters:
// PROF-NEXT:   main:
// PROF-NEXT:     Hash:
// PROF-NEXT:     Counters: 1
// PROF-NEXT:     Function count: 1
// PROF-NEXT: Instrumentation level: Front-end
// PROF-NEXT: Functions shown: 1
// PROF-NEXT: Total functions: 1
// PROF-NEXT: Maximum function count:
// PROF-NEXT: Maximum internal block count:

// Note: We don't expect the names of garbage collected functions to disappear
// from __llvm_prf_names, because collectPGOFuncNameStrings() glues the names
// together.

// PRF_NAMES: Hex dump of section '__llvm_prf_names':
// PRF_NAMES-NEXT: {{.*}} 0800666f 6f016d61 696e{{.*$}}
//                        | | f o  o # m a  i n
//                        | |___________|
//                        |             |
//               UncompressedLen = 8    |
//                                      |
//                               CompressedLen = 0

// Note: We expect the profile counters for garbage collected functions to also
// be garbage collected.

// PRF_CNTS: __llvm_prf_cnts 8

// PGO: Counters:
// PGO-NEXT:   main:
// PGO-NEXT:     Hash:
// PGO-NEXT:     Counters: 1
// PGO-NEXT: Instrumentation level: IR
// PGO-NEXT: Functions shown: 1
// PGO-NEXT: Total functions: 1
// PGO-NEXT: Maximum function count:
// PGO-NEXT: Maximum internal block count: