1 /*===- InstrProfiling.h- Support library for PGO instrumentation ----------===*\ 2 |* 3 |* The LLVM Compiler Infrastructure 4 |* 5 |* This file is distributed under the University of Illinois Open Source 6 |* License. See LICENSE.TXT for details. 7 |* 8 \*===----------------------------------------------------------------------===*/ 9 10 #ifndef PROFILE_INSTRPROFILING_H_ 11 #define PROFILE_INSTRPROFILING_H_ 12 13 #if defined(__FreeBSD__) && defined(__i386__) 14 15 /* System headers define 'size_t' incorrectly on x64 FreeBSD (prior to 16 * FreeBSD 10, r232261) when compiled in 32-bit mode. 17 */ 18 #define PRIu64 "llu" 19 typedef unsigned int uint32_t; 20 typedef unsigned long long uint64_t; 21 typedef uint32_t uintptr_t; 22 23 #else /* defined(__FreeBSD__) && defined(__i386__) */ 24 25 #include <inttypes.h> 26 #include <stdint.h> 27 28 #endif /* defined(__FreeBSD__) && defined(__i386__) */ 29 30 31 typedef struct __llvm_profile_data { 32 const uint32_t NameSize; 33 const uint32_t NumCounters; 34 const uint64_t FuncHash; 35 const char *const Name; 36 uint64_t *const Counters; 37 } __llvm_profile_data; 38 39 typedef struct __llvm_profile_header { 40 uint64_t Magic; 41 uint64_t Version; 42 uint64_t DataSize; 43 uint64_t CountersSize; 44 uint64_t NamesSize; 45 uint64_t CountersDelta; 46 uint64_t NamesDelta; 47 } __llvm_profile_header; 48 49 50 /*! 51 * \brief Get required size for profile buffer. 52 */ 53 uint64_t __llvm_profile_get_size_for_buffer(void); 54 55 /*! 56 * \brief Write instrumentation data to the given buffer. 57 * 58 * \pre \c Buffer is the start of a buffer at least as big as \a 59 * __llvm_profile_get_size_for_buffer(). 60 */ 61 int __llvm_profile_write_buffer(char *Buffer); 62 63 const __llvm_profile_data *__llvm_profile_begin_data(void); 64 const __llvm_profile_data *__llvm_profile_end_data(void); 65 const char *__llvm_profile_begin_names(void); 66 const char *__llvm_profile_end_names(void); 67 uint64_t *__llvm_profile_begin_counters(void); 68 uint64_t *__llvm_profile_end_counters(void); 69 70 /*! 71 * \brief Write instrumentation data to the current file. 72 * 73 * Writes to the file with the last name given to \a __llvm_profile_set_filename(), 74 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, 75 * or if that's not set, the last name given to 76 * \a __llvm_profile_override_default_filename(), or if that's not set, 77 * \c "default.profraw". 78 */ 79 int __llvm_profile_write_file(void); 80 81 /*! 82 * \brief Set the filename for writing instrumentation data. 83 * 84 * Sets the filename to be used for subsequent calls to 85 * \a __llvm_profile_write_file(). 86 * 87 * \c Name is not copied, so it must remain valid. Passing NULL resets the 88 * filename logic to the default behaviour. 89 */ 90 void __llvm_profile_set_filename(const char *Name); 91 92 /*! 93 * \brief Set the filename for writing instrumentation data, unless the 94 * \c LLVM_PROFILE_FILE environment variable was set. 95 * 96 * Unless overridden, sets the filename to be used for subsequent calls to 97 * \a __llvm_profile_write_file(). 98 * 99 * \c Name is not copied, so it must remain valid. Passing NULL resets the 100 * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE 101 * was set in which case it has no effect). 102 */ 103 void __llvm_profile_override_default_filename(const char *Name); 104 105 /*! \brief Register to write instrumentation data to file at exit. */ 106 int __llvm_profile_register_write_file_atexit(void); 107 108 /*! \brief Initialize file handling. */ 109 void __llvm_profile_initialize_file(void); 110 111 /*! \brief Get the magic token for the file format. */ 112 uint64_t __llvm_profile_get_magic(void); 113 114 /*! \brief Get the version of the file format. */ 115 uint64_t __llvm_profile_get_version(void); 116 117 #endif /* PROFILE_INSTRPROFILING_H_ */ 118