Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 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 | |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 10 | #ifndef PROFILE_INSTRPROFILING_H__ |
| 11 | #define PROFILE_INSTRPROFILING_H__ |
| 12 | |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 13 | #define I386_FREEBSD (defined(__FreeBSD__) && defined(__i386__)) |
| 14 | |
| 15 | #if !I386_FREEBSD |
| 16 | #include <inttypes.h> |
| 17 | #endif |
| 18 | |
| 19 | #if !defined(_MSC_VER) && !I386_FREEBSD |
| 20 | #include <stdint.h> |
| 21 | #endif |
| 22 | |
| 23 | #if defined(_MSC_VER) |
| 24 | typedef unsigned int uint32_t; |
| 25 | typedef unsigned long long uint64_t; |
| 26 | #elif I386_FREEBSD |
| 27 | /* System headers define 'size_t' incorrectly on x64 FreeBSD (prior to |
| 28 | * FreeBSD 10, r232261) when compiled in 32-bit mode. |
| 29 | */ |
| 30 | #define PRIu64 "llu" |
| 31 | typedef unsigned int uint32_t; |
| 32 | typedef unsigned long long uint64_t; |
| 33 | #endif |
| 34 | |
Duncan P. N. Exon Smith | 9edbae0 | 2014-03-20 20:00:44 +0000 | [diff] [blame] | 35 | typedef struct __llvm_profile_data { |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 36 | const uint32_t NameSize; |
| 37 | const uint32_t NumCounters; |
| 38 | const uint64_t FuncHash; |
| 39 | const char *const Name; |
Duncan P. N. Exon Smith | f121217 | 2014-03-20 19:44:31 +0000 | [diff] [blame] | 40 | uint64_t *const Counters; |
Duncan P. N. Exon Smith | 9edbae0 | 2014-03-20 20:00:44 +0000 | [diff] [blame] | 41 | } __llvm_profile_data; |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 42 | |
Duncan P. N. Exon Smith | cf4bb96 | 2014-03-21 18:29:19 +0000 | [diff] [blame^] | 43 | /*! |
| 44 | * \brief Get required size for profile buffer. |
| 45 | */ |
| 46 | uint64_t __llvm_profile_get_size_for_buffer(void); |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 47 | |
| 48 | /*! |
| 49 | * \brief Write instrumentation data to the given buffer. |
| 50 | * |
Duncan P. N. Exon Smith | cf4bb96 | 2014-03-21 18:29:19 +0000 | [diff] [blame^] | 51 | * \pre \c Buffer is the start of a buffer at least as big as \a |
| 52 | * __llvm_profile_get_size_for_buffer(). |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 53 | */ |
Duncan P. N. Exon Smith | cf4bb96 | 2014-03-21 18:29:19 +0000 | [diff] [blame^] | 54 | int __llvm_profile_write_buffer(char *Buffer); |
Duncan P. N. Exon Smith | da0de8a2 | 2014-03-20 03:23:10 +0000 | [diff] [blame] | 55 | |
Duncan P. N. Exon Smith | 7170475 | 2014-03-20 20:55:00 +0000 | [diff] [blame] | 56 | const __llvm_profile_data *__llvm_profile_data_begin(void); |
| 57 | const __llvm_profile_data *__llvm_profile_data_end(void); |
| 58 | const char *__llvm_profile_names_begin(void); |
| 59 | const char *__llvm_profile_names_end(void); |
| 60 | uint64_t *__llvm_profile_counters_begin(void); |
| 61 | uint64_t *__llvm_profile_counters_end(void); |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 62 | |
| 63 | #define PROFILE_RANGE_SIZE(Range) \ |
| 64 | (__llvm_profile_ ## Range ## _end() - __llvm_profile_ ## Range ## _begin()) |
| 65 | |
| 66 | /*! |
| 67 | * \brief Write instrumentation data to the current file. |
| 68 | * |
| 69 | * Writes to the file with the last name given to \a __llvm_profile_set_filename(), |
| 70 | * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, |
| 71 | * or if that's not set, \c "default.profdata". |
| 72 | */ |
| 73 | int __llvm_profile_write_file(void); |
| 74 | |
| 75 | /*! |
| 76 | * \brief Set the filename for writing instrumentation data. |
| 77 | * |
| 78 | * Sets the filename to be used for subsequent calls to |
| 79 | * \a __llvm_profile_write_file(). |
| 80 | * |
| 81 | * \c Name is not copied, so it must remain valid. Passing NULL resets the |
| 82 | * filename logic to the default behaviour. |
| 83 | */ |
| 84 | void __llvm_profile_set_filename(const char *Name); |
| 85 | |
| 86 | /*! \brief Register to write instrumentation data to file at exit. */ |
| 87 | int __llvm_profile_register_write_file_atexit(void); |
| 88 | |
| 89 | /*! \brief Get the magic token for the file format. */ |
| 90 | uint64_t __llvm_profile_get_magic(void); |
| 91 | |
| 92 | /*! \brief Get the version of the file format. */ |
| 93 | uint64_t __llvm_profile_get_version(void); |
| 94 | |
| 95 | #endif /* PROFILE_INSTRPROFILING_H__ */ |