1*7c3d14c8STreehugger Robot /*===- InstrProfiling.h- Support library for PGO instrumentation ----------===*\ 2*7c3d14c8STreehugger Robot |* 3*7c3d14c8STreehugger Robot |* The LLVM Compiler Infrastructure 4*7c3d14c8STreehugger Robot |* 5*7c3d14c8STreehugger Robot |* This file is distributed under the University of Illinois Open Source 6*7c3d14c8STreehugger Robot |* License. See LICENSE.TXT for details. 7*7c3d14c8STreehugger Robot |* 8*7c3d14c8STreehugger Robot \*===----------------------------------------------------------------------===*/ 9*7c3d14c8STreehugger Robot 10*7c3d14c8STreehugger Robot #ifndef PROFILE_INSTRPROFILING_H_ 11*7c3d14c8STreehugger Robot #define PROFILE_INSTRPROFILING_H_ 12*7c3d14c8STreehugger Robot 13*7c3d14c8STreehugger Robot #include "InstrProfilingPort.h" 14*7c3d14c8STreehugger Robot 15*7c3d14c8STreehugger Robot #define INSTR_PROF_VISIBILITY COMPILER_RT_VISIBILITY 16*7c3d14c8STreehugger Robot #include "InstrProfData.inc" 17*7c3d14c8STreehugger Robot 18*7c3d14c8STreehugger Robot enum ValueKind { 19*7c3d14c8STreehugger Robot #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value, 20*7c3d14c8STreehugger Robot #include "InstrProfData.inc" 21*7c3d14c8STreehugger Robot }; 22*7c3d14c8STreehugger Robot 23*7c3d14c8STreehugger Robot typedef void *IntPtrT; 24*7c3d14c8STreehugger Robot typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT) 25*7c3d14c8STreehugger Robot __llvm_profile_data { 26*7c3d14c8STreehugger Robot #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name; 27*7c3d14c8STreehugger Robot #include "InstrProfData.inc" 28*7c3d14c8STreehugger Robot } __llvm_profile_data; 29*7c3d14c8STreehugger Robot 30*7c3d14c8STreehugger Robot typedef struct __llvm_profile_header { 31*7c3d14c8STreehugger Robot #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name; 32*7c3d14c8STreehugger Robot #include "InstrProfData.inc" 33*7c3d14c8STreehugger Robot } __llvm_profile_header; 34*7c3d14c8STreehugger Robot 35*7c3d14c8STreehugger Robot typedef struct ValueProfNode * PtrToNodeT; 36*7c3d14c8STreehugger Robot typedef struct ValueProfNode { 37*7c3d14c8STreehugger Robot #define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer) Type Name; 38*7c3d14c8STreehugger Robot #include "InstrProfData.inc" 39*7c3d14c8STreehugger Robot } ValueProfNode; 40*7c3d14c8STreehugger Robot 41*7c3d14c8STreehugger Robot /*! 42*7c3d14c8STreehugger Robot * \brief Get number of bytes necessary to pad the argument to eight 43*7c3d14c8STreehugger Robot * byte boundary. 44*7c3d14c8STreehugger Robot */ 45*7c3d14c8STreehugger Robot uint8_t __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes); 46*7c3d14c8STreehugger Robot 47*7c3d14c8STreehugger Robot /*! 48*7c3d14c8STreehugger Robot * \brief Get required size for profile buffer. 49*7c3d14c8STreehugger Robot */ 50*7c3d14c8STreehugger Robot uint64_t __llvm_profile_get_size_for_buffer(void); 51*7c3d14c8STreehugger Robot 52*7c3d14c8STreehugger Robot /*! 53*7c3d14c8STreehugger Robot * \brief Write instrumentation data to the given buffer. 54*7c3d14c8STreehugger Robot * 55*7c3d14c8STreehugger Robot * \pre \c Buffer is the start of a buffer at least as big as \a 56*7c3d14c8STreehugger Robot * __llvm_profile_get_size_for_buffer(). 57*7c3d14c8STreehugger Robot */ 58*7c3d14c8STreehugger Robot int __llvm_profile_write_buffer(char *Buffer); 59*7c3d14c8STreehugger Robot 60*7c3d14c8STreehugger Robot const __llvm_profile_data *__llvm_profile_begin_data(void); 61*7c3d14c8STreehugger Robot const __llvm_profile_data *__llvm_profile_end_data(void); 62*7c3d14c8STreehugger Robot const char *__llvm_profile_begin_names(void); 63*7c3d14c8STreehugger Robot const char *__llvm_profile_end_names(void); 64*7c3d14c8STreehugger Robot uint64_t *__llvm_profile_begin_counters(void); 65*7c3d14c8STreehugger Robot uint64_t *__llvm_profile_end_counters(void); 66*7c3d14c8STreehugger Robot ValueProfNode *__llvm_profile_begin_vnodes(); 67*7c3d14c8STreehugger Robot ValueProfNode *__llvm_profile_end_vnodes(); 68*7c3d14c8STreehugger Robot 69*7c3d14c8STreehugger Robot /*! 70*7c3d14c8STreehugger Robot * \brief Clear profile counters to zero. 71*7c3d14c8STreehugger Robot * 72*7c3d14c8STreehugger Robot */ 73*7c3d14c8STreehugger Robot void __llvm_profile_reset_counters(void); 74*7c3d14c8STreehugger Robot 75*7c3d14c8STreehugger Robot /*! 76*7c3d14c8STreehugger Robot * \brief Merge profile data from buffer. 77*7c3d14c8STreehugger Robot * 78*7c3d14c8STreehugger Robot * Read profile data form buffer \p Profile and merge with 79*7c3d14c8STreehugger Robot * in-process profile counters. The client is expected to 80*7c3d14c8STreehugger Robot * have checked or already knows the profile data in the 81*7c3d14c8STreehugger Robot * buffer matches the in-process counter structure before 82*7c3d14c8STreehugger Robot * calling it. 83*7c3d14c8STreehugger Robot */ 84*7c3d14c8STreehugger Robot void __llvm_profile_merge_from_buffer(const char *Profile, uint64_t Size); 85*7c3d14c8STreehugger Robot 86*7c3d14c8STreehugger Robot /*! \brief Check if profile in buffer matches the current binary. 87*7c3d14c8STreehugger Robot * 88*7c3d14c8STreehugger Robot * Returns 0 (success) if the profile data in buffer \p Profile with size 89*7c3d14c8STreehugger Robot * \p Size was generated by the same binary and therefore matches 90*7c3d14c8STreehugger Robot * structurally the in-process counters. If the profile data in buffer is 91*7c3d14c8STreehugger Robot * not compatible, the interface returns 1 (failure). 92*7c3d14c8STreehugger Robot */ 93*7c3d14c8STreehugger Robot int __llvm_profile_check_compatibility(const char *Profile, 94*7c3d14c8STreehugger Robot uint64_t Size); 95*7c3d14c8STreehugger Robot 96*7c3d14c8STreehugger Robot /*! 97*7c3d14c8STreehugger Robot * \brief Counts the number of times a target value is seen. 98*7c3d14c8STreehugger Robot * 99*7c3d14c8STreehugger Robot * Records the target value for the CounterIndex if not seen before. Otherwise, 100*7c3d14c8STreehugger Robot * increments the counter associated w/ the target value. 101*7c3d14c8STreehugger Robot * void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, 102*7c3d14c8STreehugger Robot * uint32_t CounterIndex); 103*7c3d14c8STreehugger Robot */ 104*7c3d14c8STreehugger Robot void INSTR_PROF_VALUE_PROF_FUNC( 105*7c3d14c8STreehugger Robot #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName 106*7c3d14c8STreehugger Robot #include "InstrProfData.inc" 107*7c3d14c8STreehugger Robot ); 108*7c3d14c8STreehugger Robot 109*7c3d14c8STreehugger Robot /*! 110*7c3d14c8STreehugger Robot * \brief Write instrumentation data to the current file. 111*7c3d14c8STreehugger Robot * 112*7c3d14c8STreehugger Robot * Writes to the file with the last name given to \a * 113*7c3d14c8STreehugger Robot * __llvm_profile_set_filename(), 114*7c3d14c8STreehugger Robot * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, 115*7c3d14c8STreehugger Robot * or if that's not set, the last name given to 116*7c3d14c8STreehugger Robot * \a __llvm_profile_override_default_filename(), or if that's not set, 117*7c3d14c8STreehugger Robot * \c "default.profraw". 118*7c3d14c8STreehugger Robot */ 119*7c3d14c8STreehugger Robot int __llvm_profile_write_file(void); 120*7c3d14c8STreehugger Robot 121*7c3d14c8STreehugger Robot /*! 122*7c3d14c8STreehugger Robot * \brief Set the filename for writing instrumentation data. 123*7c3d14c8STreehugger Robot * 124*7c3d14c8STreehugger Robot * Sets the filename to be used for subsequent calls to 125*7c3d14c8STreehugger Robot * \a __llvm_profile_write_file(). 126*7c3d14c8STreehugger Robot * 127*7c3d14c8STreehugger Robot * \c Name is not copied, so it must remain valid. Passing NULL resets the 128*7c3d14c8STreehugger Robot * filename logic to the default behaviour. 129*7c3d14c8STreehugger Robot */ 130*7c3d14c8STreehugger Robot void __llvm_profile_set_filename(const char *Name); 131*7c3d14c8STreehugger Robot 132*7c3d14c8STreehugger Robot /*! 133*7c3d14c8STreehugger Robot * \brief Set the filename for writing instrumentation data, unless the 134*7c3d14c8STreehugger Robot * \c LLVM_PROFILE_FILE environment variable was set. 135*7c3d14c8STreehugger Robot * 136*7c3d14c8STreehugger Robot * Unless overridden, sets the filename to be used for subsequent calls to 137*7c3d14c8STreehugger Robot * \a __llvm_profile_write_file(). 138*7c3d14c8STreehugger Robot * 139*7c3d14c8STreehugger Robot * \c Name is not copied, so it must remain valid. Passing NULL resets the 140*7c3d14c8STreehugger Robot * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE 141*7c3d14c8STreehugger Robot * was set in which case it has no effect). 142*7c3d14c8STreehugger Robot */ 143*7c3d14c8STreehugger Robot void __llvm_profile_override_default_filename(const char *Name); 144*7c3d14c8STreehugger Robot 145*7c3d14c8STreehugger Robot /*! \brief Register to write instrumentation data to file at exit. */ 146*7c3d14c8STreehugger Robot int __llvm_profile_register_write_file_atexit(void); 147*7c3d14c8STreehugger Robot 148*7c3d14c8STreehugger Robot /*! \brief Initialize file handling. */ 149*7c3d14c8STreehugger Robot void __llvm_profile_initialize_file(void); 150*7c3d14c8STreehugger Robot 151*7c3d14c8STreehugger Robot /*! \brief Get the magic token for the file format. */ 152*7c3d14c8STreehugger Robot uint64_t __llvm_profile_get_magic(void); 153*7c3d14c8STreehugger Robot 154*7c3d14c8STreehugger Robot /*! \brief Get the version of the file format. */ 155*7c3d14c8STreehugger Robot uint64_t __llvm_profile_get_version(void); 156*7c3d14c8STreehugger Robot 157*7c3d14c8STreehugger Robot /*! \brief Get the number of entries in the profile data section. */ 158*7c3d14c8STreehugger Robot uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin, 159*7c3d14c8STreehugger Robot const __llvm_profile_data *End); 160*7c3d14c8STreehugger Robot 161*7c3d14c8STreehugger Robot /*! 162*7c3d14c8STreehugger Robot * This variable is defined in InstrProfilingRuntime.cc as a hidden 163*7c3d14c8STreehugger Robot * symbol. Its main purpose is to enable profile runtime user to 164*7c3d14c8STreehugger Robot * bypass runtime initialization code -- if the client code explicitly 165*7c3d14c8STreehugger Robot * define this variable, then InstProfileRuntime.o won't be linked in. 166*7c3d14c8STreehugger Robot * Note that this variable's visibility needs to be hidden so that the 167*7c3d14c8STreehugger Robot * definition of this variable in an instrumented shared library won't 168*7c3d14c8STreehugger Robot * affect runtime initialization decision of the main program. 169*7c3d14c8STreehugger Robot */ 170*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY extern int __llvm_profile_runtime; 171*7c3d14c8STreehugger Robot 172*7c3d14c8STreehugger Robot /*! 173*7c3d14c8STreehugger Robot * This variable is defined in InstrProfiling.c. Its main purpose is to 174*7c3d14c8STreehugger Robot * encode the raw profile version value and other format related information 175*7c3d14c8STreehugger Robot * such as whether the profile is from IR based instrumentation. The variable 176*7c3d14c8STreehugger Robot * is defined as weak so that compiler can emit an overriding definition 177*7c3d14c8STreehugger Robot * depending on user option. Since we don't support mixing FE and IR based 178*7c3d14c8STreehugger Robot * data in the same raw profile data file (in other words, shared libs and 179*7c3d14c8STreehugger Robot * main program are expected to be instrumented in the same way), there is 180*7c3d14c8STreehugger Robot * no need for this variable to be hidden. 181*7c3d14c8STreehugger Robot */ 182*7c3d14c8STreehugger Robot extern uint64_t __llvm_profile_raw_version; 183*7c3d14c8STreehugger Robot 184*7c3d14c8STreehugger Robot #endif /* PROFILE_INSTRPROFILING_H_ */ 185