LLVM 22.0.0git
Remarks.h
Go to the documentation of this file.
1/*===-- llvm-c/Remarks.h - Remarks Public C Interface -------------*- C -*-===*\
2|* *|
3|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4|* Exceptions. *|
5|* See https://llvm.org/LICENSE.txt for license information. *|
6|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public interface to a remark diagnostics library. *|
11|* LLVM provides an implementation of this interface. *|
12|* *|
13\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_C_REMARKS_H
16#define LLVM_C_REMARKS_H
17
18#include "llvm-c/ExternC.h"
19#include "llvm-c/Types.h"
20#include "llvm-c/Visibility.h"
21#ifdef __cplusplus
22#include <cstddef>
23#else
24#include <stddef.h>
25#endif /* !defined(__cplusplus) */
26
28
29/**
30 * @defgroup LLVMCREMARKS Remarks
31 * @ingroup LLVMC
32 *
33 * @{
34 */
35
36// 0 -> 1: Bitstream remarks support.
37#define REMARKS_API_VERSION 1
38
39/**
40 * The type of the emitted remark.
41 */
50};
51
52/**
53 * String containing a buffer and a length. The buffer is not guaranteed to be
54 * zero-terminated.
55 *
56 * \since REMARKS_API_VERSION=0
57 */
58typedef struct LLVMRemarkOpaqueString *LLVMRemarkStringRef;
59
60/**
61 * Returns the buffer holding the string.
62 *
63 * \since REMARKS_API_VERSION=0
64 */
65LLVM_C_ABI extern const char *
67
68/**
69 * Returns the size of the string.
70 *
71 * \since REMARKS_API_VERSION=0
72 */
74
75/**
76 * DebugLoc containing File, Line and Column.
77 *
78 * \since REMARKS_API_VERSION=0
79 */
80typedef struct LLVMRemarkOpaqueDebugLoc *LLVMRemarkDebugLocRef;
81
82/**
83 * Return the path to the source file for a debug location.
84 *
85 * \since REMARKS_API_VERSION=0
86 */
89
90/**
91 * Return the line in the source file for a debug location.
92 *
93 * \since REMARKS_API_VERSION=0
94 */
97
98/**
99 * Return the column in the source file for a debug location.
100 *
101 * \since REMARKS_API_VERSION=0
102 */
103LLVM_C_ABI extern uint32_t
105
106/**
107 * Element of the "Args" list. The key might give more information about what
108 * the semantics of the value are, e.g. "Callee" will tell you that the value
109 * is a symbol that names a function.
110 *
111 * \since REMARKS_API_VERSION=0
112 */
113typedef struct LLVMRemarkOpaqueArg *LLVMRemarkArgRef;
114
115/**
116 * Returns the key of an argument. The key defines what the value is, and the
117 * same key can appear multiple times in the list of arguments.
118 *
119 * \since REMARKS_API_VERSION=0
120 */
122
123/**
124 * Returns the value of an argument. This is a string that can contain newlines.
125 *
126 * \since REMARKS_API_VERSION=0
127 */
130
131/**
132 * Returns the debug location that is attached to the value of this argument.
133 *
134 * If there is no debug location, the return value will be `NULL`.
135 *
136 * \since REMARKS_API_VERSION=0
137 */
140
141/**
142 * A remark emitted by the compiler.
143 *
144 * \since REMARKS_API_VERSION=0
145 */
146typedef struct LLVMRemarkOpaqueEntry *LLVMRemarkEntryRef;
147
148/**
149 * Free the resources used by the remark entry.
150 *
151 * \since REMARKS_API_VERSION=0
152 */
154
155/**
156 * The type of the remark. For example, it can allow users to only keep the
157 * missed optimizations from the compiler.
158 *
159 * \since REMARKS_API_VERSION=0
160 */
161LLVM_C_ABI extern enum LLVMRemarkType
163
164/**
165 * Get the name of the pass that emitted this remark.
166 *
167 * \since REMARKS_API_VERSION=0
168 */
171
172/**
173 * Get an identifier of the remark.
174 *
175 * \since REMARKS_API_VERSION=0
176 */
179
180/**
181 * Get the name of the function being processed when the remark was emitted.
182 *
183 * \since REMARKS_API_VERSION=0
184 */
187
188/**
189 * Returns the debug location that is attached to this remark.
190 *
191 * If there is no debug location, the return value will be `NULL`.
192 *
193 * \since REMARKS_API_VERSION=0
194 */
197
198/**
199 * Return the hotness of the remark.
200 *
201 * A hotness of `0` means this value is not set.
202 *
203 * \since REMARKS_API_VERSION=0
204 */
206
207/**
208 * The number of arguments the remark holds.
209 *
210 * \since REMARKS_API_VERSION=0
211 */
213
214/**
215 * Get a new iterator to iterate over a remark's argument.
216 *
217 * If there are no arguments in \p Remark, the return value will be `NULL`.
218 *
219 * The lifetime of the returned value is bound to the lifetime of \p Remark.
220 *
221 * \since REMARKS_API_VERSION=0
222 */
225
226/**
227 * Get the next argument in \p Remark from the position of \p It.
228 *
229 * Returns `NULL` if there are no more arguments available.
230 *
231 * The lifetime of the returned value is bound to the lifetime of \p Remark.
232 *
233 * \since REMARKS_API_VERSION=0
234 */
237
238typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef;
239
240/**
241 * Creates a remark parser that can be used to parse the buffer located in \p
242 * Buf of size \p Size bytes.
243 *
244 * \p Buf cannot be `NULL`.
245 *
246 * This function should be paired with LLVMRemarkParserDispose() to avoid
247 * leaking resources.
248 *
249 * \since REMARKS_API_VERSION=0
250 */
253
254/**
255 * Creates a remark parser that can be used to parse the buffer located in \p
256 * Buf of size \p Size bytes.
257 *
258 * \p Buf cannot be `NULL`.
259 *
260 * This function should be paired with LLVMRemarkParserDispose() to avoid
261 * leaking resources.
262 *
263 * \since REMARKS_API_VERSION=1
264 */
267
268/**
269 * Returns the next remark in the file.
270 *
271 * The value pointed to by the return value needs to be disposed using a call to
272 * LLVMRemarkEntryDispose().
273 *
274 * All the entries in the returned value that are of LLVMRemarkStringRef type
275 * will become invalidated once a call to LLVMRemarkParserDispose is made.
276 *
277 * If the parser reaches the end of the buffer, the return value will be `NULL`.
278 *
279 * In the case of an error, the return value will be `NULL`, and:
280 *
281 * 1) LLVMRemarkParserHasError() will return `1`.
282 *
283 * 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error
284 * message.
285 *
286 * An error may occur if:
287 *
288 * 1) An argument is invalid.
289 *
290 * 2) There is a parsing error. This can occur on things like malformed YAML.
291 *
292 * 3) There is a Remark semantic error. This can occur on well-formed files with
293 * missing or extra fields.
294 *
295 * Here is a quick example of the usage:
296 *
297 * ```
298 * LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size);
299 * LLVMRemarkEntryRef Remark = NULL;
300 * while ((Remark = LLVMRemarkParserGetNext(Parser))) {
301 * // use Remark
302 * LLVMRemarkEntryDispose(Remark); // Release memory.
303 * }
304 * bool HasError = LLVMRemarkParserHasError(Parser);
305 * LLVMRemarkParserDispose(Parser);
306 * ```
307 *
308 * \since REMARKS_API_VERSION=0
309 */
312
313/**
314 * Returns `1` if the parser encountered an error while parsing the buffer.
315 *
316 * \since REMARKS_API_VERSION=0
317 */
319
320/**
321 * Returns a null-terminated string containing an error message.
322 *
323 * In case of no error, the result is `NULL`.
324 *
325 * The memory of the string is bound to the lifetime of \p Parser. If
326 * LLVMRemarkParserDispose() is called, the memory of the string will be
327 * released.
328 *
329 * \since REMARKS_API_VERSION=0
330 */
331LLVM_C_ABI extern const char *
333
334/**
335 * Releases all the resources used by \p Parser.
336 *
337 * \since REMARKS_API_VERSION=0
338 */
340
341/**
342 * Returns the version of the remarks library.
343 *
344 * \since REMARKS_API_VERSION=0
345 */
347
348/**
349 * @} // endgoup LLVMCREMARKS
350 */
351
353
354#endif /* LLVM_C_REMARKS_H */
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
uint64_t Size
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
#define LLVM_C_ABI
LLVM_C_ABI is the export/visibility macro used to mark symbols declared in llvm-c as exported when bu...
Definition: Visibility.h:40
uint32_t LLVMRemarkVersion(void)
Returns the version of the remarks library.
LLVM_C_ABI LLVMRemarkEntryRef LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser)
Returns the next remark in the file.
LLVM_C_ABI LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It, LLVMRemarkEntryRef Remark)
Get the next argument in Remark from the position of It.
Definition: Remark.cpp:158
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg)
Returns the value of an argument.
Definition: Remark.cpp:95
struct LLVMRemarkOpaqueEntry * LLVMRemarkEntryRef
A remark emitted by the compiler.
Definition: Remarks.h:146
LLVM_C_ABI uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String)
Returns the size of the string.
Definition: Remark.cpp:73
LLVM_C_ABI const char * LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser)
Returns a null-terminated string containing an error message.
LLVMRemarkType
The type of the emitted remark.
Definition: Remarks.h:42
struct LLVMRemarkOpaqueString * LLVMRemarkStringRef
String containing a buffer and a length.
Definition: Remarks.h:58
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark)
Get the name of the function being processed when the remark was emitted.
Definition: Remark.cpp:126
LLVM_C_ABI const char * LLVMRemarkStringGetData(LLVMRemarkStringRef String)
Returns the buffer holding the string.
Definition: Remark.cpp:69
LLVM_C_ABI LLVMRemarkDebugLocRef LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark)
Returns the debug location that is attached to this remark.
Definition: Remark.cpp:131
LLVM_C_ABI LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg)
Returns the debug location that is attached to the value of this argument.
Definition: Remark.cpp:100
LLVM_C_ABI uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL)
Return the column in the source file for a debug location.
Definition: Remark.cpp:87
struct LLVMRemarkOpaqueArg * LLVMRemarkArgRef
Element of the "Args" list.
Definition: Remarks.h:113
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark)
Get the name of the pass that emitted this remark.
Definition: Remark.cpp:116
LLVM_C_ABI void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser)
Releases all the resources used by Parser.
LLVM_C_ABI uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark)
The number of arguments the remark holds.
Definition: Remark.cpp:143
LLVM_C_ABI LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf, uint64_t Size)
Creates a remark parser that can be used to parse the buffer located in Buf of size Size bytes.
struct LLVMRemarkOpaqueParser * LLVMRemarkParserRef
Definition: Remarks.h:238
LLVM_C_ABI void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark)
Free the resources used by the remark entry.
Definition: Remark.cpp:106
LLVM_C_ABI LLVMRemarkParserRef LLVMRemarkParserCreateBitstream(const void *Buf, uint64_t Size)
Creates a remark parser that can be used to parse the buffer located in Buf of size Size bytes.
LLVM_C_ABI enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark)
The type of the remark.
Definition: Remark.cpp:110
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg)
Returns the key of an argument.
Definition: Remark.cpp:91
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark)
Get an identifier of the remark.
Definition: Remark.cpp:121
LLVM_C_ABI uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark)
Return the hotness of the remark.
Definition: Remark.cpp:137
struct LLVMRemarkOpaqueDebugLoc * LLVMRemarkDebugLocRef
DebugLoc containing File, Line and Column.
Definition: Remarks.h:80
LLVM_C_ABI LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser)
Returns 1 if the parser encountered an error while parsing the buffer.
LLVM_C_ABI LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark)
Get a new iterator to iterate over a remark's argument.
Definition: Remark.cpp:148
LLVM_C_ABI LLVMRemarkStringRef LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL)
Return the path to the source file for a debug location.
Definition: Remark.cpp:78
LLVM_C_ABI uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL)
Return the line in the source file for a debug location.
Definition: Remark.cpp:82
@ LLVMRemarkTypeAnalysisFPCommute
Definition: Remarks.h:47
@ LLVMRemarkTypeAnalysisAliasing
Definition: Remarks.h:48
@ LLVMRemarkTypePassed
Definition: Remarks.h:44
@ LLVMRemarkTypeUnknown
Definition: Remarks.h:43
@ LLVMRemarkTypeFailure
Definition: Remarks.h:49
@ LLVMRemarkTypeAnalysis
Definition: Remarks.h:46
@ LLVMRemarkTypeMissed
Definition: Remarks.h:45
int LLVMBool
Definition: Types.h:28