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 Counts the number of times a target value is seen. 67 * 68 * Records the target value for the CounterIndex if not seen before. Otherwise, 69 * increments the counter associated w/ the target value. 70 * void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, 71 * uint32_t CounterIndex); 72 */ 73 void INSTR_PROF_VALUE_PROF_FUNC( 74 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName 75 #include "InstrProfData.inc" 76 ); 77 78 /*! 79 * \brief Prepares the value profiling data for output. 80 * 81 * Returns an array of pointers to value profile data. 82 */ 83 struct ValueProfData; 84 struct ValueProfData **__llvm_profile_gather_value_data(uint64_t *Size); 85 86 /*! 87 * \brief Write instrumentation data to the current file. 88 * 89 * Writes to the file with the last name given to \a * 90 * __llvm_profile_set_filename(), 91 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, 92 * or if that's not set, the last name given to 93 * \a __llvm_profile_override_default_filename(), or if that's not set, 94 * \c "default.profraw". 95 */ 96 int __llvm_profile_write_file(void); 97 98 /*! 99 * \brief Set the filename for writing instrumentation data. 100 * 101 * Sets the filename to be used for subsequent calls to 102 * \a __llvm_profile_write_file(). 103 * 104 * \c Name is not copied, so it must remain valid. Passing NULL resets the 105 * filename logic to the default behaviour. 106 */ 107 void __llvm_profile_set_filename(const char *Name); 108 109 /*! 110 * \brief Set the filename for writing instrumentation data, unless the 111 * \c LLVM_PROFILE_FILE environment variable was set. 112 * 113 * Unless overridden, sets the filename to be used for subsequent calls to 114 * \a __llvm_profile_write_file(). 115 * 116 * \c Name is not copied, so it must remain valid. Passing NULL resets the 117 * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE 118 * was set in which case it has no effect). 119 */ 120 void __llvm_profile_override_default_filename(const char *Name); 121 122 /*! \brief Register to write instrumentation data to file at exit. */ 123 int __llvm_profile_register_write_file_atexit(void); 124 125 /*! \brief Initialize file handling. */ 126 void __llvm_profile_initialize_file(void); 127 128 /*! \brief Get the magic token for the file format. */ 129 uint64_t __llvm_profile_get_magic(void); 130 131 /*! \brief Get the version of the file format. */ 132 uint64_t __llvm_profile_get_version(void); 133 134 #endif /* PROFILE_INSTRPROFILING_H_ */ 135