xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/test/profile/instrprof-write-file-only.c (revision ef84fd3bd8895f4e6be1e38baf19e6dc3255bc64)
161f2f256Sjoerg // RUN: %clang_profgen -o %t -O3 %s
261f2f256Sjoerg // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
361f2f256Sjoerg // RUN: llvm-profdata merge -o %t.profdata %t.profraw
461f2f256Sjoerg // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
561f2f256Sjoerg 
661f2f256Sjoerg int __llvm_profile_runtime = 0;
730308f42Sjoerg void __llvm_profile_initialize_file(void);
861f2f256Sjoerg int __llvm_profile_write_file(void);
961f2f256Sjoerg void __llvm_profile_set_filename(const char *);
1061f2f256Sjoerg int foo(int);
main(int argc,const char * argv[])1161f2f256Sjoerg int main(int argc, const char *argv[]) {
12*ef84fd3bSjoerg   // CHECK-LABEL: define {{.*}} @main(
13*ef84fd3bSjoerg   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
1461f2f256Sjoerg   if (argc > 1)
1561f2f256Sjoerg     return 1;
1661f2f256Sjoerg 
1730308f42Sjoerg   // Since the runtime has been suppressed, initialize the file name, as the
1830308f42Sjoerg   // writing will fail below as the file name has not been specified.
1930308f42Sjoerg   __llvm_profile_initialize_file();
2030308f42Sjoerg 
2161f2f256Sjoerg   // Write out the profile.
2261f2f256Sjoerg   __llvm_profile_write_file();
2361f2f256Sjoerg 
2461f2f256Sjoerg   // Change the profile.
2561f2f256Sjoerg   return foo(0);
2661f2f256Sjoerg }
foo(int X)2761f2f256Sjoerg int foo(int X) {
2861f2f256Sjoerg   // There should be no profiling information for @foo, since it was called
2930308f42Sjoerg   // after the profile was written (and the atexit was suppressed by defining
3061f2f256Sjoerg   // profile_runtime).
31*ef84fd3bSjoerg   // CHECK-LABEL: define {{.*}} @foo(
3261f2f256Sjoerg   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}
3361f2f256Sjoerg   return X <= 0 ? -X : X;
3461f2f256Sjoerg }
35*ef84fd3bSjoerg // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
36