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