"Allows the return of memrefs (for testing purposes only)">,
Option<"useAlloca", "use-alloca", "bool",
/*default=*/"false",
- "Use stack allocations for memrefs (for testing purposes only)">
+ "Use stack allocations for memrefs (for testing purposes only)">,
+ Option<"analysisFuzzerSeed", "analysis-fuzzer-seed", "unsigned",
+ /*default=*/"0",
+ "Analyze ops in random order with a given seed (fuzzer)">
];
let constructor = "mlir::createLinalgComprehensiveModuleBufferizePass()";
}
/// Analyze the `ops` to determine which OpResults are inplaceable.
LogicalResult inPlaceAnalysis(SmallVector<Operation *> &ops,
BufferizationAliasInfo &aliasInfo,
- const DominanceInfo &domInfo);
+ const DominanceInfo &domInfo,
+ unsigned analysisFuzzerSeed = 0);
/// Default allocation function that is used by the comprehensive bufferization
/// pass. The default currently creates a ranked memref using `memref.alloc`.
#include "mlir/Dialect/Linalg/Transforms/ComprehensiveBufferize.h"
+#include <random>
+
#include "PassDetail.h"
#include "mlir/Dialect/Linalg/IR/LinalgOps.h"
#include "mlir/Dialect/Linalg/Passes.h"
/// ExtractSliceOps are interleaved with other ops in traversal order.
LogicalResult mlir::linalg::inPlaceAnalysis(SmallVector<Operation *> &ops,
BufferizationAliasInfo &aliasInfo,
- const DominanceInfo &domInfo) {
+ const DominanceInfo &domInfo,
+ unsigned analysisFuzzerSeed) {
+ if (analysisFuzzerSeed) {
+ // This is a fuzzer. For testing purposes only. Randomize the order in which
+ // operations are analyzed. The bufferization quality is likely worse, but
+ // we want to make sure that no assertions are triggered anywhere.
+ std::mt19937 g(analysisFuzzerSeed);
+ llvm::shuffle(ops.begin(), ops.end(), g);
+ }
+
// Walk ops in reverse for better interference analysis.
for (Operation *op : reverse(ops)) {
for (OpOperand &opOperand : op->getOpOperands())
/// Analyze the `funcOp` body to determine which OpResults are inplaceable.
static LogicalResult
inPlaceAnalysisFuncOpBody(FuncOp funcOp, BufferizationAliasInfo &aliasInfo,
- const DominanceInfo &domInfo) {
+ const DominanceInfo &domInfo,
+ unsigned analysisFuzzerSeed = 0) {
LLVM_DEBUG(llvm::dbgs() << "\n\n");
LDBG("Begin InPlaceAnalysisFuncOpInternals:\n" << funcOp << '\n');
assert(funcOp && funcOp->getNumRegions() > 0 && !funcOp.body().empty() &&
aliasInfo.setBufferizesToWritableMemory(bbArg);
}
- LogicalResult res = inPlaceAnalysis(ops, aliasInfo, domInfo);
+ LogicalResult res =
+ inPlaceAnalysis(ops, aliasInfo, domInfo, analysisFuzzerSeed);
LDBG("End InPlaceAnalysisFuncOpInternals:\n" << funcOp << '\n');
return res;
setInPlaceFuncArgument(bbArg);
// If the analysis fails, just return.
- if (failed(inPlaceAnalysisFuncOpBody(funcOp, aliasInfo, domInfo))) {
+ if (failed(inPlaceAnalysisFuncOpBody(funcOp, aliasInfo, domInfo,
+ analysisFuzzerSeed))) {
signalPassFailure();
return;
}
// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize=test-analysis-only -split-input-file | FileCheck %s
+// Run fuzzer with different seeds.
+// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize="test-analysis-only analysis-fuzzer-seed=23" -split-input-file -o /dev/null
+// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize="test-analysis-only analysis-fuzzer-seed=59" -split-input-file -o /dev/null
+// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize="test-analysis-only analysis-fuzzer-seed=91" -split-input-file -o /dev/null
+
//===----------------------------------------------------------------------===//
// Simple cases
//===----------------------------------------------------------------------===//
// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize=allow-return-memref -split-input-file | FileCheck %s
+// Run fuzzer with different seeds.
+// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize="test-analysis-only analysis-fuzzer-seed=23" -split-input-file -o /dev/null
+// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize="test-analysis-only analysis-fuzzer-seed=59" -split-input-file -o /dev/null
+// RUN: mlir-opt %s -linalg-comprehensive-module-bufferize="test-analysis-only analysis-fuzzer-seed=91" -split-input-file -o /dev/null
+
// CHECK-LABEL: func @transfer_read(%{{.*}}: memref<?xf32, #map>) -> vector<4xf32> {
func @transfer_read(%A : tensor<?xf32>) -> (vector<4xf32>) {
%c0 = arith.constant 0 : index