diff options
Diffstat (limited to 'mlir/lib/IR/Operation.cpp')
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 96c488cbefe..aa13a71dcfc 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -26,10 +26,22 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/StandardTypes.h" #include "mlir/IR/TypeUtilities.h" +#include "llvm/Support/CommandLine.h" #include <numeric> using namespace mlir; +static llvm::cl::opt<bool> printOpOnDiagnostic( + "mlir-print-op-on-diagnostic", + llvm::cl::desc("When a diagnostic is emitted on an operation, also print " + "the operation as an attached note")); + +OpAsmParser::~OpAsmParser() {} + +//===----------------------------------------------------------------------===// +// OperationName +//===----------------------------------------------------------------------===// + /// Form the OperationName for an op with the specified string. This either is /// a reference to an AbstractOperation if one is known, or a uniqued Identifier /// if not. @@ -60,8 +72,6 @@ OperationName OperationName::getFromOpaquePointer(void *pointer) { return OperationName(RepresentationUnion::getFromOpaqueValue(pointer)); } -OpAsmParser::~OpAsmParser() {} - //===----------------------------------------------------------------------===// // OpResult //===----------------------------------------------------------------------===// @@ -301,27 +311,51 @@ void Operation::replaceUsesOfWith(Value *from, Value *to) { } //===----------------------------------------------------------------------===// -// Other +// Diagnostics //===----------------------------------------------------------------------===// /// Emit an error about fatal conditions with this operation, reporting up to /// any diagnostic handlers that may be listening. InFlightDiagnostic Operation::emitError(const Twine &message) { - return mlir::emitError(getLoc(), message); + InFlightDiagnostic diag = mlir::emitError(getLoc(), message); + if (printOpOnDiagnostic) { + // Print out the operation explicitly here so that we can print the generic + // form. + // TODO(riverriddle) It would be nice if we could instead provide the + // specific printing flags when adding the operation as an argument to the + // diagnostic. + std::string printedOp; + { + llvm::raw_string_ostream os(printedOp); + print(os, OpPrintingFlags().printGenericOpForm().useLocalScope()); + } + diag.attachNote(getLoc()) << "see current operation: " << printedOp; + } + return diag; } /// Emit a warning about this operation, reporting up to any diagnostic /// handlers that may be listening. InFlightDiagnostic Operation::emitWarning(const Twine &message) { - return mlir::emitWarning(getLoc(), message); + InFlightDiagnostic diag = mlir::emitWarning(getLoc(), message); + if (printOpOnDiagnostic) + diag.attachNote(getLoc()) << "see current operation: " << *this; + return diag; } /// Emit a remark about this operation, reporting up to any diagnostic /// handlers that may be listening. InFlightDiagnostic Operation::emitRemark(const Twine &message) { - return mlir::emitRemark(getLoc(), message); + InFlightDiagnostic diag = mlir::emitRemark(getLoc(), message); + if (printOpOnDiagnostic) + diag.attachNote(getLoc()) << "see current operation: " << *this; + return diag; } +//===----------------------------------------------------------------------===// +// Other +//===----------------------------------------------------------------------===// + /// Given an operation 'other' that is within the same parent block, return /// whether the current operation is before 'other' in the operation list /// of the parent block. |

