1 /*===- InstrProfiling.h- Support library for PGO instrumentation ----------===*\
3 |* The LLVM Compiler Infrastructure
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
8 \*===----------------------------------------------------------------------===*/
10 #ifndef PROFILE_INSTRPROFILING_H_
11 #define PROFILE_INSTRPROFILING_H_
13 #include "InstrProfilingPort.h"
14 #include "InstrProfData.inc"
17 #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
18 #include "InstrProfData.inc"
21 typedef void *IntPtrT;
22 typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT)
24 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
25 #include "InstrProfData.inc"
26 } __llvm_profile_data;
28 typedef struct __llvm_profile_header {
29 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name;
30 #include "InstrProfData.inc"
31 } __llvm_profile_header;
34 * \brief Get number of bytes necessary to pad the argument to eight
37 uint8_t __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes);
40 * \brief Get required size for profile buffer.
42 uint64_t __llvm_profile_get_size_for_buffer(void);
45 * \brief Write instrumentation data to the given buffer.
47 * \pre \c Buffer is the start of a buffer at least as big as \a
48 * __llvm_profile_get_size_for_buffer().
50 int __llvm_profile_write_buffer(char *Buffer);
52 const __llvm_profile_data *__llvm_profile_begin_data(void);
53 const __llvm_profile_data *__llvm_profile_end_data(void);
54 const char *__llvm_profile_begin_names(void);
55 const char *__llvm_profile_end_names(void);
56 uint64_t *__llvm_profile_begin_counters(void);
57 uint64_t *__llvm_profile_end_counters(void);
60 * \brief Clear profile counters to zero.
63 void __llvm_profile_reset_counters(void);
66 * \brief Counts the number of times a target value is seen.
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);
73 void INSTR_PROF_VALUE_PROF_FUNC(
74 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName
75 #include "InstrProfData.inc"
79 * \brief Prepares the value profiling data for output.
81 * Returns an array of pointers to value profile data.
84 struct ValueProfData **__llvm_profile_gather_value_data(uint64_t *Size);
87 * \brief Write instrumentation data to the current file.
89 * Writes to the file with the last name given to \a *
90 * __llvm_profile_set_filename(),
91 * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
92 * or if that's not set, the last name given to
93 * \a __llvm_profile_override_default_filename(), or if that's not set,
94 * \c "default.profraw".
96 int __llvm_profile_write_file(void);
99 * \brief Set the filename for writing instrumentation data.
101 * Sets the filename to be used for subsequent calls to
102 * \a __llvm_profile_write_file().
104 * \c Name is not copied, so it must remain valid. Passing NULL resets the
105 * filename logic to the default behaviour.
107 void __llvm_profile_set_filename(const char *Name);
110 * \brief Set the filename for writing instrumentation data, unless the
111 * \c LLVM_PROFILE_FILE environment variable was set.
113 * Unless overridden, sets the filename to be used for subsequent calls to
114 * \a __llvm_profile_write_file().
116 * \c Name is not copied, so it must remain valid. Passing NULL resets the
117 * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE
118 * was set in which case it has no effect).
120 void __llvm_profile_override_default_filename(const char *Name);
122 /*! \brief Register to write instrumentation data to file at exit. */
123 int __llvm_profile_register_write_file_atexit(void);
125 /*! \brief Initialize file handling. */
126 void __llvm_profile_initialize_file(void);
128 /*! \brief Get the magic token for the file format. */
129 uint64_t __llvm_profile_get_magic(void);
131 /*! \brief Get the version of the file format. */
132 uint64_t __llvm_profile_get_version(void);
134 #endif /* PROFILE_INSTRPROFILING_H_ */