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