blob: 5b1a91ea2a0d61733589217d1d03b8cc8d99eba7 [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
Xinliang David Li26bcd192015-12-10 18:17:01 +000013#include "InstrProfilingPort.h"
Xinliang David Li0ca5bd42015-11-23 17:09:40 +000014#include "InstrProfData.inc"
15
Xinliang David Li78c4a442015-11-20 19:41:02 +000016enum ValueKind {
Xinliang David Li5c7fa272015-11-23 17:43:10 +000017#define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
18#include "InstrProfData.inc"
Xinliang David Li78c4a442015-11-20 19:41:02 +000019};
Duncan P. N. Exon Smith812dcae2014-03-21 18:29:24 +000020
Xinliang David Li78c4a442015-11-20 19:41:02 +000021typedef void *IntPtrT;
Xinliang David Liabfd5532015-12-16 03:29:15 +000022typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT)
23 __llvm_profile_data {
Xinliang David Lia1bebf22015-11-23 17:50:53 +000024#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
25#include "InstrProfData.inc"
Duncan P. N. Exon Smith9edbae02014-03-20 20:00:44 +000026} __llvm_profile_data;
Duncan P. N. Exon Smith8353a262014-03-19 22:10:27 +000027
Xinliang David Li4da5de92015-10-16 22:21:56 +000028typedef struct __llvm_profile_header {
Xinliang David Li6376db52015-11-23 18:36:40 +000029#define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name;
30#include "InstrProfData.inc"
Xinliang David Li4da5de92015-10-16 22:21:56 +000031} __llvm_profile_header;
32
Betul Buyukkurt808385f2015-11-18 18:12:35 +000033/*!
34 * \brief Get number of bytes necessary to pad the argument to eight
35 * byte boundary.
36 */
37uint8_t __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes);
Xinliang David Li4da5de92015-10-16 22:21:56 +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
Justin Bognercc0d7ee2014-09-04 15:45:31 +000052const __llvm_profile_data *__llvm_profile_begin_data(void);
53const __llvm_profile_data *__llvm_profile_end_data(void);
54const char *__llvm_profile_begin_names(void);
55const char *__llvm_profile_end_names(void);
56uint64_t *__llvm_profile_begin_counters(void);
57uint64_t *__llvm_profile_end_counters(void);
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +000058
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +000059/*!
Xinliang David Lic5c32cb2015-11-18 21:54:40 +000060 * \brief Clear profile counters to zero.
61 *
62 */
63void __llvm_profile_reset_counters(void);
64
65/*!
Xinliang David Li31f251f2016-03-04 18:58:30 +000066 * \brief Merge profile data from buffer.
67 *
68 * Read profile data form buffer \p Profile and merge with
Xinliang David Lidd12e9a2016-03-03 18:54:46 +000069 * in-process profile counters. The client is expected to
70 * have checked or already knows the profile data in the
71 * buffer matches the in-process counter structure before
72 * calling it.
73 */
74void __llvm_profile_merge_from_buffer(const char *Profile, uint64_t Size);
75
Xinliang David Li31f251f2016-03-04 18:58:30 +000076/*! \brief Check if profile in buffer matches the current binary.
77 *
78 * Returns 0 (success) if the profile data in buffer \p Profile with size
79 * \p Size was generated by the same binary and therefore matches
80 * structurally the in-process counters. If the profile data in buffer is
81 * not compatible, the interface returns 1 (failure).
82 */
83int __llvm_profile_check_compatibility(const char *Profile,
84 uint64_t Size);
85
Xinliang David Lidd12e9a2016-03-03 18:54:46 +000086/*!
Betul Buyukkurt808385f2015-11-18 18:12:35 +000087 * \brief Counts the number of times a target value is seen.
88 *
89 * Records the target value for the CounterIndex if not seen before. Otherwise,
90 * increments the counter associated w/ the target value.
Xinliang David Li39f4c2c2015-11-23 20:07:09 +000091 * void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
92 * uint32_t CounterIndex);
Betul Buyukkurt808385f2015-11-18 18:12:35 +000093 */
Xinliang David Li39f4c2c2015-11-23 20:07:09 +000094void INSTR_PROF_VALUE_PROF_FUNC(
95#define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName
96#include "InstrProfData.inc"
Xinliang David Lie9a8574d2016-05-10 00:17:31 +000097 );
Betul Buyukkurt808385f2015-11-18 18:12:35 +000098
99/*!
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +0000100 * \brief Write instrumentation data to the current file.
101 *
Xinliang David Li54dd6832015-12-29 07:13:59 +0000102 * Writes to the file with the last name given to \a *
103 * __llvm_profile_set_filename(),
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +0000104 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
Eric Christopherd641b532015-04-28 22:54:51 +0000105 * or if that's not set, the last name given to
106 * \a __llvm_profile_override_default_filename(), or if that's not set,
Diego Novilloeae95142015-07-09 17:21:52 +0000107 * \c "default.profraw".
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +0000108 */
109int __llvm_profile_write_file(void);
110
111/*!
112 * \brief Set the filename for writing instrumentation data.
113 *
114 * Sets the filename to be used for subsequent calls to
115 * \a __llvm_profile_write_file().
116 *
117 * \c Name is not copied, so it must remain valid. Passing NULL resets the
118 * filename logic to the default behaviour.
119 */
120void __llvm_profile_set_filename(const char *Name);
121
Eric Christopherd641b532015-04-28 22:54:51 +0000122/*!
123 * \brief Set the filename for writing instrumentation data, unless the
124 * \c LLVM_PROFILE_FILE environment variable was set.
125 *
126 * Unless overridden, sets the filename to be used for subsequent calls to
127 * \a __llvm_profile_write_file().
128 *
129 * \c Name is not copied, so it must remain valid. Passing NULL resets the
130 * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE
131 * was set in which case it has no effect).
132 */
133void __llvm_profile_override_default_filename(const char *Name);
134
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +0000135/*! \brief Register to write instrumentation data to file at exit. */
136int __llvm_profile_register_write_file_atexit(void);
137
Duncan P. N. Exon Smith55e4d662014-05-17 01:27:30 +0000138/*! \brief Initialize file handling. */
139void __llvm_profile_initialize_file(void);
Duncan P. N. Exon Smith08439882014-05-16 01:30:24 +0000140
Duncan P. N. Exon Smithbe0a5e12014-03-21 18:29:15 +0000141/*! \brief Get the magic token for the file format. */
142uint64_t __llvm_profile_get_magic(void);
143
144/*! \brief Get the version of the file format. */
145uint64_t __llvm_profile_get_version(void);
146
Vedant Kumarb8502512016-02-26 02:49:41 +0000147/*! \brief Get the number of entries in the profile data section. */
148uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
149 const __llvm_profile_data *End);
150
Duncan P. N. Exon Smithf1c93612014-03-21 18:47:23 +0000151#endif /* PROFILE_INSTRPROFILING_H_ */