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