1// Testing profile generate.
2// RUN: %clang_profgen %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
3// RUN: %clang_pgogen %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFGEN
4
5// Testing profile use. Generate some profile file first.
6// RUN: rm -rf rawprof.profraw
7// RUN: %clang_profgen -o %t1 %s
8// RUN: %run %t1
9// RUN: llvm-profdata merge -o %t1.profdata rawprof.profraw
10// RUN: %clang_profuse=%t1.profdata %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFUSE
11// RUN: rm -rf rawprof.profraw
12// RUN: %clang_pgogen -o %t2 %s
13// RUN: %run %t2
14// RUN: llvm-profdata merge -o %t2.profdata rawprof.profraw
15// RUN: %clang_pgouse=%t2.profdata %s -S -emit-llvm -o - | FileCheck %s --check-prefix=PROFUSE
16#include "profile/instr_prof_interface.h"
17
18__attribute__((noinline)) int bar() { return 4; }
19
20int foo() {
21 __llvm_profile_reset_counters();
22 // PROFGEN: call void @__llvm_profile_reset_counters()
23 // PROFUSE-NOT: call void @__llvm_profile_reset_counters()
24 return bar();
25}
26
27// PROFUSE-NOT: declare void @__llvm_profile_reset_counters()
28
29int main() {
30 int z = foo() + 3;
31 __llvm_profile_set_filename("rawprof.profraw");
32 // PROFGEN: call void @__llvm_profile_set_filename(ptr noundef @{{.*}})
33 // PROFUSE-NOT: call void @__llvm_profile_set_filename(ptr noundef @{{.*}})
34 if (__llvm_profile_dump())
35 return 2;
36 // PROFGEN: %{{.*}} = call {{(signext )*}}i32 @__llvm_profile_dump()
37 // PROFUSE-NOT: %{{.*}} = call {{(signext )*}}i32 @__llvm_profile_dump()
38 return z + bar() - 11;
39}
40
41// PROFUSE-NOT: declare void @__llvm_profile_set_filename(ptr noundef)
42// PROFUSE-NOT: declare signext i32 @__llvm_profile_dump()
43

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