Finish support for function attributes, and improve lots of things:
- Have the parser rewrite forward references to their resolved values at the
end of parsing.
- Implement verifier support for detecting malformed function attrs.
- Add efficient query for (in general, recursive) attributes to tell if they
contain a function.
As part of this, improve other general infrastructure:
- Implement support for verifying OperationStmt's in ml functions, refactoring
and generalizing support for operations in the verifier.
- Refactor location handling code in mlir-opt to have the non-error expecting
form of mlir-opt invocations to report error locations precisely.
- Fix parser to detect verifier failures and report them through errorReporter
instead of printing the error and crashing.
This regresses the location info for verifier errors in the parser that were
previously ascribed to the function. This will get resolved in future patches
by adding support for function attributes, which we can use to manage location
information.
PiperOrigin-RevId: 209600980
diff --git a/lib/IR/MLIRContext.cpp b/lib/IR/MLIRContext.cpp
index a960223..68839d8 100644
--- a/lib/IR/MLIRContext.cpp
+++ b/lib/IR/MLIRContext.cpp
@@ -285,6 +285,11 @@
getImpl().diagnosticHandler = handler;
}
+/// Return the current diagnostic handler, or null if none is present.
+auto MLIRContext::getDiagnosticHandler() const -> DiagnosticHandlerTy {
+ return getImpl().diagnosticHandler;
+}
+
/// This emits a diagnostic using the registered issue handle if present, or
/// with the default behavior if not. The MLIR compiler should not generally
/// interact with this, it should use methods on Operation instead.
@@ -608,8 +613,16 @@
// Copy the elements into the bump pointer.
value = impl.copyInto(value);
+ // Check to see if any of the elements have a function attr.
+ bool hasFunctionAttr = false;
+ for (auto *elt : value)
+ if (elt->isOrContainsFunction()) {
+ hasFunctionAttr = true;
+ break;
+ }
+
// Initialize the memory using placement new.
- new (result) ArrayAttr(value);
+ new (result) ArrayAttr(value, hasFunctionAttr);
// Cache and return it.
return *existing.first = result;