File: instrprof-dump.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (62 lines) | stat: -rw-r--r-- 1,592 bytes parent folder | download | duplicates (43)
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
/*
RUN: rm -fr %t.profdir
RUN: %clang_profgen=%t.profdir/default_%m.profraw -o %t -O2 %s
RUN: %run %t  2>&1 | FileCheck %s --check-prefix=NO_EXIT_WRITE
RUN: llvm-profdata merge -o %t.profdata %t.profdir
RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s  --check-prefix=PROF

NO_EXIT_WRITE: Profile data not written to file: already written
*/

int __llvm_profile_dump(void);
void __llvm_profile_reset_counters(void);
int foo(int);
int bar(int);
int skip(int);

int main(int argc, const char *argv[]) {
  int Ret = foo(0); /* region 1 */
  __llvm_profile_dump();

  /* not profiled -- cleared later. */
  skip(0);   /* skipped region */
  
  __llvm_profile_reset_counters();
  Ret += bar(0);  /* region 2 */
  __llvm_profile_dump();

  skip(1);

  __llvm_profile_reset_counters();
  /* foo's profile will be merged.  */
  foo(1);  /* region 3 */
  __llvm_profile_dump();

  return Ret;
}

__attribute__((noinline)) int foo(int X) {
  /* PROF: define {{.*}} @foo({{.*}}!prof ![[ENT:[0-9]+]]
     PROF: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
  */
  return X <= 0 ? -X : X;
}

__attribute__((noinline)) int skip(int X) {
  /* PROF: define {{.*}} @skip(
     PROF: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
  */
  return X <= 0 ? -X : X;
}

__attribute__((noinline)) int bar(int X) {
  /* PROF-LABEL: define {{.*}} @bar(
     PROF: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
  */
  return X <= 0 ? -X : X;
}

/*
PROF: ![[ENT]] = !{!"function_entry_count", i64 2}  
PROF: ![[PD1]] = !{!"branch_weights", i32 2, i32 2}
*/