blob: c924a42f6f0789c5cdf4518ab2f7c49762c6f839 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001/*===- 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
10#ifndef PROFILE_INSTRPROFILING_H_
11#define PROFILE_INSTRPROFILING_H_
12
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080013#include "InstrProfilingPort.h"
14#include "InstrProfData.inc"
Stephen Hines2d1fdb22014-05-28 23:58:16 -070015
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080016enum ValueKind {
17#define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
18#include "InstrProfData.inc"
19};
Stephen Hines2d1fdb22014-05-28 23:58:16 -070020
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080021typedef void *IntPtrT;
22typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT)
23 __llvm_profile_data {
24#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
25#include "InstrProfData.inc"
Stephen Hines2d1fdb22014-05-28 23:58:16 -070026} __llvm_profile_data;
27
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080028typedef struct __llvm_profile_header {
29#define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name;
30#include "InstrProfData.inc"
31} __llvm_profile_header;
32
33/*!
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);
38
Stephen Hines2d1fdb22014-05-28 23:58:16 -070039/*!
40 * \brief Get required size for profile buffer.
41 */
42uint64_t __llvm_profile_get_size_for_buffer(void);
43
44/*!
45 * \brief Write instrumentation data to the given buffer.
46 *
47 * \pre \c Buffer is the start of a buffer at least as big as \a
48 * __llvm_profile_get_size_for_buffer().
49 */
50int __llvm_profile_write_buffer(char *Buffer);
51
Stephen Hines6d186232014-11-26 17:56:19 -080052const __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);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070058
Stephen Hines2d1fdb22014-05-28 23:58:16 -070059/*!
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080060 * \brief Clear profile counters to zero.
61 *
62 */
63void __llvm_profile_reset_counters(void);
64
65/*!
66 * \brief Counts the number of times a target value is seen.
67 *
68 * Records the target value for the CounterIndex if not seen before. Otherwise,
69 * increments the counter associated w/ the target value.
70 * void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
71 * uint32_t CounterIndex);
72 */
73void INSTR_PROF_VALUE_PROF_FUNC(
74#define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName
75#include "InstrProfData.inc"
76);
77
78/*!
79 * \brief Prepares the value profiling data for output.
80 *
81 * Prepares a single __llvm_profile_value_data array out of the many
82 * ValueProfNode trees (one per instrumented function).
83 */
84uint64_t __llvm_profile_gather_value_data(uint8_t **DataArray);
85
86/*!
Stephen Hines2d1fdb22014-05-28 23:58:16 -070087 * \brief Write instrumentation data to the current file.
88 *
89 * Writes to the file with the last name given to \a __llvm_profile_set_filename(),
90 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070091 * or if that's not set, the last name given to
92 * \a __llvm_profile_override_default_filename(), or if that's not set,
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080093 * \c "default.profraw".
Stephen Hines2d1fdb22014-05-28 23:58:16 -070094 */
95int __llvm_profile_write_file(void);
96
97/*!
98 * \brief Set the filename for writing instrumentation data.
99 *
100 * Sets the filename to be used for subsequent calls to
101 * \a __llvm_profile_write_file().
102 *
103 * \c Name is not copied, so it must remain valid. Passing NULL resets the
104 * filename logic to the default behaviour.
105 */
106void __llvm_profile_set_filename(const char *Name);
107
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -0700108/*!
109 * \brief Set the filename for writing instrumentation data, unless the
110 * \c LLVM_PROFILE_FILE environment variable was set.
111 *
112 * Unless overridden, sets the filename to be used for subsequent calls to
113 * \a __llvm_profile_write_file().
114 *
115 * \c Name is not copied, so it must remain valid. Passing NULL resets the
116 * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE
117 * was set in which case it has no effect).
118 */
119void __llvm_profile_override_default_filename(const char *Name);
120
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700121/*! \brief Register to write instrumentation data to file at exit. */
122int __llvm_profile_register_write_file_atexit(void);
123
124/*! \brief Initialize file handling. */
125void __llvm_profile_initialize_file(void);
126
127/*! \brief Get the magic token for the file format. */
128uint64_t __llvm_profile_get_magic(void);
129
130/*! \brief Get the version of the file format. */
131uint64_t __llvm_profile_get_version(void);
132
133#endif /* PROFILE_INSTRPROFILING_H_ */