Enhance MLIRContext and operations with the ability to register diagnostic
handlers and to feed them with errors and warnings produced by the compiler.
Enhance Operation to be able to get its own MLIRContext on demand, simplifying
some clients. Change the verifier to emit certain errors with the diagnostic
handler.
This is steps towards reworking the verifier and diagnostic propagation but is
itself not particularly useful. More to come.
PiperOrigin-RevId: 206948643
diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp
index 9e52556..6eb7a68 100644
--- a/lib/IR/Verifier.cpp
+++ b/lib/IR/Verifier.cpp
@@ -73,6 +73,11 @@
return true;
}
+ bool opFailure(const Twine &message, const Operation &value) {
+ value.emitError(message);
+ return true;
+ }
+
protected:
explicit Verifier(std::string *errorResult) : errorResult(errorResult) {}
@@ -272,15 +277,15 @@
bool CFGFuncVerifier::verifyOperation(const OperationInst &inst) {
if (inst.getFunction() != &fn)
- return failure("operation in the wrong function", inst);
+ return opFailure("operation in the wrong function", inst);
// TODO: Check that operands are structurally ok.
// See if we can get operation info for this.
- if (auto *opInfo = inst.getAbstractOperation(fn.getContext())) {
+ if (auto *opInfo = inst.getAbstractOperation()) {
if (auto errorMessage = opInfo->verifyInvariants(&inst))
- return failure(Twine("'") + inst.getName().str() + "' op " + errorMessage,
- inst);
+ return opFailure(
+ Twine("'") + inst.getName().str() + "' op " + errorMessage, inst);
}
return false;