#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.
return OperationName(RepresentationUnion::getFromOpaqueValue(pointer));
}
-OpAsmParser::~OpAsmParser() {}
-
//===----------------------------------------------------------------------===//
// OpResult
//===----------------------------------------------------------------------===//
}
//===----------------------------------------------------------------------===//
-// 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.
/// Get the canonical string name of the dialect.
static StringRef getDialectName() { return "test"; }
- LogicalResult verifyRegionArgAttribute(Operation *, unsigned regionIndex,
+ LogicalResult verifyOperationAttribute(Operation *op,
+ NamedAttribute namedAttr) override;
+ LogicalResult verifyRegionArgAttribute(Operation *op, unsigned regionIndex,
unsigned argIndex,
- NamedAttribute) override;
-
- LogicalResult verifyRegionResultAttribute(Operation *, unsigned regionIndex,
+ NamedAttribute namedAttr) override;
+ LogicalResult verifyRegionResultAttribute(Operation *op, unsigned regionIndex,
unsigned resultIndex,
- NamedAttribute) override;
+ NamedAttribute namedAttr) override;
};
#define GET_OP_CLASSES