Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 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/Core.h" |
| 19 | #include "llvm-c/Types.h" |
| 20 | #ifdef __cplusplus |
| 21 | #include <cstddef> |
| 22 | extern "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 Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 37 | * The type of the emitted remark. |
| 38 | */ |
| 39 | enum LLVMRemarkType { |
| 40 | LLVMRemarkTypeUnknown, |
| 41 | LLVMRemarkTypePassed, |
| 42 | LLVMRemarkTypeMissed, |
| 43 | LLVMRemarkTypeAnalysis, |
| 44 | LLVMRemarkTypeAnalysisFPCommute, |
| 45 | LLVMRemarkTypeAnalysisAliasing, |
| 46 | LLVMRemarkTypeFailure |
| 47 | }; |
| 48 | |
| 49 | /** |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 50 | * 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 Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 55 | typedef struct LLVMRemarkOpaqueString *LLVMRemarkStringRef; |
| 56 | |
| 57 | /** |
| 58 | * Returns the buffer holding the string. |
| 59 | * |
| 60 | * \since REMARKS_API_VERSION=0 |
| 61 | */ |
| 62 | extern const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String); |
| 63 | |
| 64 | /** |
| 65 | * Returns the size of the string. |
| 66 | * |
| 67 | * \since REMARKS_API_VERSION=0 |
| 68 | */ |
| 69 | extern uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String); |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * DebugLoc containing File, Line and Column. |
| 73 | * |
| 74 | * \since REMARKS_API_VERSION=0 |
| 75 | */ |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 76 | typedef 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 | */ |
| 83 | extern LLVMRemarkStringRef |
| 84 | LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL); |
| 85 | |
| 86 | /** |
| 87 | * Return the line in the source file for a debug location. |
| 88 | * |
| 89 | * \since REMARKS_API_VERSION=0 |
| 90 | */ |
| 91 | extern 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 | */ |
| 98 | extern uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL); |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * Element of the "Args" list. The key might give more information about what |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 102 | * the semantics of the value are, e.g. "Callee" will tell you that the value |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 103 | * is a symbol that names a function. |
| 104 | * |
| 105 | * \since REMARKS_API_VERSION=0 |
| 106 | */ |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 107 | typedef struct LLVMRemarkOpaqueArg *LLVMRemarkArgRef; |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 108 | |
| 109 | /** |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 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. |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 112 | * |
| 113 | * \since REMARKS_API_VERSION=0 |
| 114 | */ |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 115 | extern LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg); |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 116 | |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 117 | /** |
| 118 | * Returns the value of an argument. This is a string that can contain newlines. |
| 119 | * |
| 120 | * \since REMARKS_API_VERSION=0 |
| 121 | */ |
| 122 | extern 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 | */ |
| 131 | extern LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg); |
| 132 | |
| 133 | /** |
| 134 | * A remark emitted by the compiler. |
| 135 | * |
| 136 | * \since REMARKS_API_VERSION=0 |
| 137 | */ |
| 138 | typedef 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 | */ |
| 146 | extern 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 | */ |
| 153 | extern LLVMRemarkStringRef |
| 154 | LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark); |
| 155 | |
| 156 | /** |
| 157 | * Get an identifier of the remark. |
| 158 | * |
| 159 | * \since REMARKS_API_VERSION=0 |
| 160 | */ |
| 161 | extern LLVMRemarkStringRef |
| 162 | LLVMRemarkEntryGetRemarkName(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 | */ |
| 169 | extern LLVMRemarkStringRef |
| 170 | LLVMRemarkEntryGetFunctionName(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 | */ |
| 179 | extern LLVMRemarkDebugLocRef |
| 180 | LLVMRemarkEntryGetDebugLoc(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 | */ |
| 189 | extern uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark); |
| 190 | |
| 191 | /** |
| 192 | * The number of arguments the remark holds. |
| 193 | * |
| 194 | * \since REMARKS_API_VERSION=0 |
| 195 | */ |
| 196 | extern 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 | */ |
| 205 | extern 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 | */ |
| 214 | extern LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It, |
| 215 | LLVMRemarkEntryRef Remark); |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 216 | |
| 217 | typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef; |
| 218 | |
| 219 | /** |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 220 | * Creates a remark parser that can be used to parse the buffer located in \p |
| 221 | * Buf of size \p Size bytes. |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 222 | * |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 223 | * \p Buf cannot be `NULL`. |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 224 | * |
| 225 | * This function should be paired with LLVMRemarkParserDispose() to avoid |
| 226 | * leaking resources. |
| 227 | * |
| 228 | * \since REMARKS_API_VERSION=0 |
| 229 | */ |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 230 | extern LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf, |
| 231 | uint64_t Size); |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 232 | |
| 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 Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 239 | * If the parser reaches the end of the buffer, the return value will be `NULL`. |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 240 | * |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 241 | * In the case of an error, the return value will be `NULL`, and: |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 242 | * |
| 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 Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 252 | * 2) There is a parsing error. This can occur on things like malformed YAML. |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 253 | * |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 254 | * 3) There is a Remark semantic error. This can occur on well-formed files with |
| 255 | * missing or extra fields. |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 256 | * |
| 257 | * Here is a quick example of the usage: |
| 258 | * |
| 259 | * ``` |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 260 | * LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size); |
| 261 | * LLVMRemarkEntryRef Remark = NULL; |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 262 | * 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 Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 271 | extern LLVMRemarkEntryRef LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser); |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * Returns `1` if the parser encountered an error while parsing the buffer. |
| 275 | * |
| 276 | * \since REMARKS_API_VERSION=0 |
| 277 | */ |
| 278 | extern 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 | */ |
| 291 | extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser); |
| 292 | |
| 293 | /** |
| 294 | * Releases all the resources used by \p Parser. |
| 295 | * |
| 296 | * \since REMARKS_API_VERSION=0 |
| 297 | */ |
| 298 | extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser); |
| 299 | |
| 300 | /** |
Francis Visoiu Mistrih | 5a05cc0 | 2019-03-19 21:11:07 +0000 | [diff] [blame^] | 301 | * Returns the version of the remarks library. |
Francis Visoiu Mistrih | 1c4bab3 | 2019-03-05 20:45:17 +0000 | [diff] [blame] | 302 | * |
| 303 | * \since REMARKS_API_VERSION=0 |
| 304 | */ |
| 305 | extern 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 */ |