Home | History | Annotate | Download | only in profile
      1 // RUN: %clang_profgen -o %t -O3 %s
      2 // RUN: env LLVM_PROFILE_FILE=%t1.profraw %run %t %t2.profraw
      3 // RUN: llvm-profdata merge -o %t1.profdata %t1.profraw
      4 // RUN: %clang_profuse=%t1.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK
      5 // RUN: llvm-profdata merge -o %t2.profdata %t2.profraw
      6 // RUN: %clang_profuse=%t2.profdata -o - -S -emit-llvm %s | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK
      7 
      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 < 2)
     15     return 1;
     16 
     17   // Write out the profile.
     18   __llvm_profile_write_file();
     19 
     20   // Change the profile.
     21   int Ret = foo(0);
     22 
     23   // It'll write out again at exit; change the filename so we get two files.
     24   __llvm_profile_set_filename(argv[1]);
     25   return Ret;
     26 }
     27 int foo(int X) {
     28   // CHECK-LABEL: define {{.*}} @foo(
     29   // CHECK1: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
     30   // CHECK2: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]
     31   return X <= 0 ? -X : X;
     32 }
     33 // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
     34 // CHECK2: ![[PD2]] = !{!"branch_weights", i32 2, i32 1}
     35