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