2019-03-06 04:45:17 +08:00
|
|
|
/*===-- llvm-c/Remarks.h - Remarks Public C Interface -------------*- C -*-===*\
|
2018-10-11 02:43:42 +08:00
|
|
|
|* *|
|
2019-01-19 16:50:56 +08:00
|
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
|
|
|
|* Exceptions. *|
|
|
|
|
|* See https://llvm.org/LICENSE.txt for license information. *|
|
|
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
2018-10-11 02:43:42 +08:00
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
2019-03-06 04:45:17 +08:00
|
|
|
|* This header provides a public interface to a remark diagnostics library. *|
|
2018-10-11 02:43:42 +08:00
|
|
|
|* LLVM provides an implementation of this interface. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
2019-03-06 04:45:17 +08:00
|
|
|
#ifndef LLVM_C_REMARKS_H
|
|
|
|
#define LLVM_C_REMARKS_H
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2019-11-15 05:57:57 +08:00
|
|
|
#include "llvm-c/ExternC.h"
|
2018-10-11 02:43:42 +08:00
|
|
|
#include "llvm-c/Types.h"
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <cstddef>
|
|
|
|
#else
|
|
|
|
#include <stddef.h>
|
|
|
|
#endif /* !defined(__cplusplus) */
|
|
|
|
|
2019-11-15 05:57:57 +08:00
|
|
|
LLVM_C_EXTERN_C_BEGIN
|
|
|
|
|
2018-10-11 02:43:42 +08:00
|
|
|
/**
|
2019-03-06 04:45:17 +08:00
|
|
|
* @defgroup LLVMCREMARKS Remarks
|
2018-10-11 02:43:42 +08:00
|
|
|
* @ingroup LLVMC
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2019-09-10 01:43:50 +08:00
|
|
|
// 0 -> 1: Bitstream remarks support.
|
|
|
|
#define REMARKS_API_VERSION 1
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2019-03-20 05:11:07 +08:00
|
|
|
/**
|
|
|
|
* The type of the emitted remark.
|
|
|
|
*/
|
|
|
|
enum LLVMRemarkType {
|
|
|
|
LLVMRemarkTypeUnknown,
|
|
|
|
LLVMRemarkTypePassed,
|
|
|
|
LLVMRemarkTypeMissed,
|
|
|
|
LLVMRemarkTypeAnalysis,
|
|
|
|
LLVMRemarkTypeAnalysisFPCommute,
|
|
|
|
LLVMRemarkTypeAnalysisAliasing,
|
|
|
|
LLVMRemarkTypeFailure
|
|
|
|
};
|
|
|
|
|
2018-10-11 02:43:42 +08:00
|
|
|
/**
|
|
|
|
* String containing a buffer and a length. The buffer is not guaranteed to be
|
|
|
|
* zero-terminated.
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-20 05:11:07 +08:00
|
|
|
typedef struct LLVMRemarkOpaqueString *LLVMRemarkStringRef;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the buffer holding the string.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern const char *LLVMRemarkStringGetData(LLVMRemarkStringRef String);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the size of the string.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern uint32_t LLVMRemarkStringGetLen(LLVMRemarkStringRef String);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DebugLoc containing File, Line and Column.
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-20 05:11:07 +08:00
|
|
|
typedef struct LLVMRemarkOpaqueDebugLoc *LLVMRemarkDebugLocRef;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the path to the source file for a debug location.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkStringRef
|
|
|
|
LLVMRemarkDebugLocGetSourceFilePath(LLVMRemarkDebugLocRef DL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the line in the source file for a debug location.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern uint32_t LLVMRemarkDebugLocGetSourceLine(LLVMRemarkDebugLocRef DL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the column in the source file for a debug location.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern uint32_t LLVMRemarkDebugLocGetSourceColumn(LLVMRemarkDebugLocRef DL);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Element of the "Args" list. The key might give more information about what
|
2019-03-20 05:11:07 +08:00
|
|
|
* the semantics of the value are, e.g. "Callee" will tell you that the value
|
2018-10-11 02:43:42 +08:00
|
|
|
* is a symbol that names a function.
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-20 05:11:07 +08:00
|
|
|
typedef struct LLVMRemarkOpaqueArg *LLVMRemarkArgRef;
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2019-03-20 05:11:07 +08:00
|
|
|
/**
|
|
|
|
* Returns the key of an argument. The key defines what the value is, and the
|
|
|
|
* same key can appear multiple times in the list of arguments.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkStringRef LLVMRemarkArgGetKey(LLVMRemarkArgRef Arg);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
|
|
|
/**
|
2019-03-20 05:11:07 +08:00
|
|
|
* Returns the value of an argument. This is a string that can contain newlines.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-20 05:11:07 +08:00
|
|
|
extern LLVMRemarkStringRef LLVMRemarkArgGetValue(LLVMRemarkArgRef Arg);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2019-03-20 05:11:07 +08:00
|
|
|
/**
|
|
|
|
* Returns the debug location that is attached to the value of this argument.
|
|
|
|
*
|
|
|
|
* If there is no debug location, the return value will be `NULL`.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkDebugLocRef LLVMRemarkArgGetDebugLoc(LLVMRemarkArgRef Arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A remark emitted by the compiler.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
typedef struct LLVMRemarkOpaqueEntry *LLVMRemarkEntryRef;
|
|
|
|
|
2019-07-16 23:25:05 +08:00
|
|
|
/**
|
|
|
|
* Free the resources used by the remark entry.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern void LLVMRemarkEntryDispose(LLVMRemarkEntryRef Remark);
|
|
|
|
|
2019-03-20 05:11:07 +08:00
|
|
|
/**
|
|
|
|
* The type of the remark. For example, it can allow users to only keep the
|
|
|
|
* missed optimizations from the compiler.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern enum LLVMRemarkType LLVMRemarkEntryGetType(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the pass that emitted this remark.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkStringRef
|
|
|
|
LLVMRemarkEntryGetPassName(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an identifier of the remark.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkStringRef
|
|
|
|
LLVMRemarkEntryGetRemarkName(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
2019-07-16 23:25:05 +08:00
|
|
|
* Get the name of the function being processed when the remark was emitted.
|
2019-03-20 05:11:07 +08:00
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkStringRef
|
|
|
|
LLVMRemarkEntryGetFunctionName(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the debug location that is attached to this remark.
|
|
|
|
*
|
|
|
|
* If there is no debug location, the return value will be `NULL`.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkDebugLocRef
|
|
|
|
LLVMRemarkEntryGetDebugLoc(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the hotness of the remark.
|
|
|
|
*
|
|
|
|
* A hotness of `0` means this value is not set.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern uint64_t LLVMRemarkEntryGetHotness(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of arguments the remark holds.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern uint32_t LLVMRemarkEntryGetNumArgs(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a new iterator to iterate over a remark's argument.
|
|
|
|
*
|
|
|
|
* If there are no arguments in \p Remark, the return value will be `NULL`.
|
|
|
|
*
|
2019-07-16 23:25:05 +08:00
|
|
|
* The lifetime of the returned value is bound to the lifetime of \p Remark.
|
|
|
|
*
|
2019-03-20 05:11:07 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkArgRef LLVMRemarkEntryGetFirstArg(LLVMRemarkEntryRef Remark);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next argument in \p Remark from the position of \p It.
|
|
|
|
*
|
|
|
|
* Returns `NULL` if there are no more arguments available.
|
|
|
|
*
|
2019-07-16 23:25:05 +08:00
|
|
|
* The lifetime of the returned value is bound to the lifetime of \p Remark.
|
|
|
|
*
|
2019-03-20 05:11:07 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkArgRef LLVMRemarkEntryGetNextArg(LLVMRemarkArgRef It,
|
|
|
|
LLVMRemarkEntryRef Remark);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2019-03-06 04:45:17 +08:00
|
|
|
typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef;
|
2018-10-11 02:43:42 +08:00
|
|
|
|
|
|
|
/**
|
2019-03-20 05:11:07 +08:00
|
|
|
* Creates a remark parser that can be used to parse the buffer located in \p
|
|
|
|
* Buf of size \p Size bytes.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-20 05:11:07 +08:00
|
|
|
* \p Buf cannot be `NULL`.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* This function should be paired with LLVMRemarkParserDispose() to avoid
|
2018-10-11 02:43:42 +08:00
|
|
|
* leaking resources.
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-20 05:11:07 +08:00
|
|
|
extern LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf,
|
|
|
|
uint64_t Size);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2019-09-10 01:43:50 +08:00
|
|
|
/**
|
|
|
|
* Creates a remark parser that can be used to parse the buffer located in \p
|
|
|
|
* Buf of size \p Size bytes.
|
|
|
|
*
|
|
|
|
* \p Buf cannot be `NULL`.
|
|
|
|
*
|
|
|
|
* This function should be paired with LLVMRemarkParserDispose() to avoid
|
|
|
|
* leaking resources.
|
|
|
|
*
|
|
|
|
* \since REMARKS_API_VERSION=1
|
|
|
|
*/
|
|
|
|
extern LLVMRemarkParserRef LLVMRemarkParserCreateBitstream(const void *Buf,
|
|
|
|
uint64_t Size);
|
|
|
|
|
2018-10-11 02:43:42 +08:00
|
|
|
/**
|
|
|
|
* Returns the next remark in the file.
|
|
|
|
*
|
2019-07-16 23:25:05 +08:00
|
|
|
* The value pointed to by the return value needs to be disposed using a call to
|
|
|
|
* LLVMRemarkEntryDispose().
|
|
|
|
*
|
|
|
|
* All the entries in the returned value that are of LLVMRemarkStringRef type
|
|
|
|
* will become invalidated once a call to LLVMRemarkParserDispose is made.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-20 05:11:07 +08:00
|
|
|
* If the parser reaches the end of the buffer, the return value will be `NULL`.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-20 05:11:07 +08:00
|
|
|
* In the case of an error, the return value will be `NULL`, and:
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* 1) LLVMRemarkParserHasError() will return `1`.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error
|
2018-10-11 02:43:42 +08:00
|
|
|
* message.
|
|
|
|
*
|
|
|
|
* An error may occur if:
|
|
|
|
*
|
|
|
|
* 1) An argument is invalid.
|
|
|
|
*
|
2019-03-20 05:11:07 +08:00
|
|
|
* 2) There is a parsing error. This can occur on things like malformed YAML.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
2019-03-20 05:11:07 +08:00
|
|
|
* 3) There is a Remark semantic error. This can occur on well-formed files with
|
|
|
|
* missing or extra fields.
|
2018-10-11 02:43:42 +08:00
|
|
|
*
|
|
|
|
* Here is a quick example of the usage:
|
|
|
|
*
|
|
|
|
* ```
|
2019-03-20 05:11:07 +08:00
|
|
|
* LLVMRemarkParserRef Parser = LLVMRemarkParserCreateYAML(Buf, Size);
|
|
|
|
* LLVMRemarkEntryRef Remark = NULL;
|
2019-07-16 23:25:05 +08:00
|
|
|
* while ((Remark = LLVMRemarkParserGetNext(Parser))) {
|
2018-10-11 02:43:42 +08:00
|
|
|
* // use Remark
|
2019-07-16 23:25:05 +08:00
|
|
|
* LLVMRemarkEntryDispose(Remark); // Release memory.
|
2019-03-06 04:45:17 +08:00
|
|
|
* }
|
|
|
|
* bool HasError = LLVMRemarkParserHasError(Parser);
|
|
|
|
* LLVMRemarkParserDispose(Parser);
|
2018-10-11 02:43:42 +08:00
|
|
|
* ```
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-20 05:11:07 +08:00
|
|
|
extern LLVMRemarkEntryRef LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns `1` if the parser encountered an error while parsing the buffer.
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-06 04:45:17 +08:00
|
|
|
extern LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a null-terminated string containing an error message.
|
|
|
|
*
|
|
|
|
* In case of no error, the result is `NULL`.
|
|
|
|
*
|
|
|
|
* The memory of the string is bound to the lifetime of \p Parser. If
|
2019-03-06 04:45:17 +08:00
|
|
|
* LLVMRemarkParserDispose() is called, the memory of the string will be
|
2018-10-11 02:43:42 +08:00
|
|
|
* released.
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-06 04:45:17 +08:00
|
|
|
extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Releases all the resources used by \p Parser.
|
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
2019-03-06 04:45:17 +08:00
|
|
|
extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser);
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2018-11-05 19:57:44 +08:00
|
|
|
/**
|
2019-03-20 05:11:07 +08:00
|
|
|
* Returns the version of the remarks library.
|
2018-11-05 19:57:44 +08:00
|
|
|
*
|
2019-03-06 04:45:17 +08:00
|
|
|
* \since REMARKS_API_VERSION=0
|
2018-11-05 19:57:44 +08:00
|
|
|
*/
|
2019-03-06 04:45:17 +08:00
|
|
|
extern uint32_t LLVMRemarkVersion(void);
|
2018-11-05 19:57:44 +08:00
|
|
|
|
2018-10-11 02:43:42 +08:00
|
|
|
/**
|
2019-03-06 04:45:17 +08:00
|
|
|
* @} // endgoup LLVMCREMARKS
|
2018-10-11 02:43:42 +08:00
|
|
|
*/
|
|
|
|
|
2019-11-15 05:57:57 +08:00
|
|
|
LLVM_C_EXTERN_C_END
|
2018-10-11 02:43:42 +08:00
|
|
|
|
2019-03-06 04:45:17 +08:00
|
|
|
#endif /* LLVM_C_REMARKS_H */
|