66 PyRemarkPolicy policy,
const std::optional<std::string> &outputFile,
68 const std::string &passedFilter,
const std::string &missedFilter,
69 const std::string &analysisFilter,
const std::string &failedFilter,
70 nb::object callback, std::optional<bool> printAsEmitRemarks) {
71 bool hasCallback = !callback.is_none();
72 if (outputFile && hasCallback)
73 throw nb::value_error(
74 "a remark callback cannot be combined with an output file");
76 throw nb::value_error(
"remarks are already enabled on this context; call "
77 "finalize_remarks() first");
87 printAsEmitRemarks.value_or(!outputFile.has_value() && !hasCallback);
92 get(), categories, remarkPolicy,
96 throw nb::value_error(
97 (
"failed to enable remarks: cannot write '" + *outputFile +
"'")
99 }
else if (hasCallback) {
100 auto *data =
new PyRemarkCallbackData{
get(), std::move(callback)};
106 remarkPolicy, printAsEmit);
109 throw nb::value_error(
"failed to enable remarks");
Wrapper around an MlirLocation.
nanobind::typed< nanobind::object, PyLocation > maybeDownCast()
Returns the most-derived Location subclass registered for this TypeID, or self.
static PyMlirContextRef forContext(MlirContext context)
Returns a context reference for the singleton PyMlirContext wrapper for the given context.
static bool isLiveContext(MlirContext context)
Whether context still has a live Python wrapper (false while it is being destroyed).
bool getRemarksEnabled()
Whether a remark engine is enabled on the context.
void enableRemarks(PyRemarkPolicy policy, const std::optional< std::string > &outputFile, PyRemarkFormat format, const std::string &allFilter, const std::string &passedFilter, const std::string &missedFilter, const std::string &analysisFilter, const std::string &failedFilter, nanobind::object callback, std::optional< bool > printAsEmitRemarks)
Enables the optimization remark engine of the context, streaming to outputFile, to callback,...
MlirContext get()
Accesses the underlying MlirContext.
void finalizeRemarks()
Finalizes and removes the remark engine; no-op when none is enabled.
Wrapper around an MlirRemark as delivered to a remark callback.
nanobind::typed< nanobind::object, PyLocation > getLocation() const
PyRemarkKind getKind() const
nanobind::str getFunctionName() const
nanobind::str getMessage() const
The textual form of the remark, without its location.
nanobind::str getRemarkName() const
nanobind::str getFullCategoryName() const
nanobind::str getCategoryName() const
nanobind::list getArgs() const
The key/value arguments as a list of (key, value) tuples.
MLIR_PYTHON_API_EXPORTED void populateIRRemarks(nanobind::module_ &m)
static nb::str remarkStr(MlirStringRef ref)
MlirStringRef toMlirStringRef(const std::string &s)
PyRemarkKind
The kinds, emitting policies and file formats of the remark engine (mlir-c/Remarks....
static void pyRemarkCallback(MlirRemark remark, void *userData)
Forwards a reported remark to the Python callable in userData; the PyRemark is invalidated once the c...
static void pyRemarkCallbackDelete(void *userData)