[mlir][linalg][bufferize][NFC] Pass BufferizationState to PostAnalysisStep

Pass BufferizationStep instead of BufferizationAliasInfo. Note: BufferizationState contains BufferizationAliasInfo.

Differential Revision: https://reviews.llvm.org/D114512
This commit is contained in:
Matthias Springer 2021-11-26 11:41:07 +09:00
parent d62b4b08af
commit 8e2214aa60
4 changed files with 12 additions and 14 deletions

View File

@ -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<Operation *> &newOps) = 0;
};

View File

@ -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<bool(OpOperand &)> anchorMatchFunc,
std::function<Value(OpBuilder &, Location, OpOperand &)> rewriteFunc,
SmallVector<Operation *> &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<Operation *> &newOps) override;
};

View File

@ -728,7 +728,7 @@ LogicalResult mlir::linalg::comprehensive_bufferize::runComprehensiveBufferize(
for (const std::unique_ptr<PostAnalysisStep> &step :
options.postAnalysisSteps) {
SmallVector<Operation *> 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)))

View File

@ -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<bool(OpOperand &)> anchorMatchFunc,
std::function<Value(OpBuilder &, Location, OpOperand &)> rewriteFunc,
SmallVector<Operation *> &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<Operation *> &newOps) {
FuncOp funcOp, BufferizationState &state,
SmallVector<Operation *> &newOps) {
return eliminateInitTensors(
funcOp, aliasInfo, domInfo,
funcOp, state,
[&](OpOperand &operand) {
auto insertSliceOp =
dyn_cast<tensor::InsertSliceOp>(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*/;
},