Home | History | Annotate | Line # | Download | only in profile
instrprof-write-file-only.c revision 1.1.1.1
      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 int __llvm_profile_write_file(void);
      8 void __llvm_profile_set_filename(const char *);
      9 int foo(int);
     10 int main(int argc, const char *argv[]) {
     11   // CHECK-LABEL: define i32 @main
     12   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !1
     13   if (argc > 1)
     14     return 1;
     15 
     16   // Write out the profile.
     17   __llvm_profile_write_file();
     18 
     19   // Change the profile.
     20   return foo(0);
     21 }
     22 int foo(int X) {
     23   // There should be no profiling information for @foo, since it was called
     24   // after the profile was written (and the atexit was supressed by defining
     25   // profile_runtime).
     26   // CHECK-LABEL: define i32 @foo
     27   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
     28   return X <= 0 ? -X : X;
     29 }
     30 // CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 2}
     31