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 | f1c9361 | 2014-03-21 18:47:23 +0000 | [diff] [blame] | 10 | #ifndef PROFILE_INSTRPROFILING_H_ |
| 11 | #define PROFILE_INSTRPROFILING_H_ |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 12 | |
Duncan P. N. Exon Smith | 8d02a2a | 2014-03-21 20:59:08 +0000 | [diff] [blame] | 13 | #if defined(__FreeBSD__) && defined(__i386__) |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 14 | |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 15 | /* System headers define 'size_t' incorrectly on x64 FreeBSD (prior to |
| 16 | * FreeBSD 10, r232261) when compiled in 32-bit mode. |
| 17 | */ |
| 18 | #define PRIu64 "llu" |
| 19 | typedef unsigned int uint32_t; |
| 20 | typedef unsigned long long uint64_t; |
Viktor Kutuzov | 9068dfa | 2014-03-26 12:00:44 +0000 | [diff] [blame] | 21 | typedef uint32_t uintptr_t; |
Duncan P. N. Exon Smith | 8d02a2a | 2014-03-21 20:59:08 +0000 | [diff] [blame] | 22 | |
| 23 | #else /* defined(__FreeBSD__) && defined(__i386__) */ |
| 24 | |
| 25 | #include <inttypes.h> |
| 26 | #include <stdint.h> |
| 27 | |
| 28 | #endif /* defined(__FreeBSD__) && defined(__i386__) */ |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 29 | |
Duncan P. N. Exon Smith | 812dcae | 2014-03-21 18:29:24 +0000 | [diff] [blame] | 30 | #define PROFILE_HEADER_SIZE 7 |
| 31 | |
Duncan P. N. Exon Smith | 9edbae0 | 2014-03-20 20:00:44 +0000 | [diff] [blame] | 32 | typedef struct __llvm_profile_data { |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 33 | const uint32_t NameSize; |
| 34 | const uint32_t NumCounters; |
| 35 | const uint64_t FuncHash; |
| 36 | const char *const Name; |
Duncan P. N. Exon Smith | f121217 | 2014-03-20 19:44:31 +0000 | [diff] [blame] | 37 | uint64_t *const Counters; |
Duncan P. N. Exon Smith | 9edbae0 | 2014-03-20 20:00:44 +0000 | [diff] [blame] | 38 | } __llvm_profile_data; |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 39 | |
Duncan P. N. Exon Smith | cf4bb96 | 2014-03-21 18:29:19 +0000 | [diff] [blame] | 40 | /*! |
| 41 | * \brief Get required size for profile buffer. |
| 42 | */ |
| 43 | uint64_t __llvm_profile_get_size_for_buffer(void); |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 44 | |
| 45 | /*! |
| 46 | * \brief Write instrumentation data to the given buffer. |
| 47 | * |
Duncan P. N. Exon Smith | cf4bb96 | 2014-03-21 18:29:19 +0000 | [diff] [blame] | 48 | * \pre \c Buffer is the start of a buffer at least as big as \a |
| 49 | * __llvm_profile_get_size_for_buffer(). |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 50 | */ |
Duncan P. N. Exon Smith | cf4bb96 | 2014-03-21 18:29:19 +0000 | [diff] [blame] | 51 | int __llvm_profile_write_buffer(char *Buffer); |
Duncan P. N. Exon Smith | da0de8a2 | 2014-03-20 03:23:10 +0000 | [diff] [blame] | 52 | |
Justin Bogner | cc0d7ee | 2014-09-04 15:45:31 +0000 | [diff] [blame] | 53 | const __llvm_profile_data *__llvm_profile_begin_data(void); |
| 54 | const __llvm_profile_data *__llvm_profile_end_data(void); |
| 55 | const char *__llvm_profile_begin_names(void); |
| 56 | const char *__llvm_profile_end_names(void); |
| 57 | uint64_t *__llvm_profile_begin_counters(void); |
| 58 | uint64_t *__llvm_profile_end_counters(void); |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 59 | |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 60 | /*! |
| 61 | * \brief Write instrumentation data to the current file. |
| 62 | * |
| 63 | * Writes to the file with the last name given to \a __llvm_profile_set_filename(), |
| 64 | * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable, |
Eric Christopher | d641b53 | 2015-04-28 22:54:51 +0000 | [diff] [blame] | 65 | * or if that's not set, the last name given to |
| 66 | * \a __llvm_profile_override_default_filename(), or if that's not set, |
Diego Novillo | eae9514 | 2015-07-09 17:21:52 +0000 | [diff] [blame^] | 67 | * \c "default.profraw". |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 68 | */ |
| 69 | int __llvm_profile_write_file(void); |
| 70 | |
| 71 | /*! |
| 72 | * \brief Set the filename for writing instrumentation data. |
| 73 | * |
| 74 | * Sets the filename to be used for subsequent calls to |
| 75 | * \a __llvm_profile_write_file(). |
| 76 | * |
| 77 | * \c Name is not copied, so it must remain valid. Passing NULL resets the |
| 78 | * filename logic to the default behaviour. |
| 79 | */ |
| 80 | void __llvm_profile_set_filename(const char *Name); |
| 81 | |
Eric Christopher | d641b53 | 2015-04-28 22:54:51 +0000 | [diff] [blame] | 82 | /*! |
| 83 | * \brief Set the filename for writing instrumentation data, unless the |
| 84 | * \c LLVM_PROFILE_FILE environment variable was set. |
| 85 | * |
| 86 | * Unless overridden, sets the filename to be used for subsequent calls to |
| 87 | * \a __llvm_profile_write_file(). |
| 88 | * |
| 89 | * \c Name is not copied, so it must remain valid. Passing NULL resets the |
| 90 | * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE |
| 91 | * was set in which case it has no effect). |
| 92 | */ |
| 93 | void __llvm_profile_override_default_filename(const char *Name); |
| 94 | |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 95 | /*! \brief Register to write instrumentation data to file at exit. */ |
| 96 | int __llvm_profile_register_write_file_atexit(void); |
| 97 | |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 98 | /*! \brief Initialize file handling. */ |
| 99 | void __llvm_profile_initialize_file(void); |
Duncan P. N. Exon Smith | 0843988 | 2014-05-16 01:30:24 +0000 | [diff] [blame] | 100 | |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 101 | /*! \brief Get the magic token for the file format. */ |
| 102 | uint64_t __llvm_profile_get_magic(void); |
| 103 | |
| 104 | /*! \brief Get the version of the file format. */ |
| 105 | uint64_t __llvm_profile_get_version(void); |
| 106 | |
Duncan P. N. Exon Smith | f1c9361 | 2014-03-21 18:47:23 +0000 | [diff] [blame] | 107 | #endif /* PROFILE_INSTRPROFILING_H_ */ |