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 #include "InstrProfilingPort.h" 14 #include "InstrProfData.inc" 15 16 enum ValueKind { 17 #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value, 18 #include "InstrProfData.inc" 19 }; 20 21 typedef void *IntPtrT; 22 typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT) 23 __llvm_profile_data { 24 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name; 25 #include "InstrProfData.inc" 26 } __llvm_profile_data; 27 28 typedef struct __llvm_profile_header { 29 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name; 30 #include "InstrProfData.inc" 31 } __llvm_profile_header; 32 33 /*! 34 * \brief Get number of bytes necessary to pad the argument to eight 35 * byte boundary. 36 */ 37 uint8_t __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes); 38 39 /*! 40 * \brief Get required size for profile buffer. 41 */ 42 uint64_t __llvm_profile_get_size_for_buffer(void); 43 44 /*! 45 * \brief Write instrumentation data to the given buffer. 46 * 47 * \pre \c Buffer is the start of a buffer at least as big as \a 48 * __llvm_profile_get_size_for_buffer(). 49 */ 50 int __llvm_profile_write_buffer(char *Buffer); 51 52 const __llvm_profile_data *__llvm_profile_begin_data(void); 53 const __llvm_profile_data *__llvm_profile_end_data(void); 54 const char *__llvm_profile_begin_names(void); 55 const char *__llvm_profile_end_names(void); 56 uint64_t *__llvm_profile_begin_counters(void); 57 uint64_t *__llvm_profile_end_counters(void); 58 59 /*! 60 * \brief Clear profile counters to zero. 61 * 62 */ 63 void __llvm_profile_reset_counters(void); 64 65 /*! 66 * \brief Merge profile data from buffer. 67 * 68 * Read profile data form buffer \p Profile and merge with 69 * in-process profile counters. The client is expected to 70 * have checked or already knows the profile data in the 71 * buffer matches the in-process counter structure before 72 * calling it. 73 */ 74 void __llvm_profile_merge_from_buffer(const char *Profile, uint64_t Size); 75 76 /*! \brief Check if profile in buffer matches the current binary. 77 * 78 * Returns 0 (success) if the profile data in buffer \p Profile with size 79 * \p Size was generated by the same binary and therefore matches 80 * structurally the in-process counters. If the profile data in buffer is 81 * not compatible, the interface returns 1 (failure). 82 */ 83 int __llvm_profile_check_compatibility(const char *Profile, 84 uint64_t Size); 85 86 /*! 87 * \brief Counts the number of times a target value is seen. 88 * 89 * Records the target value for the CounterIndex if not seen before. Otherwise, 90 * increments the counter associated w/ the target value. 91 * void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, 92 * uint32_t CounterIndex); 93 */ 94 void INSTR_PROF_VALUE_PROF_FUNC( 95 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName 96 #include "InstrProfData.inc" 97 ); 98 99 /*! 100 * \brief Prepares the value profiling data for output. 101 * 102 * Returns an array of pointers to value profile data. 103 */ 104 struct ValueProfData; 105 struct ValueProfData **__llvm_profile_gather_value_data(uint64_t *Size); 106 107 /*! 108 * \brief Write instrumentation data to the current file. 109 * 110 * Writes to the file with the last name given to \a * 111 * __llvm_profile_set_filename(), 112 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, 113 * or if that's not set, the last name given to 114 * \a __llvm_profile_override_default_filename(), or if that's not set, 115 * \c "default.profraw". 116 */ 117 int __llvm_profile_write_file(void); 118 119 /*! 120 * \brief Set the filename for writing instrumentation data. 121 * 122 * Sets the filename to be used for subsequent calls to 123 * \a __llvm_profile_write_file(). 124 * 125 * \c Name is not copied, so it must remain valid. Passing NULL resets the 126 * filename logic to the default behaviour. 127 */ 128 void __llvm_profile_set_filename(const char *Name); 129 130 /*! 131 * \brief Set the filename for writing instrumentation data, unless the 132 * \c LLVM_PROFILE_FILE environment variable was set. 133 * 134 * Unless overridden, sets the filename to be used for subsequent calls to 135 * \a __llvm_profile_write_file(). 136 * 137 * \c Name is not copied, so it must remain valid. Passing NULL resets the 138 * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE 139 * was set in which case it has no effect). 140 */ 141 void __llvm_profile_override_default_filename(const char *Name); 142 143 /*! \brief Register to write instrumentation data to file at exit. */ 144 int __llvm_profile_register_write_file_atexit(void); 145 146 /*! \brief Initialize file handling. */ 147 void __llvm_profile_initialize_file(void); 148 149 /*! \brief Get the magic token for the file format. */ 150 uint64_t __llvm_profile_get_magic(void); 151 152 /*! \brief Get the version of the file format. */ 153 uint64_t __llvm_profile_get_version(void); 154 155 /*! \brief Get the number of entries in the profile data section. */ 156 uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin, 157 const __llvm_profile_data *End); 158 159 #endif /* PROFILE_INSTRPROFILING_H_ */ 160