diff options
| author | River Riddle <riverriddle@google.com> | 2019-05-03 10:01:01 -0700 |
|---|---|---|
| committer | Mehdi Amini <joker.eph@gmail.com> | 2019-05-06 08:26:34 -0700 |
| commit | ff6e7cf558135055f65202f73a0c06db7a53e77d (patch) | |
| tree | 1bf545d82cbb014499443e3e3da002195486c771 /mlir/lib/IR/Operation.cpp | |
| parent | 8c9fbb7eb833cd0f51cb2f02f0500aec481e8c30 (diff) | |
| download | bcm5719-llvm-ff6e7cf558135055f65202f73a0c06db7a53e77d.tar.gz bcm5719-llvm-ff6e7cf558135055f65202f73a0c06db7a53e77d.zip | |
Introduce a new API for emitting diagnostics with Diagnostic and InFlightDiagnostic.
The Diagnostic class contains all of the information necessary to report a diagnostic to the DiagnosticEngine. It should generally not be constructed directly, and instead used transitively via InFlightDiagnostic. A diagnostic is currently comprised of several different elements:
* A severity level.
* A source Location.
* A list of DiagnosticArguments that help compose and comprise the output message.
* A DiagnosticArgument represents any value that may be part of the diagnostic, e.g. string, integer, Type, Attribute, etc.
* Arguments can be added to the diagnostic via the stream(<<) operator.
* (In a future cl) A list of attached notes.
* These are in the form of other diagnostics that provide supplemental information to the main diagnostic, but do not have context on their own.
The InFlightDiagnostic class represents an RAII wrapper around a Diagnostic that is set to be reported with the diagnostic engine. This allows for the user to modify a diagnostic that is inflight. The internally wrapped diagnostic can be reported directly or automatically upon destruction.
These classes allow for more natural composition of diagnostics by removing the restriction that the message of a diagnostic is comprised of a single Twine. They should also allow for nice incremental improvements to the diagnostics experience in the future, e.g. formatv style diagnostics.
Simple Example:
emitError(loc, "integer bitwidth is limited to " + Twine(IntegerType::kMaxWidth) + " bits");
emitError(loc) << "integer bitwidth is limited to " << IntegerType::kMaxWidth << " bits";
--
PiperOrigin-RevId: 246526439
Diffstat (limited to 'mlir/lib/IR/Operation.cpp')
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 1a0aaa526c1..da02c58d366 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -307,30 +307,29 @@ void Operation::walk(const std::function<void(Operation *)> &callback) { /// Emit a remark about this operation, reporting up to any diagnostic /// handlers that may be listening. -void Operation::emitRemark(const Twine &message) { - getContext()->emitRemark(getLoc(), message); +InFlightDiagnostic Operation::emitRemark(const Twine &message) { + return getContext()->emitRemark(getLoc(), message); } /// Emit a note about this operation, reporting up to any diagnostic /// handlers that may be listening. -void Operation::emitNote(const Twine &message) { - getContext()->getDiagEngine().emit(getLoc(), message, - DiagnosticSeverity::Note); +InFlightDiagnostic Operation::emitNote(const Twine &message) { + return getContext()->getDiagEngine().emit(getLoc(), DiagnosticSeverity::Note) + << message; } /// Emit a warning about this operation, reporting up to any diagnostic /// handlers that may be listening. -void Operation::emitWarning(const Twine &message) { - getContext()->getDiagEngine().emit(getLoc(), message, - DiagnosticSeverity::Warning); +InFlightDiagnostic Operation::emitWarning(const Twine &message) { + return getContext()->getDiagEngine().emit(getLoc(), + DiagnosticSeverity::Warning) + << message; } /// Emit an error about fatal conditions with this operation, reporting up to -/// any diagnostic handlers that may be listening. This function always -/// returns failure. NOTE: This may terminate the containing application, only -/// use when the IR is in an inconsistent state. -LogicalResult Operation::emitError(const Twine &message) { - return getContext()->emitError(getLoc(), message), failure(); +/// any diagnostic handlers that may be listening. +InFlightDiagnostic Operation::emitError(const Twine &message) { + return getContext()->emitError(getLoc(), message); } /// Given an operation 'other' that is within the same parent block, return @@ -551,7 +550,7 @@ LogicalResult Operation::fold(SmallVectorImpl<Value *> &results) { /// Emit an error with the op name prefixed, like "'dim' op " which is /// convenient for verifiers. -LogicalResult Operation::emitOpError(const Twine &message) { +InFlightDiagnostic Operation::emitOpError(const Twine &message) { return emitError(Twine('\'') + getName().getStringRef() + "' op " + message); } @@ -652,35 +651,33 @@ bool OpState::parse(OpAsmParser *parser, OperationState *result) { void OpState::print(OpAsmPrinter *p) { p->printGenericOp(getOperation()); } /// Emit an error about fatal conditions with this operation, reporting up to -/// any diagnostic handlers that may be listening. NOTE: This may terminate -/// the containing application, only use when the IR is in an inconsistent -/// state. -LogicalResult OpState::emitError(const Twine &message) { +/// any diagnostic handlers that may be listening. +InFlightDiagnostic OpState::emitError(const Twine &message) { return getOperation()->emitError(message); } /// Emit an error with the op name prefixed, like "'dim' op " which is /// convenient for verifiers. -LogicalResult OpState::emitOpError(const Twine &message) { +InFlightDiagnostic OpState::emitOpError(const Twine &message) { return getOperation()->emitOpError(message); } /// Emit a warning about this operation, reporting up to any diagnostic /// handlers that may be listening. -void OpState::emitWarning(const Twine &message) { - getOperation()->emitWarning(message); +InFlightDiagnostic OpState::emitWarning(const Twine &message) { + return getOperation()->emitWarning(message); } /// Emit a note about this operation, reporting up to any diagnostic /// handlers that may be listening. -void OpState::emitNote(const Twine &message) { - getOperation()->emitNote(message); +InFlightDiagnostic OpState::emitNote(const Twine &message) { + return getOperation()->emitNote(message); } /// Emit a remark about this operation, reporting up to any diagnostic /// handlers that may be listening. -void OpState::emitRemark(const Twine &message) { - getOperation()->emitRemark(message); +InFlightDiagnostic OpState::emitRemark(const Twine &message) { + return getOperation()->emitRemark(message); } //===----------------------------------------------------------------------===// |

