InstrProfiling.h revision 2d1fdb26e458c4ddc04155c1d421bced3ba90cd0
139213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant/*===- InstrProfiling.h- Support library for PGO instrumentation ----------===*\ 239213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant|* 339213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant|* The LLVM Compiler Infrastructure 439213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant|* 539213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant|* This file is distributed under the University of Illinois Open Source 639213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant|* License. See LICENSE.TXT for details. 739213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant|* 839213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant\*===----------------------------------------------------------------------===*/ 939213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 1039213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#ifndef PROFILE_INSTRPROFILING_H_ 1139213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#define PROFILE_INSTRPROFILING_H_ 1239213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 1339213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#if defined(__FreeBSD__) && defined(__i386__) 145e57142c5902c3f73a6fdcb8cab55e88ffb43a56Howard Hinnant 1539213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant/* System headers define 'size_t' incorrectly on x64 FreeBSD (prior to 1639213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant * FreeBSD 10, r232261) when compiled in 32-bit mode. 1739213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant */ 1839213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#define PRIu64 "llu" 1939213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnanttypedef unsigned int uint32_t; 2039213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnanttypedef unsigned long long uint64_t; 2139213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnanttypedef uint32_t uintptr_t; 2239213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 2339213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#else /* defined(__FreeBSD__) && defined(__i386__) */ 2439213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 2539213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#include <inttypes.h> 2639213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#include <stdint.h> 2739213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 2839213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#endif /* defined(__FreeBSD__) && defined(__i386__) */ 2939213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 3039213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant#define PROFILE_HEADER_SIZE 7 3139213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 3239213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnanttypedef struct __llvm_profile_data { 3339213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant const uint32_t NameSize; 3439213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant const uint32_t NumCounters; 3539213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant const uint64_t FuncHash; 3639213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant const char *const Name; 3739213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant uint64_t *const Counters; 3839213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant} __llvm_profile_data; 3939213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant 4039213641f4dbaa2f412bd6cceb57f81edcae95f9Howard Hinnant/*! 41 * \brief Get required size for profile buffer. 42 */ 43uint64_t __llvm_profile_get_size_for_buffer(void); 44 45/*! 46 * \brief Write instrumentation data to the given buffer. 47 * 48 * \pre \c Buffer is the start of a buffer at least as big as \a 49 * __llvm_profile_get_size_for_buffer(). 50 */ 51int __llvm_profile_write_buffer(char *Buffer); 52 53const __llvm_profile_data *__llvm_profile_data_begin(void); 54const __llvm_profile_data *__llvm_profile_data_end(void); 55const char *__llvm_profile_names_begin(void); 56const char *__llvm_profile_names_end(void); 57uint64_t *__llvm_profile_counters_begin(void); 58uint64_t *__llvm_profile_counters_end(void); 59 60#define PROFILE_RANGE_SIZE(Range) \ 61 (__llvm_profile_ ## Range ## _end() - __llvm_profile_ ## Range ## _begin()) 62 63/*! 64 * \brief Write instrumentation data to the current file. 65 * 66 * Writes to the file with the last name given to \a __llvm_profile_set_filename(), 67 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, 68 * or if that's not set, \c "default.profdata". 69 */ 70int __llvm_profile_write_file(void); 71 72/*! 73 * \brief Set the filename for writing instrumentation data. 74 * 75 * Sets the filename to be used for subsequent calls to 76 * \a __llvm_profile_write_file(). 77 * 78 * \c Name is not copied, so it must remain valid. Passing NULL resets the 79 * filename logic to the default behaviour. 80 */ 81void __llvm_profile_set_filename(const char *Name); 82 83/*! \brief Register to write instrumentation data to file at exit. */ 84int __llvm_profile_register_write_file_atexit(void); 85 86/*! \brief Initialize file handling. */ 87void __llvm_profile_initialize_file(void); 88 89/*! \brief Get the magic token for the file format. */ 90uint64_t __llvm_profile_get_magic(void); 91 92/*! \brief Get the version of the file format. */ 93uint64_t __llvm_profile_get_version(void); 94 95#endif /* PROFILE_INSTRPROFILING_H_ */ 96