blob: fb6e32a4755e9efe4975c2059ea6cd052744d42f [file] [log] [blame]
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +00001/*===- 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 Smithf1c93612014-03-21 18:47:23 +000010#ifndef PROFILE_INSTRPROFILING_H_
11#define PROFILE_INSTRPROFILING_H_
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +000012
Duncan P. N. Exon Smith8d02a2a2014-03-21 20:59:08 +000013#if defined(__FreeBSD__) && defined(__i386__)
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000014
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000015/* 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"
19typedef unsigned int uint32_t;
20typedef unsigned long long uint64_t;
Viktor Kutuzov9068dfa2014-03-26 12:00:44 +000021typedef uint32_t uintptr_t;
Duncan P. N. Exon Smith8d02a2a2014-03-21 20:59:08 +000022
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 Smith8353a262014-03-19 22:10:27 +000029
Duncan P. N. Exon Smith812dcae2014-03-21 18:29:24 +000030
Duncan P. N. Exon Smith9edbae02014-03-20 20:00:44 +000031typedef struct __llvm_profile_data {
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000032 const uint32_t NameSize;
33 const uint32_t NumCounters;
34 const uint64_t FuncHash;
Xinliang David Li470bfa92015-11-08 18:00:13 +000035 const char *const NamePtr;
36 uint64_t *const CounterPtr;
Duncan P. N. Exon Smith9edbae02014-03-20 20:00:44 +000037} __llvm_profile_data;
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000038
Xinliang David Li4da5de92015-10-16 22:21:56 +000039typedef struct __llvm_profile_header {
40 uint64_t Magic;
41 uint64_t Version;
42 uint64_t DataSize;
43 uint64_t CountersSize;
44 uint64_t NamesSize;
45 uint64_t CountersDelta;
46 uint64_t NamesDelta;
47} __llvm_profile_header;
48
49
Duncan P. N. Exon Smithcf4bb962014-03-21 18:29:19 +000050/*!
51 * \brief Get required size for profile buffer.
52 */
53uint64_t __llvm_profile_get_size_for_buffer(void);
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000054
55/*!
56 * \brief Write instrumentation data to the given buffer.
57 *
Duncan P. N. Exon Smithcf4bb962014-03-21 18:29:19 +000058 * \pre \c Buffer is the start of a buffer at least as big as \a
59 * __llvm_profile_get_size_for_buffer().
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000060 */
Duncan P. N. Exon Smithcf4bb962014-03-21 18:29:19 +000061int __llvm_profile_write_buffer(char *Buffer);
Duncan P. N. Exon Smithda0de8a22014-03-20 03:23:10 +000062
Justin Bognercc0d7ee2014-09-04 15:45:31 +000063const __llvm_profile_data *__llvm_profile_begin_data(void);
64const __llvm_profile_data *__llvm_profile_end_data(void);
65const char *__llvm_profile_begin_names(void);
66const char *__llvm_profile_end_names(void);
67uint64_t *__llvm_profile_begin_counters(void);
68uint64_t *__llvm_profile_end_counters(void);
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +000069
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +000070/*!
71 * \brief Write instrumentation data to the current file.
72 *
73 * Writes to the file with the last name given to \a __llvm_profile_set_filename(),
74 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
Eric Christopherd641b532015-04-28 22:54:51 +000075 * or if that's not set, the last name given to
76 * \a __llvm_profile_override_default_filename(), or if that's not set,
Diego Novilloeae95142015-07-09 17:21:52 +000077 * \c "default.profraw".
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +000078 */
79int __llvm_profile_write_file(void);
80
81/*!
82 * \brief Set the filename for writing instrumentation data.
83 *
84 * Sets the filename to be used for subsequent calls to
85 * \a __llvm_profile_write_file().
86 *
87 * \c Name is not copied, so it must remain valid. Passing NULL resets the
88 * filename logic to the default behaviour.
89 */
90void __llvm_profile_set_filename(const char *Name);
91
Eric Christopherd641b532015-04-28 22:54:51 +000092/*!
93 * \brief Set the filename for writing instrumentation data, unless the
94 * \c LLVM_PROFILE_FILE environment variable was set.
95 *
96 * Unless overridden, sets the filename to be used for subsequent calls to
97 * \a __llvm_profile_write_file().
98 *
99 * \c Name is not copied, so it must remain valid. Passing NULL resets the
100 * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE
101 * was set in which case it has no effect).
102 */
103void __llvm_profile_override_default_filename(const char *Name);
104
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +0000105/*! \brief Register to write instrumentation data to file at exit. */
106int __llvm_profile_register_write_file_atexit(void);
107
Duncan P. N. Exon Smith55e4d662014-05-17 01:27:30 +0000108/*! \brief Initialize file handling. */
109void __llvm_profile_initialize_file(void);
Duncan P. N. Exon Smith08439882014-05-16 01:30:24 +0000110
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +0000111/*! \brief Get the magic token for the file format. */
112uint64_t __llvm_profile_get_magic(void);
113
114/*! \brief Get the version of the file format. */
115uint64_t __llvm_profile_get_version(void);
116
Duncan P. N. Exon Smithf1c93612014-03-21 18:47:23 +0000117#endif /* PROFILE_INSTRPROFILING_H_ */