Home | History | Annotate | Download | only in profile
      1 // RUN: %clang_profgen -o %t -O3 %s
      2 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
      3 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
      4 // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
      5 
      6 int __llvm_profile_runtime = 0;
      7 void __llvm_profile_initialize_file(void);
      8 int __llvm_profile_write_file(void);
      9 void __llvm_profile_set_filename(const char *);
     10 int foo(int);
     11 int main(int argc, const char *argv[]) {
     12   // CHECK-LABEL: define {{.*}} @main(
     13   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
     14   if (argc > 42)
     15     return 1;
     16 
     17   // Since the runtime has been suppressed, initialize the file name, as the
     18   // writing will fail below as the file name has not been specified.
     19   __llvm_profile_initialize_file();
     20 
     21   // Write out the profile.
     22   __llvm_profile_write_file();
     23 
     24   // Change the profile.
     25   return foo(0);
     26 }
     27 int foo(int X) {
     28   // There should be no profiling information for @foo, since it was called
     29   // after the profile was written (and the atexit was suppressed by defining
     30   // profile_runtime).
     31   // CHECK-LABEL: define {{.*}} @foo(
     32   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
     33   return X <= 0 ? -X : X;
     34 }
     35 // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
     36