diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp --- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp @@ -16,6 +16,7 @@ #include "mlir/Dialect/Bufferization/Transforms/Transforms.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/IR/Diagnostics.h" #include "mlir/IR/Operation.h" #include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Pass/PassManager.h" @@ -221,6 +222,12 @@ // Configure type converter. LayoutMapOption unknownTypeConversionOption = parseLayoutMapOption(unknownTypeConversion); + if (unknownTypeConversionOption == LayoutMapOption::InferLayoutMap) { + emitError(UnknownLoc::get(&getContext()), + "Invalid option: 'infer-layout-map' is not a valid value for " + "'unknown-type-conversion'"); + return signalPassFailure(); + } opt.unknownTypeConverterFn = [=](Value value, Attribute memorySpace, const BufferizationOptions &options) { auto tensorType = cast(value.getType()); @@ -248,6 +255,31 @@ opt = *options; } + if (opt.copyBeforeWrite && opt.testAnalysisOnly) { + // These two flags do not make sense together: "copy-before-write" + // indicates that copies should be inserted before every memory write, + // but "test-analysis-only" indicates that only the analysis should be + // tested. (I.e., no IR is bufferized.) + emitError(UnknownLoc::get(&getContext()), + "Invalid option: 'copy-before-write' cannot be used with " + "'test-analysis-only'"); + return signalPassFailure(); + } + + if (opt.printConflicts && !opt.testAnalysisOnly) { + emitError( + UnknownLoc::get(&getContext()), + "Invalid option: 'print-conflicts' requires 'test-analysis-only'"); + return signalPassFailure(); + } + + if (opt.dumpAliasSets && !opt.testAnalysisOnly) { + emitError( + UnknownLoc::get(&getContext()), + "Invalid option: 'dump-alias-sets' requires 'test-analysis-only'"); + return signalPassFailure(); + } + BufferizationStatistics statistics; ModuleOp moduleOp = getOperation(); if (opt.bufferizeFunctionBoundaries) { @@ -256,8 +288,12 @@ return; } } else { - assert(opt.noAnalysisFuncFilter.empty() && - "invalid combination of bufferization flags"); + if (!opt.noAnalysisFuncFilter.empty()) { + emitError(UnknownLoc::get(&getContext()), + "Invalid option: 'no-analysis-func-filter' requires " + "'bufferize-function-boundaries'"); + return signalPassFailure(); + } if (failed(runOneShotBufferize(moduleOp, opt, &statistics))) { signalPassFailure(); return;