1 /*===-- llvm-c/Remarks.h - Remarks Public C Interface -------------*- C -*-===*\
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header provides a public interface to a remark diagnostics library. *|
11 |* LLVM provides an implementation of this interface. *|
13 \*===----------------------------------------------------------------------===*/
15 #ifndef LLVM_C_REMARKS_H
16 #define LLVM_C_REMARKS_H
18 #include "llvm-c/Types.h"
24 #endif /* !defined(__cplusplus) */
27 * @defgroup LLVMCREMARKS Remarks
33 // 0 -> 1: Bitstream remarks support.
34 #define REMARKS_API_VERSION 1
37 * The type of the emitted remark.
40 LLVMRemarkTypeUnknown
,
43 LLVMRemarkTypeAnalysis
,
44 LLVMRemarkTypeAnalysisFPCommute
,
45 LLVMRemarkTypeAnalysisAliasing
,
50 * String containing a buffer and a length. The buffer is not guaranteed to be
53 * \since REMARKS_API_VERSION=0
55 typedef struct LLVMRemarkOpaqueString
*LLVMRemarkStringRef
;
58 * Returns the buffer holding the string.
60 * \since REMARKS_API_VERSION=0
62 extern const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String
);
65 * Returns the size of the string.
67 * \since REMARKS_API_VERSION=0
69 extern uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String
);
72 * DebugLoc containing File, Line and Column.
74 * \since REMARKS_API_VERSION=0
76 typedef struct LLVMRemarkOpaqueDebugLoc
*LLVMRemarkDebugLocRef
;
79 * Return the path to the source file for a debug location.
81 * \since REMARKS_API_VERSION=0
83 extern LLVMRemarkStringRef
84 LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL
);
87 * Return the line in the source file for a debug location.
89 * \since REMARKS_API_VERSION=0
91 extern uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL
);
94 * Return the column in the source file for a debug location.
96 * \since REMARKS_API_VERSION=0
98 extern uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL
);
101 * Element of the "Args" list. The key might give more information about what
102 * the semantics of the value are, e.g. "Callee" will tell you that the value
103 * is a symbol that names a function.
105 * \since REMARKS_API_VERSION=0
107 typedef struct LLVMRemarkOpaqueArg
*LLVMRemarkArgRef
;
110 * 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.
113 * \since REMARKS_API_VERSION=0
115 extern LLVMRemarkStringRef
LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg
);
118 * Returns the value of an argument. This is a string that can contain newlines.
120 * \since REMARKS_API_VERSION=0
122 extern LLVMRemarkStringRef
LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg
);
125 * Returns the debug location that is attached to the value of this argument.
127 * If there is no debug location, the return value will be `NULL`.
129 * \since REMARKS_API_VERSION=0
131 extern LLVMRemarkDebugLocRef
LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg
);
134 * A remark emitted by the compiler.
136 * \since REMARKS_API_VERSION=0
138 typedef struct LLVMRemarkOpaqueEntry
*LLVMRemarkEntryRef
;
141 * Free the resources used by the remark entry.
143 * \since REMARKS_API_VERSION=0
145 extern void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark
);
148 * The type of the remark. For example, it can allow users to only keep the
149 * missed optimizations from the compiler.
151 * \since REMARKS_API_VERSION=0
153 extern enum LLVMRemarkType
LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark
);
156 * Get the name of the pass that emitted this remark.
158 * \since REMARKS_API_VERSION=0
160 extern LLVMRemarkStringRef
161 LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark
);
164 * Get an identifier of the remark.
166 * \since REMARKS_API_VERSION=0
168 extern LLVMRemarkStringRef
169 LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark
);
172 * Get the name of the function being processed when the remark was emitted.
174 * \since REMARKS_API_VERSION=0
176 extern LLVMRemarkStringRef
177 LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark
);
180 * Returns the debug location that is attached to this remark.
182 * If there is no debug location, the return value will be `NULL`.
184 * \since REMARKS_API_VERSION=0
186 extern LLVMRemarkDebugLocRef
187 LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark
);
190 * Return the hotness of the remark.
192 * A hotness of `0` means this value is not set.
194 * \since REMARKS_API_VERSION=0
196 extern uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark
);
199 * The number of arguments the remark holds.
201 * \since REMARKS_API_VERSION=0
203 extern uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark
);
206 * Get a new iterator to iterate over a remark's argument.
208 * If there are no arguments in \p Remark, the return value will be `NULL`.
210 * The lifetime of the returned value is bound to the lifetime of \p Remark.
212 * \since REMARKS_API_VERSION=0
214 extern LLVMRemarkArgRef
LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark
);
217 * Get the next argument in \p Remark from the position of \p It.
219 * Returns `NULL` if there are no more arguments available.
221 * The lifetime of the returned value is bound to the lifetime of \p Remark.
223 * \since REMARKS_API_VERSION=0
225 extern LLVMRemarkArgRef
LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It
,
226 LLVMRemarkEntryRef Remark
);
228 typedef struct LLVMRemarkOpaqueParser
*LLVMRemarkParserRef
;
231 * Creates a remark parser that can be used to parse the buffer located in \p
232 * Buf of size \p Size bytes.
234 * \p Buf cannot be `NULL`.
236 * This function should be paired with LLVMRemarkParserDispose() to avoid
239 * \since REMARKS_API_VERSION=0
241 extern LLVMRemarkParserRef
LLVMRemarkParserCreateYAML(const void *Buf
,
245 * Creates a remark parser that can be used to parse the buffer located in \p
246 * Buf of size \p Size bytes.
248 * \p Buf cannot be `NULL`.
250 * This function should be paired with LLVMRemarkParserDispose() to avoid
253 * \since REMARKS_API_VERSION=1
255 extern LLVMRemarkParserRef
LLVMRemarkParserCreateBitstream(const void *Buf
,
259 * Returns the next remark in the file.
261 * The value pointed to by the return value needs to be disposed using a call to
262 * LLVMRemarkEntryDispose().
264 * All the entries in the returned value that are of LLVMRemarkStringRef type
265 * will become invalidated once a call to LLVMRemarkParserDispose is made.
267 * If the parser reaches the end of the buffer, the return value will be `NULL`.
269 * In the case of an error, the return value will be `NULL`, and:
271 * 1) LLVMRemarkParserHasError() will return `1`.
273 * 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error
276 * An error may occur if:
278 * 1) An argument is invalid.
280 * 2) There is a parsing error. This can occur on things like malformed YAML.
282 * 3) There is a Remark semantic error. This can occur on well-formed files with
283 * missing or extra fields.
285 * Here is a quick example of the usage:
288 * LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size);
289 * LLVMRemarkEntryRef Remark = NULL;
290 * while ((Remark = LLVMRemarkParserGetNext(Parser))) {
292 * LLVMRemarkEntryDispose(Remark); // Release memory.
294 * bool HasError = LLVMRemarkParserHasError(Parser);
295 * LLVMRemarkParserDispose(Parser);
298 * \since REMARKS_API_VERSION=0
300 extern LLVMRemarkEntryRef
LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser
);
303 * Returns `1` if the parser encountered an error while parsing the buffer.
305 * \since REMARKS_API_VERSION=0
307 extern LLVMBool
LLVMRemarkParserHasError(LLVMRemarkParserRef Parser
);
310 * Returns a null-terminated string containing an error message.
312 * In case of no error, the result is `NULL`.
314 * The memory of the string is bound to the lifetime of \p Parser. If
315 * LLVMRemarkParserDispose() is called, the memory of the string will be
318 * \since REMARKS_API_VERSION=0
320 extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser
);
323 * Releases all the resources used by \p Parser.
325 * \since REMARKS_API_VERSION=0
327 extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser
);
330 * Returns the version of the remarks library.
332 * \since REMARKS_API_VERSION=0
334 extern uint32_t LLVMRemarkVersion(void);
337 * @} // endgoup LLVMCREMARKS
342 #endif /* !defined(__cplusplus) */
344 #endif /* LLVM_C_REMARKS_H */