Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / include / llvm-c / Remarks.h
blobffe647a6554aabb2132cf272b7bd8930c8ec2344
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 \*===----------------------------------------------------------------------===*/
15 #ifndef LLVM_C_REMARKS_H
16 #define LLVM_C_REMARKS_H
18 #include "llvm-c/ExternC.h"
19 #include "llvm-c/Types.h"
20 #ifdef __cplusplus
21 #include <cstddef>
22 #else
23 #include <stddef.h>
24 #endif /* !defined(__cplusplus) */
26 LLVM_C_EXTERN_C_BEGIN
28 /**
29 * @defgroup LLVMCREMARKS Remarks
30 * @ingroup LLVMC
32 * @{
35 // 0 -> 1: Bitstream remarks support.
36 #define REMARKS_API_VERSION 1
38 /**
39 * The type of the emitted remark.
41 enum LLVMRemarkType {
42 LLVMRemarkTypeUnknown,
43 LLVMRemarkTypePassed,
44 LLVMRemarkTypeMissed,
45 LLVMRemarkTypeAnalysis,
46 LLVMRemarkTypeAnalysisFPCommute,
47 LLVMRemarkTypeAnalysisAliasing,
48 LLVMRemarkTypeFailure
51 /**
52 * String containing a buffer and a length. The buffer is not guaranteed to be
53 * zero-terminated.
55 * \since REMARKS_API_VERSION=0
57 typedef struct LLVMRemarkOpaqueString *LLVMRemarkStringRef;
59 /**
60 * Returns the buffer holding the string.
62 * \since REMARKS_API_VERSION=0
64 extern const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String);
66 /**
67 * Returns the size of the string.
69 * \since REMARKS_API_VERSION=0
71 extern uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String);
73 /**
74 * DebugLoc containing File, Line and Column.
76 * \since REMARKS_API_VERSION=0
78 typedef struct LLVMRemarkOpaqueDebugLoc *LLVMRemarkDebugLocRef;
80 /**
81 * Return the path to the source file for a debug location.
83 * \since REMARKS_API_VERSION=0
85 extern LLVMRemarkStringRef
86 LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL);
88 /**
89 * Return the line in the source file for a debug location.
91 * \since REMARKS_API_VERSION=0
93 extern uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL);
95 /**
96 * Return the column in the source file for a debug location.
98 * \since REMARKS_API_VERSION=0
100 extern uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL);
103 * Element of the "Args" list. The key might give more information about what
104 * the semantics of the value are, e.g. "Callee" will tell you that the value
105 * is a symbol that names a function.
107 * \since REMARKS_API_VERSION=0
109 typedef struct LLVMRemarkOpaqueArg *LLVMRemarkArgRef;
112 * Returns the key of an argument. The key defines what the value is, and the
113 * same key can appear multiple times in the list of arguments.
115 * \since REMARKS_API_VERSION=0
117 extern LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg);
120 * Returns the value of an argument. This is a string that can contain newlines.
122 * \since REMARKS_API_VERSION=0
124 extern LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg);
127 * Returns the debug location that is attached to the value of this argument.
129 * If there is no debug location, the return value will be `NULL`.
131 * \since REMARKS_API_VERSION=0
133 extern LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg);
136 * A remark emitted by the compiler.
138 * \since REMARKS_API_VERSION=0
140 typedef struct LLVMRemarkOpaqueEntry *LLVMRemarkEntryRef;
143 * Free the resources used by the remark entry.
145 * \since REMARKS_API_VERSION=0
147 extern void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark);
150 * The type of the remark. For example, it can allow users to only keep the
151 * missed optimizations from the compiler.
153 * \since REMARKS_API_VERSION=0
155 extern enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark);
158 * Get the name of the pass that emitted this remark.
160 * \since REMARKS_API_VERSION=0
162 extern LLVMRemarkStringRef
163 LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark);
166 * Get an identifier of the remark.
168 * \since REMARKS_API_VERSION=0
170 extern LLVMRemarkStringRef
171 LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark);
174 * Get the name of the function being processed when the remark was emitted.
176 * \since REMARKS_API_VERSION=0
178 extern LLVMRemarkStringRef
179 LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark);
182 * Returns the debug location that is attached to this remark.
184 * If there is no debug location, the return value will be `NULL`.
186 * \since REMARKS_API_VERSION=0
188 extern LLVMRemarkDebugLocRef
189 LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark);
192 * Return the hotness of the remark.
194 * A hotness of `0` means this value is not set.
196 * \since REMARKS_API_VERSION=0
198 extern uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark);
201 * The number of arguments the remark holds.
203 * \since REMARKS_API_VERSION=0
205 extern uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark);
208 * Get a new iterator to iterate over a remark's argument.
210 * If there are no arguments in \p Remark, the return value will be `NULL`.
212 * The lifetime of the returned value is bound to the lifetime of \p Remark.
214 * \since REMARKS_API_VERSION=0
216 extern LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark);
219 * Get the next argument in \p Remark from the position of \p It.
221 * Returns `NULL` if there are no more arguments available.
223 * The lifetime of the returned value is bound to the lifetime of \p Remark.
225 * \since REMARKS_API_VERSION=0
227 extern LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It,
228 LLVMRemarkEntryRef Remark);
230 typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef;
233 * Creates a remark parser that can be used to parse the buffer located in \p
234 * Buf of size \p Size bytes.
236 * \p Buf cannot be `NULL`.
238 * This function should be paired with LLVMRemarkParserDispose() to avoid
239 * leaking resources.
241 * \since REMARKS_API_VERSION=0
243 extern LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf,
244 uint64_t Size);
247 * Creates a remark parser that can be used to parse the buffer located in \p
248 * Buf of size \p Size bytes.
250 * \p Buf cannot be `NULL`.
252 * This function should be paired with LLVMRemarkParserDispose() to avoid
253 * leaking resources.
255 * \since REMARKS_API_VERSION=1
257 extern LLVMRemarkParserRef LLVMRemarkParserCreateBitstream(const void *Buf,
258 uint64_t Size);
261 * Returns the next remark in the file.
263 * The value pointed to by the return value needs to be disposed using a call to
264 * LLVMRemarkEntryDispose().
266 * All the entries in the returned value that are of LLVMRemarkStringRef type
267 * will become invalidated once a call to LLVMRemarkParserDispose is made.
269 * If the parser reaches the end of the buffer, the return value will be `NULL`.
271 * In the case of an error, the return value will be `NULL`, and:
273 * 1) LLVMRemarkParserHasError() will return `1`.
275 * 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error
276 * message.
278 * An error may occur if:
280 * 1) An argument is invalid.
282 * 2) There is a parsing error. This can occur on things like malformed YAML.
284 * 3) There is a Remark semantic error. This can occur on well-formed files with
285 * missing or extra fields.
287 * Here is a quick example of the usage:
289 * ```
290 * LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size);
291 * LLVMRemarkEntryRef Remark = NULL;
292 * while ((Remark = LLVMRemarkParserGetNext(Parser))) {
293 * // use Remark
294 * LLVMRemarkEntryDispose(Remark); // Release memory.
296 * bool HasError = LLVMRemarkParserHasError(Parser);
297 * LLVMRemarkParserDispose(Parser);
298 * ```
300 * \since REMARKS_API_VERSION=0
302 extern LLVMRemarkEntryRef LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser);
305 * Returns `1` if the parser encountered an error while parsing the buffer.
307 * \since REMARKS_API_VERSION=0
309 extern LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser);
312 * Returns a null-terminated string containing an error message.
314 * In case of no error, the result is `NULL`.
316 * The memory of the string is bound to the lifetime of \p Parser. If
317 * LLVMRemarkParserDispose() is called, the memory of the string will be
318 * released.
320 * \since REMARKS_API_VERSION=0
322 extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser);
325 * Releases all the resources used by \p Parser.
327 * \since REMARKS_API_VERSION=0
329 extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser);
332 * Returns the version of the remarks library.
334 * \since REMARKS_API_VERSION=0
336 extern uint32_t LLVMRemarkVersion(void);
339 * @} // endgoup LLVMCREMARKS
342 LLVM_C_EXTERN_C_END
344 #endif /* LLVM_C_REMARKS_H */