Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:01

0001 /*===-- llvm-c/Remarks.h - Remarks Public C Interface -------------*- C -*-===*\
0002 |*                                                                            *|
0003 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
0004 |* Exceptions.                                                                *|
0005 |* See https://llvm.org/LICENSE.txt for license information.                  *|
0006 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
0007 |*                                                                            *|
0008 |*===----------------------------------------------------------------------===*|
0009 |*                                                                            *|
0010 |* This header provides a public interface to a remark diagnostics library.   *|
0011 |* LLVM provides an implementation of this interface.                         *|
0012 |*                                                                            *|
0013 \*===----------------------------------------------------------------------===*/
0014 
0015 #ifndef LLVM_C_REMARKS_H
0016 #define LLVM_C_REMARKS_H
0017 
0018 #include "llvm-c/ExternC.h"
0019 #include "llvm-c/Types.h"
0020 #ifdef __cplusplus
0021 #include <cstddef>
0022 #else
0023 #include <stddef.h>
0024 #endif /* !defined(__cplusplus) */
0025 
0026 LLVM_C_EXTERN_C_BEGIN
0027 
0028 /**
0029  * @defgroup LLVMCREMARKS Remarks
0030  * @ingroup LLVMC
0031  *
0032  * @{
0033  */
0034 
0035 // 0 -> 1: Bitstream remarks support.
0036 #define REMARKS_API_VERSION 1
0037 
0038 /**
0039  * The type of the emitted remark.
0040  */
0041 enum LLVMRemarkType {
0042   LLVMRemarkTypeUnknown,
0043   LLVMRemarkTypePassed,
0044   LLVMRemarkTypeMissed,
0045   LLVMRemarkTypeAnalysis,
0046   LLVMRemarkTypeAnalysisFPCommute,
0047   LLVMRemarkTypeAnalysisAliasing,
0048   LLVMRemarkTypeFailure
0049 };
0050 
0051 /**
0052  * String containing a buffer and a length. The buffer is not guaranteed to be
0053  * zero-terminated.
0054  *
0055  * \since REMARKS_API_VERSION=0
0056  */
0057 typedef struct LLVMRemarkOpaqueString *LLVMRemarkStringRef;
0058 
0059 /**
0060  * Returns the buffer holding the string.
0061  *
0062  * \since REMARKS_API_VERSION=0
0063  */
0064 extern const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String);
0065 
0066 /**
0067  * Returns the size of the string.
0068  *
0069  * \since REMARKS_API_VERSION=0
0070  */
0071 extern uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String);
0072 
0073 /**
0074  * DebugLoc containing File, Line and Column.
0075  *
0076  * \since REMARKS_API_VERSION=0
0077  */
0078 typedef struct LLVMRemarkOpaqueDebugLoc *LLVMRemarkDebugLocRef;
0079 
0080 /**
0081  * Return the path to the source file for a debug location.
0082  *
0083  * \since REMARKS_API_VERSION=0
0084  */
0085 extern LLVMRemarkStringRef
0086 LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL);
0087 
0088 /**
0089  * Return the line in the source file for a debug location.
0090  *
0091  * \since REMARKS_API_VERSION=0
0092  */
0093 extern uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL);
0094 
0095 /**
0096  * Return the column in the source file for a debug location.
0097  *
0098  * \since REMARKS_API_VERSION=0
0099  */
0100 extern uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL);
0101 
0102 /**
0103  * Element of the "Args" list. The key might give more information about what
0104  * the semantics of the value are, e.g. "Callee" will tell you that the value
0105  * is a symbol that names a function.
0106  *
0107  * \since REMARKS_API_VERSION=0
0108  */
0109 typedef struct LLVMRemarkOpaqueArg *LLVMRemarkArgRef;
0110 
0111 /**
0112  * Returns the key of an argument. The key defines what the value is, and the
0113  * same key can appear multiple times in the list of arguments.
0114  *
0115  * \since REMARKS_API_VERSION=0
0116  */
0117 extern LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg);
0118 
0119 /**
0120  * Returns the value of an argument. This is a string that can contain newlines.
0121  *
0122  * \since REMARKS_API_VERSION=0
0123  */
0124 extern LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg);
0125 
0126 /**
0127  * Returns the debug location that is attached to the value of this argument.
0128  *
0129  * If there is no debug location, the return value will be `NULL`.
0130  *
0131  * \since REMARKS_API_VERSION=0
0132  */
0133 extern LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg);
0134 
0135 /**
0136  * A remark emitted by the compiler.
0137  *
0138  * \since REMARKS_API_VERSION=0
0139  */
0140 typedef struct LLVMRemarkOpaqueEntry *LLVMRemarkEntryRef;
0141 
0142 /**
0143  * Free the resources used by the remark entry.
0144  *
0145  * \since REMARKS_API_VERSION=0
0146  */
0147 extern void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark);
0148 
0149 /**
0150  * The type of the remark. For example, it can allow users to only keep the
0151  * missed optimizations from the compiler.
0152  *
0153  * \since REMARKS_API_VERSION=0
0154  */
0155 extern enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark);
0156 
0157 /**
0158  * Get the name of the pass that emitted this remark.
0159  *
0160  * \since REMARKS_API_VERSION=0
0161  */
0162 extern LLVMRemarkStringRef
0163 LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark);
0164 
0165 /**
0166  * Get an identifier of the remark.
0167  *
0168  * \since REMARKS_API_VERSION=0
0169  */
0170 extern LLVMRemarkStringRef
0171 LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark);
0172 
0173 /**
0174  * Get the name of the function being processed when the remark was emitted.
0175  *
0176  * \since REMARKS_API_VERSION=0
0177  */
0178 extern LLVMRemarkStringRef
0179 LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark);
0180 
0181 /**
0182  * Returns the debug location that is attached to this remark.
0183  *
0184  * If there is no debug location, the return value will be `NULL`.
0185  *
0186  * \since REMARKS_API_VERSION=0
0187  */
0188 extern LLVMRemarkDebugLocRef
0189 LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark);
0190 
0191 /**
0192  * Return the hotness of the remark.
0193  *
0194  * A hotness of `0` means this value is not set.
0195  *
0196  * \since REMARKS_API_VERSION=0
0197  */
0198 extern uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark);
0199 
0200 /**
0201  * The number of arguments the remark holds.
0202  *
0203  * \since REMARKS_API_VERSION=0
0204  */
0205 extern uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark);
0206 
0207 /**
0208  * Get a new iterator to iterate over a remark's argument.
0209  *
0210  * If there are no arguments in \p Remark, the return value will be `NULL`.
0211  *
0212  * The lifetime of the returned value is bound to the lifetime of \p Remark.
0213  *
0214  * \since REMARKS_API_VERSION=0
0215  */
0216 extern LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark);
0217 
0218 /**
0219  * Get the next argument in \p Remark from the position of \p It.
0220  *
0221  * Returns `NULL` if there are no more arguments available.
0222  *
0223  * The lifetime of the returned value is bound to the lifetime of \p Remark.
0224  *
0225  * \since REMARKS_API_VERSION=0
0226  */
0227 extern LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It,
0228                                                   LLVMRemarkEntryRef Remark);
0229 
0230 typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef;
0231 
0232 /**
0233  * Creates a remark parser that can be used to parse the buffer located in \p
0234  * Buf of size \p Size bytes.
0235  *
0236  * \p Buf cannot be `NULL`.
0237  *
0238  * This function should be paired with LLVMRemarkParserDispose() to avoid
0239  * leaking resources.
0240  *
0241  * \since REMARKS_API_VERSION=0
0242  */
0243 extern LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf,
0244                                                       uint64_t Size);
0245 
0246 /**
0247  * Creates a remark parser that can be used to parse the buffer located in \p
0248  * Buf of size \p Size bytes.
0249  *
0250  * \p Buf cannot be `NULL`.
0251  *
0252  * This function should be paired with LLVMRemarkParserDispose() to avoid
0253  * leaking resources.
0254  *
0255  * \since REMARKS_API_VERSION=1
0256  */
0257 extern LLVMRemarkParserRef LLVMRemarkParserCreateBitstream(const void *Buf,
0258                                                            uint64_t Size);
0259 
0260 /**
0261  * Returns the next remark in the file.
0262  *
0263  * The value pointed to by the return value needs to be disposed using a call to
0264  * LLVMRemarkEntryDispose().
0265  *
0266  * All the entries in the returned value that are of LLVMRemarkStringRef type
0267  * will become invalidated once a call to LLVMRemarkParserDispose is made.
0268  *
0269  * If the parser reaches the end of the buffer, the return value will be `NULL`.
0270  *
0271  * In the case of an error, the return value will be `NULL`, and:
0272  *
0273  * 1) LLVMRemarkParserHasError() will return `1`.
0274  *
0275  * 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error
0276  *    message.
0277  *
0278  * An error may occur if:
0279  *
0280  * 1) An argument is invalid.
0281  *
0282  * 2) There is a parsing error. This can occur on things like malformed YAML.
0283  *
0284  * 3) There is a Remark semantic error. This can occur on well-formed files with
0285  *    missing or extra fields.
0286  *
0287  * Here is a quick example of the usage:
0288  *
0289  * ```
0290  * LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size);
0291  * LLVMRemarkEntryRef Remark = NULL;
0292  * while ((Remark = LLVMRemarkParserGetNext(Parser))) {
0293  *    // use Remark
0294  *    LLVMRemarkEntryDispose(Remark); // Release memory.
0295  * }
0296  * bool HasError = LLVMRemarkParserHasError(Parser);
0297  * LLVMRemarkParserDispose(Parser);
0298  * ```
0299  *
0300  * \since REMARKS_API_VERSION=0
0301  */
0302 extern LLVMRemarkEntryRef LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser);
0303 
0304 /**
0305  * Returns `1` if the parser encountered an error while parsing the buffer.
0306  *
0307  * \since REMARKS_API_VERSION=0
0308  */
0309 extern LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser);
0310 
0311 /**
0312  * Returns a null-terminated string containing an error message.
0313  *
0314  * In case of no error, the result is `NULL`.
0315  *
0316  * The memory of the string is bound to the lifetime of \p Parser. If
0317  * LLVMRemarkParserDispose() is called, the memory of the string will be
0318  * released.
0319  *
0320  * \since REMARKS_API_VERSION=0
0321  */
0322 extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser);
0323 
0324 /**
0325  * Releases all the resources used by \p Parser.
0326  *
0327  * \since REMARKS_API_VERSION=0
0328  */
0329 extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser);
0330 
0331 /**
0332  * Returns the version of the remarks library.
0333  *
0334  * \since REMARKS_API_VERSION=0
0335  */
0336 extern uint32_t LLVMRemarkVersion(void);
0337 
0338 /**
0339  * @} // endgoup LLVMCREMARKS
0340  */
0341 
0342 LLVM_C_EXTERN_C_END
0343 
0344 #endif /* LLVM_C_REMARKS_H */