d09e76c8f9
Validate Operations / validate-operations (push) Has been cancelled
fix reshape lowering add support for grouped-convolution lowering quieter verifier with capped error messages
63 lines
2.2 KiB
C++
63 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "mlir/IR/Diagnostics.h"
|
|
#include "mlir/IR/Operation.h"
|
|
#include "mlir/Support/LogicalResult.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include <cstdint>
|
|
#include <system_error>
|
|
|
|
namespace onnx_mlir::pim {
|
|
|
|
struct CappedDiagnosticReporter {
|
|
explicit CappedDiagnosticReporter(int64_t maxReportedFailures = 8) : maxReportedFailures(maxReportedFailures) {}
|
|
|
|
template <typename EmitFn>
|
|
void report(mlir::Operation* op, EmitFn&& emit) {
|
|
numFailures++;
|
|
if (numFailures <= maxReportedFailures)
|
|
emit(op);
|
|
}
|
|
|
|
void emitSuppressedSummary(mlir::Operation* op, llvm::StringRef failureDescription) const {
|
|
if (numFailures > maxReportedFailures)
|
|
op->emitError() << "suppressed " << (numFailures - maxReportedFailures) << " additional "
|
|
<< failureDescription;
|
|
}
|
|
|
|
bool hasFailure() const { return numFailures != 0; }
|
|
|
|
private:
|
|
int64_t maxReportedFailures;
|
|
int64_t numFailures = 0;
|
|
};
|
|
|
|
/// Emits a consistent diagnostic for target paths that require static shapes.
|
|
mlir::InFlightDiagnostic emitUnsupportedStaticShapeDiagnostic(mlir::Operation* op, llvm::StringRef valueDescription);
|
|
|
|
/// Emits a consistent diagnostic for unsupported ranks while listing the ranks
|
|
/// accepted by the current lowering/codegen path.
|
|
mlir::InFlightDiagnostic emitUnsupportedRankDiagnostic(mlir::Operation* op,
|
|
llvm::StringRef valueDescription,
|
|
int64_t actualRank,
|
|
llvm::ArrayRef<int64_t> supportedRanks);
|
|
|
|
/// Emits a consistent diagnostic for missing symbol/global references.
|
|
mlir::InFlightDiagnostic
|
|
emitMissingSymbolDiagnostic(mlir::Operation* op, llvm::StringRef symbolKind, llvm::StringRef symbolName);
|
|
|
|
/// Converts a filesystem error into an MLIR failure diagnostic anchored at
|
|
/// the relevant IR location.
|
|
mlir::LogicalResult
|
|
emitFileSystemError(mlir::Location loc, llvm::StringRef action, llvm::StringRef path, const std::error_code& errorCode);
|
|
|
|
template <typename T>
|
|
mlir::LogicalResult failureOrToLogicalResult(const llvm::FailureOr<T>& value) {
|
|
return mlir::success(succeeded(value));
|
|
}
|
|
|
|
} // namespace onnx_mlir::pim
|