1// RUN: %clang_profgen -o %t -O3 %s
2// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
3// RUN: llvm-profdata merge -o %t.profdata %t.profraw
4// RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s --check-prefix=PROFCNT
5// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=ORIG
6//
7// RUN: rm -fr %t.dir1
8// RUN: mkdir -p %t.dir1
9// RUN: env LLVM_PROFILE_FILE=%t.dir1/profraw_e_%1m %run %t
10// RUN: env LLVM_PROFILE_FILE=%t.dir1/profraw_e_%1m %run %t
11// RUN: llvm-profdata merge -o %t.em.profdata %t.dir1
12// RUN: llvm-profdata show --all-functions %t.em.profdata | FileCheck %s --check-prefix=PROFCNT
13// RUN: %clang_profuse=%t.em.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=MERGE
14//
15// RUN: rm -fr %t.dir2
16// RUN: mkdir -p %t.dir2
17// RUN: %clang_profgen=%t.dir2/%m.profraw -o %t.merge -O3 %s
18// RUN: %run %t.merge
19// RUN: %run %t.merge
20// RUN: llvm-profdata merge -o %t.m.profdata %t.dir2/
21// RUN: llvm-profdata show --all-functions %t.m.profdata | FileCheck %s --check-prefix=PROFCNT
22// RUN: %clang_profuse=%t.m.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=MERGE
23//
24// Test that merging is enabled by default with -fprofile-generate=
25// RUN: rm -fr %t.dir3
26// RUN: mkdir -p %t.dir3
27// RUN: %clang_pgogen=%t.dir3/ -o %t.merge3 -O0 %s
28// RUN: %run %t.merge3
29// RUN: %run %t.merge3
30// RUN: %run %t.merge3
31// RUN: %run %t.merge3
32// RUN: llvm-profdata merge -o %t.m3.profdata %t.dir3/
33// RUN: llvm-profdata show --all-functions %t.m3.profdata | FileCheck %s --check-prefix=PROFCNT
34// RUN: %clang_profuse=%t.m3.profdata -O0 -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=PGOMERGE
35//
36// Test that merging is enabled by default with -fprofile-generate
37// RUN: rm -fr %t.dir4
38// RUN: mkdir -p %t.dir4
39// RUN: %clang_pgogen -o %t.dir4/merge4 -O0 %s
40// RUN: cd %t.dir4
41// RUN: %run %t.dir4/merge4
42// RUN: %run %t.dir4/merge4
43// RUN: %run %t.dir4/merge4
44// RUN: %run %t.dir4/merge4
45// RUN: rm -f %t.dir4/merge4*
46// RUN: llvm-profdata merge -o %t.m4.profdata ./
47// RUN: llvm-profdata show --all-functions %t.m4.profdata | FileCheck %s --check-prefix=PROFCNT
48// RUN: %clang_profuse=%t.m4.profdata -O0 -o - -S -emit-llvm %s | FileCheck %s --check-prefix=COMMON --check-prefix=PGOMERGE
49
50/// Test that the merge pool size can be larger than 10.
51// RUN: rm -fr %t.dir5
52// RUN: mkdir -p %t.dir5
53// RUN: env LLVM_PROFILE_FILE=%t.dir5/e_%20m.profraw %run %t
54// RUN: not ls %t.dir5/e_%20m.profraw
55// RUN: ls %t.dir5/e_*.profraw | count 1
56
57// Test that all three functions have counters in the profile.
58// PROFCNT-DAG: begin
59// PROFCNT-DAG: end
60// PROFCNT-DAG: main
61// PROFCNT: Functions shown: 3
62// PROFCNT: Total functions: 3
63
64int begin(int i) {
65 // COMMON: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
66 if (i)
67 return 0;
68 return 1;
69}
70
71int end(int i) {
72 // COMMON: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
73 if (i)
74 return 0;
75 return 1;
76}
77
78int main(int argc, const char *argv[]) {
79 begin(i: 0);
80 end(i: 1);
81
82 // COMMON: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
83 if (argc)
84 return 0;
85 return 1;
86}
87
88// ORIG: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
89// ORIG: ![[PD2]] = !{!"branch_weights", i32 2, i32 1}
90// MERGE: ![[PD1]] = !{!"branch_weights", i32 1, i32 3}
91// MERGE: ![[PD2]] = !{!"branch_weights", i32 3, i32 1}
92// PGOMERGE: ![[PD1]] = !{!"branch_weights", i32 0, i32 4}
93// PGOMERGE: ![[PD2]] = !{!"branch_weights", i32 4, i32 0}
94

source code of compiler-rt/test/profile/instrprof-basic.c