xref: /minix3/sys/external/bsd/compiler_rt/dist/test/profile/instrprof-write-file.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_profgen -o %t -O3 %s
2*0a6a1f1dSLionel Sambuc // RUN: env LLVM_PROFILE_FILE=%t1.profraw %run %t %t2.profraw
3*0a6a1f1dSLionel Sambuc // RUN: llvm-profdata merge -o %t1.profdata %t1.profraw
4*0a6a1f1dSLionel Sambuc // RUN: %clang_profuse=%t1.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK
5*0a6a1f1dSLionel Sambuc // RUN: llvm-profdata merge -o %t2.profdata %t2.profraw
6*0a6a1f1dSLionel Sambuc // RUN: %clang_profuse=%t2.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc int __llvm_profile_write_file(void);
9*0a6a1f1dSLionel Sambuc void __llvm_profile_set_filename(const char *);
10*0a6a1f1dSLionel Sambuc int foo(int);
main(int argc,const char * argv[])11*0a6a1f1dSLionel Sambuc int main(int argc, const char *argv[]) {
12*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define i32 @main
13*0a6a1f1dSLionel Sambuc   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !1
14*0a6a1f1dSLionel Sambuc   if (argc < 2)
15*0a6a1f1dSLionel Sambuc     return 1;
16*0a6a1f1dSLionel Sambuc 
17*0a6a1f1dSLionel Sambuc   // Write out the profile.
18*0a6a1f1dSLionel Sambuc   __llvm_profile_write_file();
19*0a6a1f1dSLionel Sambuc 
20*0a6a1f1dSLionel Sambuc   // Change the profile.
21*0a6a1f1dSLionel Sambuc   int Ret = foo(0);
22*0a6a1f1dSLionel Sambuc 
23*0a6a1f1dSLionel Sambuc   // It'll write out again at exit; change the filename so we get two files.
24*0a6a1f1dSLionel Sambuc   __llvm_profile_set_filename(argv[1]);
25*0a6a1f1dSLionel Sambuc   return Ret;
26*0a6a1f1dSLionel Sambuc }
foo(int X)27*0a6a1f1dSLionel Sambuc int foo(int X) {
28*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define i32 @foo
29*0a6a1f1dSLionel Sambuc   // CHECK1: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
30*0a6a1f1dSLionel Sambuc   // CHECK2: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !2
31*0a6a1f1dSLionel Sambuc   return X <= 0 ? -X : X;
32*0a6a1f1dSLionel Sambuc }
33*0a6a1f1dSLionel Sambuc // CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 2}
34*0a6a1f1dSLionel Sambuc // CHECK2: !2 = metadata !{metadata !"branch_weights", i32 2, i32 1}
35