int main(int argc, const char *argv[]) { // CHECK-LABEL: define {{.*}} @main( // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]] if (argc < 2) return 1; const uint64_t MaxSize = 10000; static char Buffer[MaxSize]; uint64_t Size = __llvm_profile_get_size_for_buffer(); if (Size > MaxSize) return 1; int Write = __llvm_profile_write_buffer(Buffer); if (Write) return Write; #ifdef CHECK_SYMBOLS // Don't write it out. Since we're checking the symbols, we don't have libc // available. // Call merge function to make sure it does not bring in libc deps: __llvm_profile_merge_from_buffer(Buffer, Size); return 0; #else // Actually write it out so we can FileCheck the output. FILE *File = fopen(argv[1], "w"); if (!File) return 1; if (fwrite(Buffer, 1, Size, File) != Size) return 1; return fclose(File); #endif }
static uint64_t get_size_for_buffer(int flags) { if (flags & PGO_HIB) { return __llvm_profile_get_size_for_buffer_internal( &__pgo_hib_DataStart, &__pgo_hib_DataEnd, &__pgo_hib_CountersStart, &__pgo_hib_CountersEnd, &__pgo_hib_NamesStart, &__pgo_hib_NamesEnd); } else { return __llvm_profile_get_size_for_buffer(); } }
/* Returns 0 (size) when an error occurs. */ uint64_t libEntry(char *Buffer, uint64_t MaxSize) { uint64_t Size = __llvm_profile_get_size_for_buffer(); if (Size > MaxSize) return 0; __llvm_profile_reset_counters(); bar('1'); if (__llvm_profile_write_buffer(Buffer)) return 0; /* Now check compatibility. Should return 0. */ if (__llvm_profile_check_compatibility(Buffer, Size)) return 0; return Size; }