Home | History | Annotate | Line # | Download | only in profile
      1      1.1  joerg // RUN: %clang_profgen -DCHECK_SYMBOLS -O3 -o %t.symbols %s
      2      1.1  joerg // RUN: llvm-nm %t.symbols | FileCheck %s --check-prefix=CHECK-SYMBOLS
      3      1.1  joerg // RUN: %clang_profgen -O3 -o %t %s
      4      1.1  joerg // RUN: %run %t %t.profraw
      5      1.1  joerg // RUN: llvm-profdata merge -o %t.profdata %t.profraw
      6      1.1  joerg // RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
      7      1.1  joerg 
      8      1.1  joerg #include <stdint.h>
      9      1.1  joerg #include <stdlib.h>
     10      1.1  joerg 
     11      1.1  joerg #ifndef CHECK_SYMBOLS
     12      1.1  joerg #include <stdio.h>
     13      1.1  joerg #endif
     14      1.1  joerg 
     15      1.1  joerg int __llvm_profile_runtime = 0;
     16      1.1  joerg uint64_t __llvm_profile_get_size_for_buffer(void);
     17      1.1  joerg int __llvm_profile_write_buffer(char *);
     18      1.1  joerg int write_buffer(uint64_t, const char *);
     19      1.1  joerg int main(int argc, const char *argv[]) {
     20  1.1.1.2  joerg   // CHECK-LABEL: define {{.*}} @main(
     21  1.1.1.2  joerg   // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]
     22      1.1  joerg   if (argc < 2)
     23      1.1  joerg     return 1;
     24      1.1  joerg 
     25      1.1  joerg   const uint64_t MaxSize = 10000;
     26      1.1  joerg   static char Buffer[MaxSize];
     27      1.1  joerg 
     28      1.1  joerg   uint64_t Size = __llvm_profile_get_size_for_buffer();
     29      1.1  joerg   if (Size > MaxSize)
     30      1.1  joerg     return 1;
     31      1.1  joerg   int Write = __llvm_profile_write_buffer(Buffer);
     32      1.1  joerg   if (__llvm_profile_write_buffer(Buffer))
     33      1.1  joerg     return Write;
     34      1.1  joerg 
     35      1.1  joerg #ifdef CHECK_SYMBOLS
     36      1.1  joerg   // Don't write it out.  Since we're checking the symbols, we don't have libc
     37      1.1  joerg   // available.
     38      1.1  joerg   return 0;
     39      1.1  joerg #else
     40      1.1  joerg   // Actually write it out so we can FileCheck the output.
     41      1.1  joerg   FILE *File = fopen(argv[1], "w");
     42      1.1  joerg   if (!File)
     43      1.1  joerg     return 1;
     44      1.1  joerg   if (fwrite(Buffer, 1, Size, File) != Size)
     45      1.1  joerg     return 1;
     46      1.1  joerg   return fclose(File);
     47      1.1  joerg #endif
     48      1.1  joerg }
     49  1.1.1.2  joerg // CHECK: ![[PD1]] = !{!"branch_weights", i32 1, i32 2}
     50      1.1  joerg 
     51      1.1  joerg // CHECK-SYMBOLS-NOT: ___cxx_global_var_init
     52      1.1  joerg // CHECK-SYMBOLS-NOT: ___llvm_profile_register_write_file_atexit
     53      1.1  joerg // CHECK-SYMBOLS-NOT: ___llvm_profile_set_filename
     54      1.1  joerg // CHECK-SYMBOLS-NOT: ___llvm_profile_write_file
     55      1.1  joerg // CHECK-SYMBOLS-NOT: _fdopen
     56      1.1  joerg // CHECK-SYMBOLS-NOT: _fopen
     57      1.1  joerg // CHECK-SYMBOLS-NOT: _fwrite
     58      1.1  joerg // CHECK-SYMBOLS-NOT: _getenv
     59  1.1.1.2  joerg // CHECK-SYMBOLS-NOT: getenv
     60      1.1  joerg // CHECK-SYMBOLS-NOT: _malloc
     61  1.1.1.2  joerg // CHECK-SYMBOLS-NOT: malloc
     62  1.1.1.2  joerg // CHECK-SYMBOLS-NOT: _calloc
     63  1.1.1.2  joerg // CHECK-SYMBOLS-NOT: calloc
     64  1.1.1.2  joerg // CHECK-SYMBOLS-NOT: _free
     65  1.1.1.2  joerg // CHECK-SYMBOLS-NOT: free
     66      1.1  joerg // CHECK-SYMBOLS-NOT: _open
     67