From 8e2214aa60bc836d263fd7cb61be8f595eb05a37 Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Fri, 26 Nov 2021 11:41:07 +0900 Subject: [PATCH] [mlir][linalg][bufferize][NFC] Pass BufferizationState to PostAnalysisStep Pass BufferizationStep instead of BufferizationAliasInfo. Note: BufferizationState contains BufferizationAliasInfo. Differential Revision: https://reviews.llvm.org/D114512 --- .../ComprehensiveBufferize/BufferizableOpInterface.h | 7 +++---- .../ComprehensiveBufferize/LinalgInterfaceImpl.h | 5 ++--- .../ComprehensiveBufferize.cpp | 2 +- .../ComprehensiveBufferize/LinalgInterfaceImpl.cpp | 12 ++++++------ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h index e03aaea85731..52befbd72605 100644 --- a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h +++ b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/BufferizableOpInterface.h @@ -327,10 +327,9 @@ struct PostAnalysisStep { virtual ~PostAnalysisStep() {} /// Run the post analysis step. This function may modify the IR, but must keep - /// `aliasInfo` consistent. Newly created operations and operations that - /// should be re-analyzed must be stored in `newOps`. - virtual LogicalResult run(FuncOp funcOp, BufferizationAliasInfo &aliasInfo, - DominanceInfo &domInfo, + /// `aliasInfo` (inside `state`) consistent. Newly created operations and + /// operations that should be re-analyzed must be stored in `newOps`. + virtual LogicalResult run(FuncOp funcOp, BufferizationState &state, SmallVector &newOps) = 0; }; diff --git a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.h b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.h index d5ee20bf3392..185878701d71 100644 --- a/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.h +++ b/mlir/include/mlir/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.h @@ -34,7 +34,7 @@ struct InitTensorEliminationStep : public PostAnalysisStep { /// * The result of `rewriteFunc` must usually be analyzed for inplacability. /// This analysis can be skipped with `skipAnalysis`. LogicalResult eliminateInitTensors( - FuncOp funcOp, BufferizationAliasInfo &aliasInfo, DominanceInfo &domInfo, + FuncOp funcOp, BufferizationState &state, std::function anchorMatchFunc, std::function rewriteFunc, SmallVector &newOps); @@ -45,8 +45,7 @@ struct InitTensorEliminationStep : public PostAnalysisStep { /// (and some other conditions are met). struct InsertSliceAnchoredInitTensorEliminationStep : public InitTensorEliminationStep { - LogicalResult run(FuncOp funcOp, BufferizationAliasInfo &aliasInfo, - DominanceInfo &domInfo, + LogicalResult run(FuncOp funcOp, BufferizationState &state, SmallVector &newOps) override; }; diff --git a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp index 53eaab56dc62..eb37a544de60 100644 --- a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp +++ b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ComprehensiveBufferize.cpp @@ -728,7 +728,7 @@ LogicalResult mlir::linalg::comprehensive_bufferize::runComprehensiveBufferize( for (const std::unique_ptr &step : options.postAnalysisSteps) { SmallVector newOps; - if (failed(step->run(funcOp, aliasInfo, domInfo, newOps))) + if (failed(step->run(funcOp, state, newOps))) return failure(); // Analyze ops that were created by the PostAnalysisStep. if (failed(inPlaceAnalysis(newOps, aliasInfo, domInfo))) diff --git a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.cpp index 7bea450c343f..b4a439ec5ad3 100644 --- a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.cpp @@ -407,12 +407,12 @@ struct LinalgOpInterfaceHelper<> { /// OpOperand, that eventually ends at a single InitTensorOp. LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext:: InitTensorEliminationStep::eliminateInitTensors( - FuncOp funcOp, BufferizationAliasInfo &aliasInfo, - DominanceInfo &domInfo, + FuncOp funcOp, BufferizationState &state, std::function anchorMatchFunc, std::function rewriteFunc, SmallVector &newOps) { OpBuilder b(funcOp->getContext()); + BufferizationAliasInfo &aliasInfo = state.aliasInfo; WalkResult status = funcOp->walk([&](Operation *op) { for (OpOperand &operand : op->getOpOperands()) { @@ -501,17 +501,17 @@ LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext:: /// out-of-place due to RaW conflicts. LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext:: InsertSliceAnchoredInitTensorEliminationStep::run( - FuncOp funcOp, BufferizationAliasInfo &aliasInfo, - DominanceInfo &domInfo, SmallVector &newOps) { + FuncOp funcOp, BufferizationState &state, + SmallVector &newOps) { return eliminateInitTensors( - funcOp, aliasInfo, domInfo, + funcOp, state, [&](OpOperand &operand) { auto insertSliceOp = dyn_cast(operand.getOwner()); if (!insertSliceOp) return false; // Only inplace bufferized InsertSliceOps are eligible. - if (!aliasInfo.isInPlace(insertSliceOp->getOpResult(0))) + if (!state.aliasInfo.isInPlace(insertSliceOp->getOpResult(0))) return false; return &operand == &insertSliceOp->getOpOperand(0) /*source*/; },