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