Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/Remarks.h
35233 views
/*===-- llvm-c/Remarks.h - Remarks Public C Interface -------------*- C -*-===*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header provides a public interface to a remark diagnostics library. *|10|* LLVM provides an implementation of this interface. *|11|* *|12\*===----------------------------------------------------------------------===*/1314#ifndef LLVM_C_REMARKS_H15#define LLVM_C_REMARKS_H1617#include "llvm-c/ExternC.h"18#include "llvm-c/Types.h"19#ifdef __cplusplus20#include <cstddef>21#else22#include <stddef.h>23#endif /* !defined(__cplusplus) */2425LLVM_C_EXTERN_C_BEGIN2627/**28* @defgroup LLVMCREMARKS Remarks29* @ingroup LLVMC30*31* @{32*/3334// 0 -> 1: Bitstream remarks support.35#define REMARKS_API_VERSION 13637/**38* The type of the emitted remark.39*/40enum LLVMRemarkType {41LLVMRemarkTypeUnknown,42LLVMRemarkTypePassed,43LLVMRemarkTypeMissed,44LLVMRemarkTypeAnalysis,45LLVMRemarkTypeAnalysisFPCommute,46LLVMRemarkTypeAnalysisAliasing,47LLVMRemarkTypeFailure48};4950/**51* String containing a buffer and a length. The buffer is not guaranteed to be52* zero-terminated.53*54* \since REMARKS_API_VERSION=055*/56typedef struct LLVMRemarkOpaqueString *LLVMRemarkStringRef;5758/**59* Returns the buffer holding the string.60*61* \since REMARKS_API_VERSION=062*/63extern const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String);6465/**66* Returns the size of the string.67*68* \since REMARKS_API_VERSION=069*/70extern uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String);7172/**73* DebugLoc containing File, Line and Column.74*75* \since REMARKS_API_VERSION=076*/77typedef struct LLVMRemarkOpaqueDebugLoc *LLVMRemarkDebugLocRef;7879/**80* Return the path to the source file for a debug location.81*82* \since REMARKS_API_VERSION=083*/84extern LLVMRemarkStringRef85LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL);8687/**88* Return the line in the source file for a debug location.89*90* \since REMARKS_API_VERSION=091*/92extern uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL);9394/**95* Return the column in the source file for a debug location.96*97* \since REMARKS_API_VERSION=098*/99extern uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL);100101/**102* Element of the "Args" list. The key might give more information about what103* the semantics of the value are, e.g. "Callee" will tell you that the value104* is a symbol that names a function.105*106* \since REMARKS_API_VERSION=0107*/108typedef struct LLVMRemarkOpaqueArg *LLVMRemarkArgRef;109110/**111* Returns the key of an argument. The key defines what the value is, and the112* same key can appear multiple times in the list of arguments.113*114* \since REMARKS_API_VERSION=0115*/116extern LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg);117118/**119* Returns the value of an argument. This is a string that can contain newlines.120*121* \since REMARKS_API_VERSION=0122*/123extern LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg);124125/**126* Returns the debug location that is attached to the value of this argument.127*128* If there is no debug location, the return value will be `NULL`.129*130* \since REMARKS_API_VERSION=0131*/132extern LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg);133134/**135* A remark emitted by the compiler.136*137* \since REMARKS_API_VERSION=0138*/139typedef struct LLVMRemarkOpaqueEntry *LLVMRemarkEntryRef;140141/**142* Free the resources used by the remark entry.143*144* \since REMARKS_API_VERSION=0145*/146extern void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark);147148/**149* The type of the remark. For example, it can allow users to only keep the150* missed optimizations from the compiler.151*152* \since REMARKS_API_VERSION=0153*/154extern enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark);155156/**157* Get the name of the pass that emitted this remark.158*159* \since REMARKS_API_VERSION=0160*/161extern LLVMRemarkStringRef162LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark);163164/**165* Get an identifier of the remark.166*167* \since REMARKS_API_VERSION=0168*/169extern LLVMRemarkStringRef170LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark);171172/**173* Get the name of the function being processed when the remark was emitted.174*175* \since REMARKS_API_VERSION=0176*/177extern LLVMRemarkStringRef178LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark);179180/**181* Returns the debug location that is attached to this remark.182*183* If there is no debug location, the return value will be `NULL`.184*185* \since REMARKS_API_VERSION=0186*/187extern LLVMRemarkDebugLocRef188LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark);189190/**191* Return the hotness of the remark.192*193* A hotness of `0` means this value is not set.194*195* \since REMARKS_API_VERSION=0196*/197extern uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark);198199/**200* The number of arguments the remark holds.201*202* \since REMARKS_API_VERSION=0203*/204extern uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark);205206/**207* Get a new iterator to iterate over a remark's argument.208*209* If there are no arguments in \p Remark, the return value will be `NULL`.210*211* The lifetime of the returned value is bound to the lifetime of \p Remark.212*213* \since REMARKS_API_VERSION=0214*/215extern LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark);216217/**218* Get the next argument in \p Remark from the position of \p It.219*220* Returns `NULL` if there are no more arguments available.221*222* The lifetime of the returned value is bound to the lifetime of \p Remark.223*224* \since REMARKS_API_VERSION=0225*/226extern LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It,227LLVMRemarkEntryRef Remark);228229typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef;230231/**232* Creates a remark parser that can be used to parse the buffer located in \p233* Buf of size \p Size bytes.234*235* \p Buf cannot be `NULL`.236*237* This function should be paired with LLVMRemarkParserDispose() to avoid238* leaking resources.239*240* \since REMARKS_API_VERSION=0241*/242extern LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf,243uint64_t Size);244245/**246* Creates a remark parser that can be used to parse the buffer located in \p247* Buf of size \p Size bytes.248*249* \p Buf cannot be `NULL`.250*251* This function should be paired with LLVMRemarkParserDispose() to avoid252* leaking resources.253*254* \since REMARKS_API_VERSION=1255*/256extern LLVMRemarkParserRef LLVMRemarkParserCreateBitstream(const void *Buf,257uint64_t Size);258259/**260* Returns the next remark in the file.261*262* The value pointed to by the return value needs to be disposed using a call to263* LLVMRemarkEntryDispose().264*265* All the entries in the returned value that are of LLVMRemarkStringRef type266* will become invalidated once a call to LLVMRemarkParserDispose is made.267*268* If the parser reaches the end of the buffer, the return value will be `NULL`.269*270* In the case of an error, the return value will be `NULL`, and:271*272* 1) LLVMRemarkParserHasError() will return `1`.273*274* 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error275* message.276*277* An error may occur if:278*279* 1) An argument is invalid.280*281* 2) There is a parsing error. This can occur on things like malformed YAML.282*283* 3) There is a Remark semantic error. This can occur on well-formed files with284* missing or extra fields.285*286* Here is a quick example of the usage:287*288* ```289* LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size);290* LLVMRemarkEntryRef Remark = NULL;291* while ((Remark = LLVMRemarkParserGetNext(Parser))) {292* // use Remark293* LLVMRemarkEntryDispose(Remark); // Release memory.294* }295* bool HasError = LLVMRemarkParserHasError(Parser);296* LLVMRemarkParserDispose(Parser);297* ```298*299* \since REMARKS_API_VERSION=0300*/301extern LLVMRemarkEntryRef LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser);302303/**304* Returns `1` if the parser encountered an error while parsing the buffer.305*306* \since REMARKS_API_VERSION=0307*/308extern LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser);309310/**311* Returns a null-terminated string containing an error message.312*313* In case of no error, the result is `NULL`.314*315* The memory of the string is bound to the lifetime of \p Parser. If316* LLVMRemarkParserDispose() is called, the memory of the string will be317* released.318*319* \since REMARKS_API_VERSION=0320*/321extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser);322323/**324* Releases all the resources used by \p Parser.325*326* \since REMARKS_API_VERSION=0327*/328extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser);329330/**331* Returns the version of the remarks library.332*333* \since REMARKS_API_VERSION=0334*/335extern uint32_t LLVMRemarkVersion(void);336337/**338* @} // endgoup LLVMCREMARKS339*/340341LLVM_C_EXTERN_C_END342343#endif /* LLVM_C_REMARKS_H */344345346