xref: /minix3/sys/external/bsd/compiler_rt/dist/test/profile/instrprof-write-file-only.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_profgen -o %t -O3 %s
2*0a6a1f1dSLionel Sambuc // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
3*0a6a1f1dSLionel Sambuc // RUN: llvm-profdata merge -o %t.profdata %t.profraw
4*0a6a1f1dSLionel Sambuc // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
5*0a6a1f1dSLionel Sambuc 
6*0a6a1f1dSLionel Sambuc int __llvm_profile_runtime = 0;
7*0a6a1f1dSLionel Sambuc void __llvm_profile_initialize_file(void);
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 > 1)
15*0a6a1f1dSLionel Sambuc     return 1;
16*0a6a1f1dSLionel Sambuc 
17*0a6a1f1dSLionel Sambuc   // Since the runtime has been suppressed, initialize the file name, as the
18*0a6a1f1dSLionel Sambuc   // writing will fail below as the file name has not been specified.
19*0a6a1f1dSLionel Sambuc   __llvm_profile_initialize_file();
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc   // Write out the profile.
22*0a6a1f1dSLionel Sambuc   __llvm_profile_write_file();
23*0a6a1f1dSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc   // Change the profile.
25*0a6a1f1dSLionel Sambuc   return foo(0);
26*0a6a1f1dSLionel Sambuc }
foo(int X)27*0a6a1f1dSLionel Sambuc int foo(int X) {
28*0a6a1f1dSLionel Sambuc   // There should be no profiling information for @foo, since it was called
29*0a6a1f1dSLionel Sambuc   // after the profile was written (and the atexit was suppressed by defining
30*0a6a1f1dSLionel Sambuc   // profile_runtime).
31*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define i32 @foo
32*0a6a1f1dSLionel Sambuc   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
33*0a6a1f1dSLionel Sambuc   return X <= 0 ? -X : X;
34*0a6a1f1dSLionel Sambuc }
35*0a6a1f1dSLionel Sambuc // CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 2}
36