forked from OSchip/llvm-project
[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:
parent
d62b4b08af
commit
8e2214aa60
|
@ -327,10 +327,9 @@ struct PostAnalysisStep {
|
||||||
virtual ~PostAnalysisStep() {}
|
virtual ~PostAnalysisStep() {}
|
||||||
|
|
||||||
/// Run the post analysis step. This function may modify the IR, but must keep
|
/// Run the post analysis step. This function may modify the IR, but must keep
|
||||||
/// `aliasInfo` consistent. Newly created operations and operations that
|
/// `aliasInfo` (inside `state`) consistent. Newly created operations and
|
||||||
/// should be re-analyzed must be stored in `newOps`.
|
/// operations that should be re-analyzed must be stored in `newOps`.
|
||||||
virtual LogicalResult run(FuncOp funcOp, BufferizationAliasInfo &aliasInfo,
|
virtual LogicalResult run(FuncOp funcOp, BufferizationState &state,
|
||||||
DominanceInfo &domInfo,
|
|
||||||
SmallVector<Operation *> &newOps) = 0;
|
SmallVector<Operation *> &newOps) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ struct InitTensorEliminationStep : public PostAnalysisStep {
|
||||||
/// * The result of `rewriteFunc` must usually be analyzed for inplacability.
|
/// * The result of `rewriteFunc` must usually be analyzed for inplacability.
|
||||||
/// This analysis can be skipped with `skipAnalysis`.
|
/// This analysis can be skipped with `skipAnalysis`.
|
||||||
LogicalResult eliminateInitTensors(
|
LogicalResult eliminateInitTensors(
|
||||||
FuncOp funcOp, BufferizationAliasInfo &aliasInfo, DominanceInfo &domInfo,
|
FuncOp funcOp, BufferizationState &state,
|
||||||
std::function<bool(OpOperand &)> anchorMatchFunc,
|
std::function<bool(OpOperand &)> anchorMatchFunc,
|
||||||
std::function<Value(OpBuilder &, Location, OpOperand &)> rewriteFunc,
|
std::function<Value(OpBuilder &, Location, OpOperand &)> rewriteFunc,
|
||||||
SmallVector<Operation *> &newOps);
|
SmallVector<Operation *> &newOps);
|
||||||
|
@ -45,8 +45,7 @@ struct InitTensorEliminationStep : public PostAnalysisStep {
|
||||||
/// (and some other conditions are met).
|
/// (and some other conditions are met).
|
||||||
struct InsertSliceAnchoredInitTensorEliminationStep
|
struct InsertSliceAnchoredInitTensorEliminationStep
|
||||||
: public InitTensorEliminationStep {
|
: public InitTensorEliminationStep {
|
||||||
LogicalResult run(FuncOp funcOp, BufferizationAliasInfo &aliasInfo,
|
LogicalResult run(FuncOp funcOp, BufferizationState &state,
|
||||||
DominanceInfo &domInfo,
|
|
||||||
SmallVector<Operation *> &newOps) override;
|
SmallVector<Operation *> &newOps) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -728,7 +728,7 @@ LogicalResult mlir::linalg::comprehensive_bufferize::runComprehensiveBufferize(
|
||||||
for (const std::unique_ptr<PostAnalysisStep> &step :
|
for (const std::unique_ptr<PostAnalysisStep> &step :
|
||||||
options.postAnalysisSteps) {
|
options.postAnalysisSteps) {
|
||||||
SmallVector<Operation *> newOps;
|
SmallVector<Operation *> newOps;
|
||||||
if (failed(step->run(funcOp, aliasInfo, domInfo, newOps)))
|
if (failed(step->run(funcOp, state, newOps)))
|
||||||
return failure();
|
return failure();
|
||||||
// Analyze ops that were created by the PostAnalysisStep.
|
// Analyze ops that were created by the PostAnalysisStep.
|
||||||
if (failed(inPlaceAnalysis(newOps, aliasInfo, domInfo)))
|
if (failed(inPlaceAnalysis(newOps, aliasInfo, domInfo)))
|
||||||
|
|
|
@ -407,12 +407,12 @@ struct LinalgOpInterfaceHelper<> {
|
||||||
/// OpOperand, that eventually ends at a single InitTensorOp.
|
/// OpOperand, that eventually ends at a single InitTensorOp.
|
||||||
LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext::
|
LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext::
|
||||||
InitTensorEliminationStep::eliminateInitTensors(
|
InitTensorEliminationStep::eliminateInitTensors(
|
||||||
FuncOp funcOp, BufferizationAliasInfo &aliasInfo,
|
FuncOp funcOp, BufferizationState &state,
|
||||||
DominanceInfo &domInfo,
|
|
||||||
std::function<bool(OpOperand &)> anchorMatchFunc,
|
std::function<bool(OpOperand &)> anchorMatchFunc,
|
||||||
std::function<Value(OpBuilder &, Location, OpOperand &)> rewriteFunc,
|
std::function<Value(OpBuilder &, Location, OpOperand &)> rewriteFunc,
|
||||||
SmallVector<Operation *> &newOps) {
|
SmallVector<Operation *> &newOps) {
|
||||||
OpBuilder b(funcOp->getContext());
|
OpBuilder b(funcOp->getContext());
|
||||||
|
BufferizationAliasInfo &aliasInfo = state.aliasInfo;
|
||||||
|
|
||||||
WalkResult status = funcOp->walk([&](Operation *op) {
|
WalkResult status = funcOp->walk([&](Operation *op) {
|
||||||
for (OpOperand &operand : op->getOpOperands()) {
|
for (OpOperand &operand : op->getOpOperands()) {
|
||||||
|
@ -501,17 +501,17 @@ LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext::
|
||||||
/// out-of-place due to RaW conflicts.
|
/// out-of-place due to RaW conflicts.
|
||||||
LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext::
|
LogicalResult mlir::linalg::comprehensive_bufferize::linalg_ext::
|
||||||
InsertSliceAnchoredInitTensorEliminationStep::run(
|
InsertSliceAnchoredInitTensorEliminationStep::run(
|
||||||
FuncOp funcOp, BufferizationAliasInfo &aliasInfo,
|
FuncOp funcOp, BufferizationState &state,
|
||||||
DominanceInfo &domInfo, SmallVector<Operation *> &newOps) {
|
SmallVector<Operation *> &newOps) {
|
||||||
return eliminateInitTensors(
|
return eliminateInitTensors(
|
||||||
funcOp, aliasInfo, domInfo,
|
funcOp, state,
|
||||||
[&](OpOperand &operand) {
|
[&](OpOperand &operand) {
|
||||||
auto insertSliceOp =
|
auto insertSliceOp =
|
||||||
dyn_cast<tensor::InsertSliceOp>(operand.getOwner());
|
dyn_cast<tensor::InsertSliceOp>(operand.getOwner());
|
||||||
if (!insertSliceOp)
|
if (!insertSliceOp)
|
||||||
return false;
|
return false;
|
||||||
// Only inplace bufferized InsertSliceOps are eligible.
|
// Only inplace bufferized InsertSliceOps are eligible.
|
||||||
if (!aliasInfo.isInPlace(insertSliceOp->getOpResult(0)))
|
if (!state.aliasInfo.isInPlace(insertSliceOp->getOpResult(0)))
|
||||||
return false;
|
return false;
|
||||||
return &operand == &insertSliceOp->getOpOperand(0) /*source*/;
|
return &operand == &insertSliceOp->getOpOperand(0) /*source*/;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue