blob: e57ca3cd8f50597d04d1b02e3e7077e65bbc6c79 [file] [log] [blame]
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +00001/*===-- 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/Core.h"
19#include "llvm-c/Types.h"
20#ifdef __cplusplus
21#include <cstddef>
22extern "C" {
23#else
24#include <stddef.h>
25#endif /* !defined(__cplusplus) */
26
27/**
28 * @defgroup LLVMCREMARKS Remarks
29 * @ingroup LLVMC
30 *
31 * @{
32 */
33
34#define REMARKS_API_VERSION 0
35
36/**
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +000037 * The type of the emitted remark.
38 */
39enum LLVMRemarkType {
40 LLVMRemarkTypeUnknown,
41 LLVMRemarkTypePassed,
42 LLVMRemarkTypeMissed,
43 LLVMRemarkTypeAnalysis,
44 LLVMRemarkTypeAnalysisFPCommute,
45 LLVMRemarkTypeAnalysisAliasing,
46 LLVMRemarkTypeFailure
47};
48
49/**
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +000050 * String containing a buffer and a length. The buffer is not guaranteed to be
51 * zero-terminated.
52 *
53 * \since REMARKS_API_VERSION=0
54 */
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +000055typedef struct LLVMRemarkOpaqueString *LLVMRemarkStringRef;
56
57/**
58 * Returns the buffer holding the string.
59 *
60 * \since REMARKS_API_VERSION=0
61 */
62extern const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String);
63
64/**
65 * Returns the size of the string.
66 *
67 * \since REMARKS_API_VERSION=0
68 */
69extern uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String);
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +000070
71/**
72 * DebugLoc containing File, Line and Column.
73 *
74 * \since REMARKS_API_VERSION=0
75 */
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +000076typedef struct LLVMRemarkOpaqueDebugLoc *LLVMRemarkDebugLocRef;
77
78/**
79 * Return the path to the source file for a debug location.
80 *
81 * \since REMARKS_API_VERSION=0
82 */
83extern LLVMRemarkStringRef
84LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL);
85
86/**
87 * Return the line in the source file for a debug location.
88 *
89 * \since REMARKS_API_VERSION=0
90 */
91extern uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL);
92
93/**
94 * Return the column in the source file for a debug location.
95 *
96 * \since REMARKS_API_VERSION=0
97 */
98extern uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL);
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +000099
100/**
101 * Element of the "Args" list. The key might give more information about what
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000102 * the semantics of the value are, e.g. "Callee" will tell you that the value
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000103 * is a symbol that names a function.
104 *
105 * \since REMARKS_API_VERSION=0
106 */
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000107typedef struct LLVMRemarkOpaqueArg *LLVMRemarkArgRef;
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000108
109/**
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000110 * Returns the key of an argument. The key defines what the value is, and the
111 * same key can appear multiple times in the list of arguments.
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000112 *
113 * \since REMARKS_API_VERSION=0
114 */
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000115extern LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg);
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000116
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000117/**
118 * Returns the value of an argument. This is a string that can contain newlines.
119 *
120 * \since REMARKS_API_VERSION=0
121 */
122extern LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg);
123
124/**
125 * Returns the debug location that is attached to the value of this argument.
126 *
127 * If there is no debug location, the return value will be `NULL`.
128 *
129 * \since REMARKS_API_VERSION=0
130 */
131extern LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg);
132
133/**
134 * A remark emitted by the compiler.
135 *
136 * \since REMARKS_API_VERSION=0
137 */
138typedef struct LLVMRemarkOpaqueEntry *LLVMRemarkEntryRef;
139
140/**
141 * The type of the remark. For example, it can allow users to only keep the
142 * missed optimizations from the compiler.
143 *
144 * \since REMARKS_API_VERSION=0
145 */
146extern enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark);
147
148/**
149 * Get the name of the pass that emitted this remark.
150 *
151 * \since REMARKS_API_VERSION=0
152 */
153extern LLVMRemarkStringRef
154LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark);
155
156/**
157 * Get an identifier of the remark.
158 *
159 * \since REMARKS_API_VERSION=0
160 */
161extern LLVMRemarkStringRef
162LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark);
163
164/**
165 * Get the name of the function being processsed when the remark was emitted.
166 *
167 * \since REMARKS_API_VERSION=0
168 */
169extern LLVMRemarkStringRef
170LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark);
171
172/**
173 * Returns the debug location that is attached to this remark.
174 *
175 * If there is no debug location, the return value will be `NULL`.
176 *
177 * \since REMARKS_API_VERSION=0
178 */
179extern LLVMRemarkDebugLocRef
180LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark);
181
182/**
183 * Return the hotness of the remark.
184 *
185 * A hotness of `0` means this value is not set.
186 *
187 * \since REMARKS_API_VERSION=0
188 */
189extern uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark);
190
191/**
192 * The number of arguments the remark holds.
193 *
194 * \since REMARKS_API_VERSION=0
195 */
196extern uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark);
197
198/**
199 * Get a new iterator to iterate over a remark's argument.
200 *
201 * If there are no arguments in \p Remark, the return value will be `NULL`.
202 *
203 * \since REMARKS_API_VERSION=0
204 */
205extern LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark);
206
207/**
208 * Get the next argument in \p Remark from the position of \p It.
209 *
210 * Returns `NULL` if there are no more arguments available.
211 *
212 * \since REMARKS_API_VERSION=0
213 */
214extern LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It,
215 LLVMRemarkEntryRef Remark);
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000216
217typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef;
218
219/**
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000220 * Creates a remark parser that can be used to parse the buffer located in \p
221 * Buf of size \p Size bytes.
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000222 *
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000223 * \p Buf cannot be `NULL`.
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000224 *
225 * This function should be paired with LLVMRemarkParserDispose() to avoid
226 * leaking resources.
227 *
228 * \since REMARKS_API_VERSION=0
229 */
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000230extern LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf,
231 uint64_t Size);
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000232
233/**
234 * Returns the next remark in the file.
235 *
236 * The value pointed to by the return value is invalidated by the next call to
237 * LLVMRemarkParserGetNext().
238 *
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000239 * If the parser reaches the end of the buffer, the return value will be `NULL`.
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000240 *
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000241 * In the case of an error, the return value will be `NULL`, and:
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000242 *
243 * 1) LLVMRemarkParserHasError() will return `1`.
244 *
245 * 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error
246 * message.
247 *
248 * An error may occur if:
249 *
250 * 1) An argument is invalid.
251 *
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000252 * 2) There is a parsing error. This can occur on things like malformed YAML.
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000253 *
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000254 * 3) There is a Remark semantic error. This can occur on well-formed files with
255 * missing or extra fields.
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000256 *
257 * Here is a quick example of the usage:
258 *
259 * ```
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000260 * LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size);
261 * LLVMRemarkEntryRef Remark = NULL;
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000262 * while ((Remark == LLVMRemarkParserGetNext(Parser))) {
263 * // use Remark
264 * }
265 * bool HasError = LLVMRemarkParserHasError(Parser);
266 * LLVMRemarkParserDispose(Parser);
267 * ```
268 *
269 * \since REMARKS_API_VERSION=0
270 */
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000271extern LLVMRemarkEntryRef LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser);
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000272
273/**
274 * Returns `1` if the parser encountered an error while parsing the buffer.
275 *
276 * \since REMARKS_API_VERSION=0
277 */
278extern LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser);
279
280/**
281 * Returns a null-terminated string containing an error message.
282 *
283 * In case of no error, the result is `NULL`.
284 *
285 * The memory of the string is bound to the lifetime of \p Parser. If
286 * LLVMRemarkParserDispose() is called, the memory of the string will be
287 * released.
288 *
289 * \since REMARKS_API_VERSION=0
290 */
291extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser);
292
293/**
294 * Releases all the resources used by \p Parser.
295 *
296 * \since REMARKS_API_VERSION=0
297 */
298extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser);
299
300/**
Francis Visoiu Mistrih5a05cc02019-03-19 21:11:07 +0000301 * Returns the version of the remarks library.
Francis Visoiu Mistrih1c4bab32019-03-05 20:45:17 +0000302 *
303 * \since REMARKS_API_VERSION=0
304 */
305extern uint32_t LLVMRemarkVersion(void);
306
307/**
308 * @} // endgoup LLVMCREMARKS
309 */
310
311#ifdef __cplusplus
312}
313#endif /* !defined(__cplusplus) */
314
315#endif /* LLVM_C_REMARKS_H */