[Mlir-commits] [mlir] a623689 - [mlir][bufferization] Check for invalid pass flags instead of failed assertions

Matthias Springer llvmlistbot at llvm.org
Fri Aug 18 06:33:57 PDT 2023


Author: Matthias Springer
Date: 2023-08-18T15:30:32+02:00
New Revision: a623689878923c7c6db0fc9154459cacf425edd3

URL: https://github.com/llvm/llvm-project/commit/a623689878923c7c6db0fc9154459cacf425edd3
DIFF: https://github.com/llvm/llvm-project/commit/a623689878923c7c6db0fc9154459cacf425edd3.diff

LOG: [mlir][bufferization] Check for invalid pass flags instead of failed assertions

Check for invalid pass flags when running `-one-shot-bufferize` instead of crashing with a failed assertion.

This fixes #64267.

Differential Revision: https://reviews.llvm.org/D158162

Added: 
    

Modified: 
    mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 67e749be6d7020..c3950a553d7b5d 100644
--- 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 @@ struct OneShotBufferizePass
       // 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<TensorType>(value.getType());
@@ -248,6 +255,31 @@ struct OneShotBufferizePass
       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 @@ struct OneShotBufferizePass
         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;


        


More information about the Mlir-commits mailing list