xref: /llvm-project/compiler-rt/test/profile/instrprof-entry-coverage.c (revision f872706615cb928ec35ea35280536b59a22a2bf2)
1 // RUN: %clang_pgogen -mllvm -pgo-function-entry-coverage %s -o %t.out
2 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.out
3 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
4 // RUN: llvm-profdata show --covered %t.profdata | FileCheck %s --implicit-check-not goo
5 
6 // We deliberately merge the raw profile twice to test that internal counts can
7 // grow larger than one. Technically, accumulating coverage values is different
8 // than accumulating counts, but this helps discriminate cold functions from hot
9 // functions when the number of raw profiles is large.
10 // RUN: llvm-profdata merge -o %t2.profdata %t.profraw %t.profraw
11 // RUN: llvm-profdata show %t2.profdata | FileCheck %s --check-prefix=COUNTS
12 
13 // RUN: %clang_cspgogen -O1 -mllvm -pgo-function-entry-coverage %s -o %t.cs.out
14 // RUN: env LLVM_PROFILE_FILE=%t.csprofraw %run %t.cs.out
15 // RUN: llvm-profdata merge -o %t.csprofdata %t.csprofraw
16 // RUN: llvm-profdata show --covered %t.csprofdata --showcs | FileCheck %s --implicit-check-not goo
17 // RUN: llvm-profdata merge -o %t2.csprofdata %t.csprofraw %t.csprofraw
18 // RUN: llvm-profdata show --showcs %t2.csprofdata | FileCheck %s --check-prefix=COUNTS
19 
markUsed(int a)20 void markUsed(int a) {
21   volatile int g;
22   g = a;
23 }
24 
foo(int i)25 __attribute__((noinline)) int foo(int i) { return 4 * i + 1; }
bar(int i)26 __attribute__((noinline)) int bar(int i) { return 4 * i + 2; }
goo(int i)27 __attribute__((noinline)) int goo(int i) { return 4 * i + 3; }
28 
main(int argc,char * argv[])29 int main(int argc, char *argv[]) {
30   markUsed(foo(5));
31   markUsed(argc ? bar(6) : goo(7));
32   return 0;
33 }
34 
35 // CHECK-DAG: main
36 // CHECK-DAG: foo
37 // CHECK-DAG: bar
38 
39 // COUNTS: Maximum function count: 2
40