blob: 1198749ea98400062afae667f69d93861c842427 [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;
Duncan P. N. Exon Smith8d02a2a2014-03-21 20:59:08 +000021
22#else /* defined(__FreeBSD__) && defined(__i386__) */
23
24#include <inttypes.h>
25#include <stdint.h>
26
27#endif /* defined(__FreeBSD__) && defined(__i386__) */
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000028
Duncan P. N. Exon Smith812dcae2014-03-21 18:29:24 +000029#define PROFILE_HEADER_SIZE 7
30
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;
35 const char *const Name;
Duncan P. N. Exon Smithf1212172014-03-20 19:44:31 +000036 uint64_t *const Counters;
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
Duncan P. N. Exon Smithcf4bb962014-03-21 18:29:19 +000039/*!
40 * \brief Get required size for profile buffer.
41 */
42uint64_t __llvm_profile_get_size_for_buffer(void);
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000043
44/*!
45 * \brief Write instrumentation data to the given buffer.
46 *
Duncan P. N. Exon Smithcf4bb962014-03-21 18:29:19 +000047 * \pre \c Buffer is the start of a buffer at least as big as \a
48 * __llvm_profile_get_size_for_buffer().
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000049 */
Duncan P. N. Exon Smithcf4bb962014-03-21 18:29:19 +000050int __llvm_profile_write_buffer(char *Buffer);
Duncan P. N. Exon Smithda0de8a22014-03-20 03:23:10 +000051
Duncan P. N. Exon Smith71704752014-03-20 20:55:00 +000052const __llvm_profile_data *__llvm_profile_data_begin(void);
53const __llvm_profile_data *__llvm_profile_data_end(void);
54const char *__llvm_profile_names_begin(void);
55const char *__llvm_profile_names_end(void);
56uint64_t *__llvm_profile_counters_begin(void);
57uint64_t *__llvm_profile_counters_end(void);
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +000058
59#define PROFILE_RANGE_SIZE(Range) \
60 (__llvm_profile_ ## Range ## _end() - __llvm_profile_ ## Range ## _begin())
61
62/*!
63 * \brief Write instrumentation data to the current file.
64 *
65 * Writes to the file with the last name given to \a __llvm_profile_set_filename(),
66 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
67 * or if that's not set, \c "default.profdata".
68 */
69int __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 */
80void __llvm_profile_set_filename(const char *Name);
81
82/*! \brief Register to write instrumentation data to file at exit. */
83int __llvm_profile_register_write_file_atexit(void);
84
85/*! \brief Get the magic token for the file format. */
86uint64_t __llvm_profile_get_magic(void);
87
88/*! \brief Get the version of the file format. */
89uint64_t __llvm_profile_get_version(void);
90
Duncan P. N. Exon Smithf1c93612014-03-21 18:47:23 +000091#endif /* PROFILE_INSTRPROFILING_H_ */