]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/lib/profile/InstrProfilingInternal.h
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / lib / profile / InstrProfilingInternal.h
CommitLineData
92a42be0
SL
1/*===- 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_INTERNALH_
11#define PROFILE_INSTRPROFILING_INTERNALH_
12
13#include "InstrProfiling.h"
3157f602 14#include "stddef.h"
92a42be0
SL
15
16/*!
17 * \brief Write instrumentation data to the given buffer, given explicit
18 * pointers to the live data in memory. This function is probably not what you
19 * want. Use __llvm_profile_get_size_for_buffer instead. Use this function if
20 * your program has a custom memory layout.
21 */
22uint64_t __llvm_profile_get_size_for_buffer_internal(
23 const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd,
24 const uint64_t *CountersBegin, const uint64_t *CountersEnd,
25 const char *NamesBegin, const char *NamesEnd);
26
27/*!
28 * \brief Write instrumentation data to the given buffer, given explicit
29 * pointers to the live data in memory. This function is probably not what you
30 * want. Use __llvm_profile_write_buffer instead. Use this function if your
31 * program has a custom memory layout.
32 *
33 * \pre \c Buffer is the start of a buffer at least as big as \a
34 * __llvm_profile_get_size_for_buffer_internal().
35 */
36int __llvm_profile_write_buffer_internal(
37 char *Buffer, const __llvm_profile_data *DataBegin,
38 const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin,
39 const uint64_t *CountersEnd, const char *NamesBegin, const char *NamesEnd);
40
3157f602
XL
41/*!
42 * The data structure describing the data to be written by the
43 * low level writer callback function.
44 */
45typedef struct ProfDataIOVec {
46 const void *Data;
47 size_t ElmSize;
48 size_t NumElm;
49} ProfDataIOVec;
50
51typedef uint32_t (*WriterCallback)(ProfDataIOVec *, uint32_t NumIOVecs,
52 void **WriterCtx);
53
54/*!
55 * The data structure for buffered IO of profile data.
56 */
57typedef struct ProfBufferIO {
58 /* File handle. */
59 void *File;
60 /* Low level IO callback. */
61 WriterCallback FileWriter;
62 /* The start of the buffer. */
63 uint8_t *BufferStart;
64 /* Total size of the buffer. */
65 uint32_t BufferSz;
66 /* Current byte offset from the start of the buffer. */
67 uint32_t CurOffset;
68} ProfBufferIO;
69
70/* The creator interface used by testing. */
5bcae85e
SL
71ProfBufferIO *lprofCreateBufferIOInternal(void *File, uint32_t BufferSz);
72
3157f602
XL
73/*!
74 * This is the interface to create a handle for buffered IO.
75 */
5bcae85e
SL
76ProfBufferIO *lprofCreateBufferIO(WriterCallback FileWriter, void *File);
77
3157f602
XL
78/*!
79 * The interface to destroy the bufferIO handle and reclaim
80 * the memory.
81 */
5bcae85e 82void lprofDeleteBufferIO(ProfBufferIO *BufferIO);
3157f602
XL
83
84/*!
85 * This is the interface to write \c Data of \c Size bytes through
86 * \c BufferIO. Returns 0 if successful, otherwise return -1.
87 */
5bcae85e
SL
88int lprofBufferIOWrite(ProfBufferIO *BufferIO, const uint8_t *Data,
89 uint32_t Size);
3157f602
XL
90/*!
91 * The interface to flush the remaining data in the buffer.
92 * through the low level writer callback.
93 */
5bcae85e 94int lprofBufferIOFlush(ProfBufferIO *BufferIO);
3157f602
XL
95
96/* The low level interface to write data into a buffer. It is used as the
97 * callback by other high level writer methods such as buffered IO writer
98 * and profile data writer. */
5bcae85e
SL
99uint32_t lprofBufferWriter(ProfDataIOVec *IOVecs, uint32_t NumIOVecs,
100 void **WriterCtx);
101
102struct ValueProfData;
103struct ValueProfRecord;
104struct InstrProfValueData;
105struct ValueProfNode;
106
107/*!
108 * The class that defines a set of methods to read value profile
109 * data for streaming/serialization from the instrumentation runtime.
110 */
111typedef struct VPDataReaderType {
112 uint32_t (*InitRTRecord)(const __llvm_profile_data *Data,
113 uint8_t *SiteCountArray[]);
114 /* Function pointer to getValueProfRecordHeader method. */
115 uint32_t (*GetValueProfRecordHeaderSize)(uint32_t NumSites);
116 /* Function pointer to getFristValueProfRecord method. */
117 struct ValueProfRecord *(*GetFirstValueProfRecord)(struct ValueProfData *);
118 /* Return the number of value data for site \p Site. */
119 uint32_t (*GetNumValueDataForSite)(uint32_t VK, uint32_t Site);
120 /* Return the total size of the value profile data of the
121 * current function. */
122 uint32_t (*GetValueProfDataSize)(void);
123 /*!
124 * Read the next \p N value data for site \p Site and store the data
125 * in \p Dst. \p StartNode is the first value node to start with if
126 * it is not null. The function returns the pointer to the value
127 * node pointer to be used as the \p StartNode of the next batch reading.
128 * If there is nothing left, it returns NULL.
129 */
130 struct ValueProfNode *(*GetValueData)(uint32_t ValueKind, uint32_t Site,
131 struct InstrProfValueData *Dst,
132 struct ValueProfNode *StartNode,
133 uint32_t N);
134} VPDataReaderType;
135
136int lprofWriteData(WriterCallback Writer, void *WriterCtx,
137 VPDataReaderType *VPDataReader);
138int lprofWriteDataImpl(WriterCallback Writer, void *WriterCtx,
139 const __llvm_profile_data *DataBegin,
140 const __llvm_profile_data *DataEnd,
141 const uint64_t *CountersBegin,
142 const uint64_t *CountersEnd,
143 VPDataReaderType *VPDataReader, const char *NamesBegin,
144 const char *NamesEnd);
145
146/* Merge value profile data pointed to by SrcValueProfData into
147 * in-memory profile counters pointed by to DstData. */
148void lprofMergeValueProfData(struct ValueProfData *SrcValueProfData,
149 __llvm_profile_data *DstData);
150
151VPDataReaderType *lprofGetVPDataReader();
152
153/* Internal interface used by test to reset the max number of
154 * tracked values per value site to be \p MaxVals.
155 */
156void lprofSetMaxValsPerSite(uint32_t MaxVals);
157void lprofSetupValueProfiler();
158
159/* Return the profile header 'signature' value associated with the current
160 * executable or shared library. The signature value can be used to for
161 * a profile name that is unique to this load module so that it does not
162 * collide with profiles from other binaries. It also allows shared libraries
163 * to dump merged profile data into its own profile file. */
164uint64_t lprofGetLoadModuleSignature();
165
166/* GCOV_PREFIX and GCOV_PREFIX_STRIP support */
167/* Return the path prefix specified by GCOV_PREFIX environment variable.
168 * If GCOV_PREFIX_STRIP is also specified, the strip level (integer value)
169 * is returned via \c *PrefixStrip. The prefix length is stored in *PrefixLen.
170 */
171const char *lprofGetPathPrefix(int *PrefixStrip, size_t *PrefixLen);
172/* Apply the path prefix specified in \c Prefix to path string in \c PathStr,
173 * and store the result to buffer pointed to by \c Buffer. If \c PrefixStrip
174 * is not zero, path prefixes are stripped from \c PathStr (the level of
175 * stripping is specified by \c PrefixStrip) before \c Prefix is added.
176 */
177void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,
178 size_t PrefixLen, int PrefixStrip);
179
180COMPILER_RT_VISIBILITY extern char *(*GetEnvHook)(const char *);
181COMPILER_RT_VISIBILITY extern void (*FreeHook)(void *);
182COMPILER_RT_VISIBILITY extern uint8_t *DynamicBufferIOBuffer;
183COMPILER_RT_VISIBILITY extern uint32_t VPBufferSize;
184COMPILER_RT_VISIBILITY extern uint32_t VPMaxNumValsPerSite;
185/* Pointer to the start of static value counters to be allocted. */
186COMPILER_RT_VISIBILITY extern ValueProfNode *CurrentVNode;
187COMPILER_RT_VISIBILITY extern ValueProfNode *EndVNode;
188extern void (*VPMergeHook)(struct ValueProfData *, __llvm_profile_data *);
3157f602 189
92a42be0 190#endif