1// RUN: %clang_profgen -O2 -mllvm -enable-value-profiling=true -mllvm -vp-static-alloc=true -mllvm -vp-counters-per-site=3 -o %t %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 -ic-targets %t.profdata | FileCheck %s
5
6// IR level instrumentation
7// RUN: %clang_pgogen -O2 -mllvm -disable-vp=false -mllvm -vp-static-alloc=true -mllvm -vp-counters-per-site=3 -o %t.ir %s
8// RUN: env LLVM_PROFILE_FILE=%t.ir.profraw %run %t.ir
9// RUN: llvm-profdata merge -o %t.ir.profdata %t.ir.profraw
10// RUN: llvm-profdata show --all-functions -ic-targets %t.ir.profdata | FileCheck %s
11
12// IR level instrumentation, dynamic allocation
13// RUN: %clang_pgogen -O2 -mllvm -disable-vp=false -mllvm -vp-static-alloc=false -o %t.ir.dyn %s
14// RUN: env LLVM_PROFILE_FILE=%t.ir.dyn.profraw %run %t.ir.dyn
15// RUN: llvm-profdata merge -o %t.ir.dyn.profdata %t.ir.dyn.profraw
16// RUN: llvm-profdata show --all-functions -ic-targets %t.ir.dyn.profdata | FileCheck %s
17void callee_0() {}
18void callee_1() {}
19void callee_2() {}
20
21void *CalleeAddrs[] = {callee_0, callee_1, callee_2, callee_2, callee_2};
22extern void lprofSetMaxValsPerSite(unsigned);
23extern void __llvm_profile_reset_counters();
24
25typedef void (*FPT)(void);
26
27
28// Testing value profiling eviction algorithm.
29FPT getCalleeFunc(int I) { return CalleeAddrs[I]; }
30
31int main() {
32 int I;
33
34 // First fill up two value profile entries with two targets
35 lprofSetMaxValsPerSite(2);
36
37 for (I = 0; I < 5; I++) {
38 if (I == 2) {
39 __llvm_profile_reset_counters();
40 }
41 // CHECK: callee_2, 3
42 // CHECK-NEXT: callee_1, 0
43 // CHECK-NOT: callee_0,
44 FPT FP = getCalleeFunc(I);
45 FP();
46 }
47}
48