MLIR
24.0.0git
include
mlir-c
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
23
extern
"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.
32
struct
MlirRemark
{
33
const
void
*
ptr
;
34
};
35
typedef
struct
MlirRemark
MlirRemark
;
36
37
/// The outcome a remark describes (see mlir::remark::RemarkKind).
38
enum
MlirRemarkKind
{
39
MlirRemarkKindUnknown
,
40
/// An optimization was applied.
41
MlirRemarkKindPassed
,
42
/// A profitable optimization opportunity was found but not applied.
43
MlirRemarkKindMissed
,
44
/// The optimization was attempted but failed.
45
MlirRemarkKindFailure
,
46
/// Informational context without a pass/fail outcome.
47
MlirRemarkKindAnalysis
48
};
49
typedef
enum
MlirRemarkKind
MlirRemarkKind
;
50
51
/// The emitting policy of the remark engine.
52
enum
MlirRemarkPolicy
{
53
/// Report every remark as it is emitted.
54
MlirRemarkPolicyAll
,
55
/// Postpone remarks and report the final set when the engine is finalized,
56
/// grouping related remarks under their parents.
57
MlirRemarkPolicyFinal
58
};
59
typedef
enum
MlirRemarkPolicy
MlirRemarkPolicy
;
60
61
/// The serialization format of a remark output file.
62
enum
MlirRemarkFileFormat
{
63
MlirRemarkFileFormatYAML
,
64
MlirRemarkFileFormatBitstream
65
};
66
typedef
enum
MlirRemarkFileFormat
MlirRemarkFileFormat
;
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.
72
struct
MlirRemarkCategories
{
73
MlirStringRef
all
;
74
MlirStringRef
passed
;
75
MlirStringRef
missed
;
76
MlirStringRef
analysis
;
77
MlirStringRef
failed
;
78
};
79
typedef
struct
MlirRemarkCategories
MlirRemarkCategories
;
80
81
/// Callback receiving every remark the engine reports.
82
typedef
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).
92
MLIR_CAPI_EXPORTED
MlirLogicalResult
mlirContextEnableOptimizationRemarks
(
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.
100
MLIR_CAPI_EXPORTED
MlirLogicalResult
mlirContextEnableOptimizationRemarksToFile
(
101
MlirContext context,
MlirRemarkCategories
categories,
102
MlirRemarkPolicy
policy,
MlirRemarkFileFormat
format,
MlirStringRef
path,
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.
109
MLIR_CAPI_EXPORTED
MlirLogicalResult
110
mlirContextEnableOptimizationRemarksWithCallback
(
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.
118
MLIR_CAPI_EXPORTED
void
119
mlirContextFinalizeOptimizationRemarks
(MlirContext context);
120
121
/// Returns whether the context has a remark engine enabled.
122
MLIR_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.
129
MLIR_CAPI_EXPORTED
MlirRemarkKind
mlirRemarkGetKind
(
MlirRemark
remark);
130
131
/// Returns the name identifying the remark.
132
MLIR_CAPI_EXPORTED
MlirStringRef
mlirRemarkGetRemarkName
(
MlirRemark
remark);
133
134
/// Returns the category of the remark (the subject of the filters).
135
MLIR_CAPI_EXPORTED
MlirStringRef
mlirRemarkGetCategoryName
(
MlirRemark
remark);
136
137
/// Returns the combined `category:subcategory` name of the remark.
138
MLIR_CAPI_EXPORTED
MlirStringRef
139
mlirRemarkGetFullCategoryName
(
MlirRemark
remark);
140
141
/// Returns the name of the function the remark refers to.
142
MLIR_CAPI_EXPORTED
MlirStringRef
mlirRemarkGetFunctionName
(
MlirRemark
remark);
143
144
/// Returns the location of the remark.
145
MLIR_CAPI_EXPORTED
MlirLocation
mlirRemarkGetLocation
(
MlirRemark
remark);
146
147
/// Returns the unique id of the remark within its engine (0 when unset).
148
MLIR_CAPI_EXPORTED
uint64_t
mlirRemarkGetId
(
MlirRemark
remark);
149
150
/// Returns the number of key/value arguments attached to the remark.
151
MLIR_CAPI_EXPORTED
intptr_t
mlirRemarkGetNumArgs
(
MlirRemark
remark);
152
153
/// Returns the key of the `pos`-th argument of the remark.
154
MLIR_CAPI_EXPORTED
MlirStringRef
mlirRemarkGetArgKey
(
MlirRemark
remark,
155
intptr_t
pos);
156
157
/// Returns the value of the `pos`-th argument of the remark.
158
MLIR_CAPI_EXPORTED
MlirStringRef
mlirRemarkGetArgValue
(
MlirRemark
remark,
159
intptr_t
pos);
160
161
/// Prints the remark in its textual form, `[Kind] name | Category:... |
162
/// Function=... | key=value, ...` (without its location).
163
MLIR_CAPI_EXPORTED
void
164
mlirRemarkPrint
(
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.
175
MLIR_CAPI_EXPORTED
bool
mlirEmitOptimizationRemark
(
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
intptr_t
void
IR.h
mlirRemarkGetCategoryName
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetCategoryName(MlirRemark remark)
Returns the category of the remark (the subject of the filters).
Definition
Remarks.cpp:169
mlirRemarkGetFullCategoryName
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetFullCategoryName(MlirRemark remark)
Returns the combined category:subcategory name of the remark.
Definition
Remarks.cpp:173
MlirRemarkFileFormat
MlirRemarkFileFormat
The serialization format of a remark output file.
Definition
Remarks.h:62
MlirRemarkFileFormatBitstream
@ MlirRemarkFileFormatBitstream
Definition
Remarks.h:64
MlirRemarkFileFormatYAML
@ MlirRemarkFileFormatYAML
Definition
Remarks.h:63
mlirRemarkGetRemarkName
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetRemarkName(MlirRemark remark)
Returns the name identifying the remark.
Definition
Remarks.cpp:165
mlirEmitOptimizationRemark
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
mlirRemarkGetKind
MLIR_CAPI_EXPORTED MlirRemarkKind mlirRemarkGetKind(MlirRemark remark)
Returns the kind of the remark.
Definition
Remarks.cpp:161
mlirRemarkPrint
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
mlirContextEnableOptimizationRemarksToFile
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
mlirRemarkGetNumArgs
MLIR_CAPI_EXPORTED intptr_t mlirRemarkGetNumArgs(MlirRemark remark)
Returns the number of key/value arguments attached to the remark.
Definition
Remarks.cpp:189
MlirRemarkPolicy
MlirRemarkPolicy
The emitting policy of the remark engine.
Definition
Remarks.h:52
MlirRemarkPolicyFinal
@ MlirRemarkPolicyFinal
Postpone remarks and report the final set when the engine is finalized, grouping related remarks unde...
Definition
Remarks.h:57
MlirRemarkPolicyAll
@ MlirRemarkPolicyAll
Report every remark as it is emitted.
Definition
Remarks.h:54
mlirRemarkGetLocation
MLIR_CAPI_EXPORTED MlirLocation mlirRemarkGetLocation(MlirRemark remark)
Returns the location of the remark.
Definition
Remarks.cpp:181
mlirRemarkGetArgValue
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
mlirContextHasRemarkEngine
MLIR_CAPI_EXPORTED bool mlirContextHasRemarkEngine(MlirContext context)
Returns whether the context has a remark engine enabled.
Definition
Remarks.cpp:153
mlirContextEnableOptimizationRemarksWithCallback
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
MlirRemarkCallback
void(* MlirRemarkCallback)(MlirRemark remark, void *userData)
Callback receiving every remark the engine reports.
Definition
Remarks.h:82
MlirRemarkKind
MlirRemarkKind
The outcome a remark describes (see mlir::remark::RemarkKind).
Definition
Remarks.h:38
MlirRemarkKindFailure
@ MlirRemarkKindFailure
The optimization was attempted but failed.
Definition
Remarks.h:45
MlirRemarkKindAnalysis
@ MlirRemarkKindAnalysis
Informational context without a pass/fail outcome.
Definition
Remarks.h:47
MlirRemarkKindMissed
@ MlirRemarkKindMissed
A profitable optimization opportunity was found but not applied.
Definition
Remarks.h:43
MlirRemarkKindUnknown
@ MlirRemarkKindUnknown
Definition
Remarks.h:39
MlirRemarkKindPassed
@ MlirRemarkKindPassed
An optimization was applied.
Definition
Remarks.h:41
mlirContextFinalizeOptimizationRemarks
MLIR_CAPI_EXPORTED void mlirContextFinalizeOptimizationRemarks(MlirContext context)
Finalizes and removes the remark engine of the context: postponed remarks are reported,...
Definition
Remarks.cpp:147
mlirRemarkGetId
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
mlirRemarkGetFunctionName
MLIR_CAPI_EXPORTED MlirStringRef mlirRemarkGetFunctionName(MlirRemark remark)
Returns the name of the function the remark refers to.
Definition
Remarks.cpp:177
mlirContextEnableOptimizationRemarks
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
mlirRemarkGetArgKey
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
Support.h
MLIR_CAPI_EXPORTED
#define MLIR_CAPI_EXPORTED
Definition
Support.h:46
MlirStringCallback
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition
Support.h:110
MlirLogicalResult
A logical result value, essentially a boolean with named states.
Definition
Support.h:121
MlirRemarkCategories
Regular expressions (llvm::Regex syntax, anchored by the engine) selecting the remark categories to r...
Definition
Remarks.h:72
MlirRemarkCategories::missed
MlirStringRef missed
Definition
Remarks.h:75
MlirRemarkCategories::all
MlirStringRef all
Definition
Remarks.h:73
MlirRemarkCategories::analysis
MlirStringRef analysis
Definition
Remarks.h:76
MlirRemarkCategories::failed
MlirStringRef failed
Definition
Remarks.h:77
MlirRemarkCategories::passed
MlirStringRef passed
Definition
Remarks.h:74
MlirRemark
An opaque reference to a remark.
Definition
Remarks.h:32
MlirRemark::ptr
const void * ptr
Definition
Remarks.h:33
MlirStringRef
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition
Support.h:78
Generated on
for MLIR by
1.14.0