MLIR 24.0.0git
Remarks.h
Go to the documentation of this file.
1//===-- mlir-c/Remarks.h - MLIR Remark Engine C API ---------------*- C -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM 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 declares the C interface to the MLIR optimization remark engine:
10// enabling the engine on a context with category filters, an emitting policy
11// and a sink (MLIR diagnostics, a YAML/bitstream file, or a callback),
12// emitting remarks, and inspecting a remark from inside a callback.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef MLIR_C_REMARKS_H
17#define MLIR_C_REMARKS_H
18
19#include "mlir-c/IR.h"
20#include "mlir-c/Support.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26//===----------------------------------------------------------------------===//
27// Opaque types and enums.
28//===----------------------------------------------------------------------===//
29
30/// An opaque reference to a remark. A remark is only valid for the duration of
31/// the callback it is passed to; it must not be stored.
32struct MlirRemark {
33 const void *ptr;
34};
35typedef struct MlirRemark MlirRemark;
36
37/// The outcome a remark describes (see mlir::remark::RemarkKind).
40 /// An optimization was applied.
42 /// A profitable optimization opportunity was found but not applied.
44 /// The optimization was attempted but failed.
46 /// Informational context without a pass/fail outcome.
48};
50
51/// The emitting policy of the remark engine.
53 /// Report every remark as it is emitted.
55 /// Postpone remarks and report the final set when the engine is finalized,
56 /// grouping related remarks under their parents.
58};
60
61/// The serialization format of a remark output file.
67
68/// Regular expressions (llvm::Regex syntax, anchored by the engine) selecting
69/// the remark categories to report: `all` applies to every kind, the others to
70/// one kind each. A string of length 0 means the filter is not set, so the
71/// corresponding kind is not reported unless `all` matches.
80
81/// Callback receiving every remark the engine reports.
82typedef void (*MlirRemarkCallback)(MlirRemark remark, void *userData);
83
84//===----------------------------------------------------------------------===//
85// Enabling and finalizing the engine of a context.
86//===----------------------------------------------------------------------===//
87
88/// Enables the remark engine on the context without a streamer; when
89/// `printAsEmitRemarks` is set, every reported remark is emitted as an MLIR
90/// remark diagnostic at its location. Fails when the context already has a
91/// remark engine (finalize it first).
93 MlirContext context, MlirRemarkCategories categories,
94 MlirRemarkPolicy policy, bool printAsEmitRemarks);
95
96/// Enables the remark engine on the context, streaming the reported remarks to
97/// the file at `path` in `format`. The file is written when the engine is
98/// finalized. Fails when the file cannot be created or the context already has
99/// a remark engine.
101 MlirContext context, MlirRemarkCategories categories,
103 bool printAsEmitRemarks);
104
105/// Enables the remark engine on the context, delivering every reported remark
106/// to `callback`. `userData` is passed to the callback unchanged and released
107/// through `deleteUserData` (may be null) when the engine is finalized or the
108/// context is destroyed. Fails when the context already has a remark engine.
111 MlirContext context, MlirRemarkCategories categories,
112 MlirRemarkPolicy policy, MlirRemarkCallback callback, void *userData,
113 void (*deleteUserData)(void *), bool printAsEmitRemarks);
114
115/// Finalizes and removes the remark engine of the context: postponed remarks
116/// are reported, the output file is written and the callback's user data is
117/// released. Does nothing when no engine is enabled.
119mlirContextFinalizeOptimizationRemarks(MlirContext context);
120
121/// Returns whether the context has a remark engine enabled.
122MLIR_CAPI_EXPORTED bool mlirContextHasRemarkEngine(MlirContext context);
123
124//===----------------------------------------------------------------------===//
125// Remark accessors (valid only inside a remark callback).
126//===----------------------------------------------------------------------===//
127
128/// Returns the kind of the remark.
130
131/// Returns the name identifying the remark.
133
134/// Returns the category of the remark (the subject of the filters).
136
137/// Returns the combined `category:subcategory` name of the remark.
140
141/// Returns the name of the function the remark refers to.
143
144/// Returns the location of the remark.
146
147/// Returns the unique id of the remark within its engine (0 when unset).
149
150/// Returns the number of key/value arguments attached to the remark.
152
153/// Returns the key of the `pos`-th argument of the remark.
155 intptr_t pos);
156
157/// Returns the value of the `pos`-th argument of the remark.
159 intptr_t pos);
160
161/// Prints the remark in its textual form, `[Kind] name | Category:... |
162/// Function=... | key=value, ...` (without its location).
164mlirRemarkPrint(MlirRemark remark, MlirStringCallback callback, void *userData);
165
166//===----------------------------------------------------------------------===//
167// Emission.
168//===----------------------------------------------------------------------===//
169
170/// Emits a remark of `kind` at `location` through the remark engine of the
171/// location's context. `message` (when non-empty) and the `numArgs` key/value
172/// pairs become the arguments of the remark. Returns false, emitting nothing,
173/// when the context has no remark engine, the category is filtered out, or
174/// `kind` is MlirRemarkKindUnknown.
176 MlirLocation location, MlirRemarkKind kind, MlirStringRef remarkName,
177 MlirStringRef categoryName, MlirStringRef subCategoryName,
178 MlirStringRef functionName, MlirStringRef message, intptr_t numArgs,
179 const MlirStringRef *argKeys, const MlirStringRef *argValues);
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif // MLIR_C_REMARKS_H
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetCategoryName(MlirRemark remark)
Returns the category of the remark (the subject of the filters).
Definition Remarks.cpp:169
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetFullCategoryName(MlirRemark remark)
Returns the combined category:subcategory name of the remark.
Definition Remarks.cpp:173
MlirRemarkFileFormat
The serialization format of a remark output file.
Definition Remarks.h:62
@ MlirRemarkFileFormatBitstream
Definition Remarks.h:64
@ MlirRemarkFileFormatYAML
Definition Remarks.h:63
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetRemarkName(MlirRemark remark)
Returns the name identifying the remark.
Definition Remarks.cpp:165
MLIR_CAPI_EXPORTED bool mlirEmitOptimizationRemark(MlirLocation location, MlirRemarkKind kind, MlirStringRef remarkName, MlirStringRef categoryName, MlirStringRef subCategoryName, MlirStringRef functionName, MlirStringRef message, intptr_t numArgs, const MlirStringRef *argKeys, const MlirStringRef *argValues)
Emits a remark of kind at location through the remark engine of the location's context.
Definition Remarks.cpp:217
MLIR_CAPI_EXPORTED MlirRemarkKind mlirRemarkGetKind(MlirRemark remark)
Returns the kind of the remark.
Definition Remarks.cpp:161
MLIR_CAPI_EXPORTED void mlirRemarkPrint(MlirRemark remark, MlirStringCallback callback, void *userData)
Prints the remark in its textual form, [Kind] name | Category:... | / Function=......
Definition Remarks.cpp:207
MLIR_CAPI_EXPORTED MlirLogicalResult mlirContextEnableOptimizationRemarksToFile(MlirContext context, MlirRemarkCategories categories, MlirRemarkPolicy policy, MlirRemarkFileFormat format, MlirStringRef path, bool printAsEmitRemarks)
Enables the remark engine on the context, streaming the reported remarks to the file at path in forma...
Definition Remarks.cpp:116
MLIR_CAPI_EXPORTED intptr_t mlirRemarkGetNumArgs(MlirRemark remark)
Returns the number of key/value arguments attached to the remark.
Definition Remarks.cpp:189
MlirRemarkPolicy
The emitting policy of the remark engine.
Definition Remarks.h:52
@ MlirRemarkPolicyFinal
Postpone remarks and report the final set when the engine is finalized, grouping related remarks unde...
Definition Remarks.h:57
@ MlirRemarkPolicyAll
Report every remark as it is emitted.
Definition Remarks.h:54
MLIR_CAPI_EXPORTED MlirLocation mlirRemarkGetLocation(MlirRemark remark)
Returns the location of the remark.
Definition Remarks.cpp:181
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetArgValue(MlirRemark remark, intptr_t pos)
Returns the value of the pos-th argument of the remark.
Definition Remarks.cpp:200
MLIR_CAPI_EXPORTED bool mlirContextHasRemarkEngine(MlirContext context)
Returns whether the context has a remark engine enabled.
Definition Remarks.cpp:153
MLIR_CAPI_EXPORTED MlirLogicalResult mlirContextEnableOptimizationRemarksWithCallback(MlirContext context, MlirRemarkCategories categories, MlirRemarkPolicy policy, MlirRemarkCallback callback, void *userData, void(*deleteUserData)(void *), bool printAsEmitRemarks)
Enables the remark engine on the context, delivering every reported remark to callback.
Definition Remarks.cpp:128
void(* MlirRemarkCallback)(MlirRemark remark, void *userData)
Callback receiving every remark the engine reports.
Definition Remarks.h:82
MlirRemarkKind
The outcome a remark describes (see mlir::remark::RemarkKind).
Definition Remarks.h:38
@ MlirRemarkKindFailure
The optimization was attempted but failed.
Definition Remarks.h:45
@ MlirRemarkKindAnalysis
Informational context without a pass/fail outcome.
Definition Remarks.h:47
@ MlirRemarkKindMissed
A profitable optimization opportunity was found but not applied.
Definition Remarks.h:43
@ MlirRemarkKindUnknown
Definition Remarks.h:39
@ MlirRemarkKindPassed
An optimization was applied.
Definition Remarks.h:41
MLIR_CAPI_EXPORTED void mlirContextFinalizeOptimizationRemarks(MlirContext context)
Finalizes and removes the remark engine of the context: postponed remarks are reported,...
Definition Remarks.cpp:147
MLIR_CAPI_EXPORTED uint64_t mlirRemarkGetId(MlirRemark remark)
Returns the unique id of the remark within its engine (0 when unset).
Definition Remarks.cpp:185
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetFunctionName(MlirRemark remark)
Returns the name of the function the remark refers to.
Definition Remarks.cpp:177
MLIR_CAPI_EXPORTED MlirLogicalResult mlirContextEnableOptimizationRemarks(MlirContext context, MlirRemarkCategories categories, MlirRemarkPolicy policy, bool printAsEmitRemarks)
Enables the remark engine on the context without a streamer; when printAsEmitRemarks is set,...
Definition Remarks.cpp:105
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetArgKey(MlirRemark remark, intptr_t pos)
Returns the key of the pos-th argument of the remark.
Definition Remarks.cpp:193
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition Support.h:110
A logical result value, essentially a boolean with named states.
Definition Support.h:121
Regular expressions (llvm::Regex syntax, anchored by the engine) selecting the remark categories to r...
Definition Remarks.h:72
MlirStringRef missed
Definition Remarks.h:75
MlirStringRef all
Definition Remarks.h:73
MlirStringRef analysis
Definition Remarks.h:76
MlirStringRef failed
Definition Remarks.h:77
MlirStringRef passed
Definition Remarks.h:74
An opaque reference to a remark.
Definition Remarks.h:32
const void * ptr
Definition Remarks.h:33
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78