[Mlir-commits] [mlir] 129420d - [mlir][bufferization][NFC] Move EmptyTensorToAllocTensorPass
Matthias Springer
llvmlistbot at llvm.org
Tue Oct 4 17:58:16 PDT 2022
Author: Matthias Springer
Date: 2022-10-05T09:57:22+09:00
New Revision: 129420df5122a27560a17f6a472c8c750d3bbd7b
URL: https://github.com/llvm/llvm-project/commit/129420df5122a27560a17f6a472c8c750d3bbd7b
DIFF: https://github.com/llvm/llvm-project/commit/129420df5122a27560a17f6a472c8c750d3bbd7b.diff
LOG: [mlir][bufferization][NFC] Move EmptyTensorToAllocTensorPass
This change moves the pass from the Linalg dialect to the bufferization dialect.
Differential Revision: https://reviews.llvm.org/D135130
Added:
mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorToAllocTensor.cpp
Modified:
mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
mlir/include/mlir/Dialect/Linalg/Passes.h
mlir/include/mlir/Dialect/Linalg/Passes.td
mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
Removed:
mlir/lib/Dialect/Linalg/Transforms/InitTensorToAllocTensor.cpp
################################################################################
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
index c5aca6b4d0447..aa3f6423407c7 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
@@ -46,6 +46,9 @@ LogicalResult promoteBufferResultsToOutParams(ModuleOp module);
/// function argument.
std::unique_ptr<Pass> createDropEquivalentBufferResultsPass();
+/// Create a pass that rewrites tensor.empty to bufferization.alloc_tensor.
+std::unique_ptr<Pass> createEmptyTensorToAllocTensorPass();
+
/// Drop all memref function results that are equivalent to a function argument.
LogicalResult dropEquivalentBufferResults(ModuleOp module);
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
index f2d699985bfe0..312f2ffaf0ae3 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
@@ -168,6 +168,17 @@ def DropEquivalentBufferResults : Pass<"drop-equivalent-buffer-results", "Module
let dependentDialects = ["memref::MemRefDialect"];
}
+def EmptyTensorToAllocTensor : Pass<"empty-tensor-to-alloc-tensor"> {
+ let summary = "Replace all empty ops by alloc_tensor ops.";
+ let description = [{
+ tensor.empty ops return a tensor of unspecified contents who's only purpose
+ is to carry the tensor shape. This pass converts such ops to
+ bufferization.alloc_tensor ops, which bufferize to buffer allocations.
+ }];
+ let constructor = "mlir::bufferization::createEmptyTensorToAllocTensorPass()";
+ let dependentDialects = ["tensor::TensorDialect"];
+}
+
def OneShotBufferize : Pass<"one-shot-bufferize", "ModuleOp"> {
let summary = "One-Shot Bufferize";
let description = [{
diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.h b/mlir/include/mlir/Dialect/Linalg/Passes.h
index 6b401029e12f5..20157d2226c11 100644
--- a/mlir/include/mlir/Dialect/Linalg/Passes.h
+++ b/mlir/include/mlir/Dialect/Linalg/Passes.h
@@ -61,9 +61,6 @@ createConvertLinalgToParallelLoopsPass();
std::unique_ptr<OperationPass<func::FuncOp>>
createConvertLinalgToAffineLoopsPass();
-/// Create a pass that rewrites tensor.empty to bufferization.alloc_tensor.
-std::unique_ptr<Pass> createEmptyTensorToAllocTensorPass();
-
/// Create a pass to convert Linalg operations which work on tensors to use
/// buffers instead.
std::unique_ptr<OperationPass<func::FuncOp>> createLinalgBufferizePass();
diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td
index 6af6a126a790d..348067ddd1b48 100644
--- a/mlir/include/mlir/Dialect/Linalg/Passes.td
+++ b/mlir/include/mlir/Dialect/Linalg/Passes.td
@@ -24,16 +24,6 @@ def ConvertElementwiseToLinalg : Pass<"convert-elementwise-to-linalg", ""> {
let dependentDialects = ["linalg::LinalgDialect", "memref::MemRefDialect"];
}
-def EmptyTensorToAllocTensor : Pass<"empty-tensor-to-alloc-tensor"> {
- let summary = "Replace all empty ops by alloc_tensor ops.";
- let description = [{
- tensor.empty ops return a tensor of unspecified contents who's only purpose
- is to carry the tensor shape. This pass converts such ops to
- bufferization.alloc_tensor ops, which bufferize to buffer allocations.
- }];
- let constructor = "mlir::createEmptyTensorToAllocTensorPass()";
-}
-
def LinalgFoldUnitExtentDims : Pass<"linalg-fold-unit-extent-dims", ""> {
let summary = "Remove unit-extent dimension in Linalg ops on tensors";
let constructor = "mlir::createLinalgFoldUnitExtentDimsPass()";
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
index dfb84c430c115..3fc472c408c44 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
@@ -7,6 +7,7 @@ add_mlir_dialect_library(MLIRBufferizationTransforms
BufferUtils.cpp
BufferViewFlowAnalysis.cpp
DropEquivalentBufferResults.cpp
+ EmptyTensorToAllocTensor.cpp
FuncBufferizableOpInterfaceImpl.cpp
OneShotAnalysis.cpp
OneShotModuleBufferize.cpp
diff --git a/mlir/lib/Dialect/Linalg/Transforms/InitTensorToAllocTensor.cpp b/mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorToAllocTensor.cpp
similarity index 79%
rename from mlir/lib/Dialect/Linalg/Transforms/InitTensorToAllocTensor.cpp
rename to mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorToAllocTensor.cpp
index c82bbce9e6f1e..47f11c09a3405 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/InitTensorToAllocTensor.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorToAllocTensor.cpp
@@ -1,4 +1,4 @@
-//===- InitTensorToAllocTensor.cpp - Lower init_tensor to alloc_tensor ----===//
+//===- InitTensorToAllocTensor.cpp - Lower tensor.empty to alloc_tensor ---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Dialect/Linalg/Passes.h"
+#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
@@ -14,8 +14,10 @@
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
namespace mlir {
+namespace bufferization {
#define GEN_PASS_DEF_EMPTYTENSORTOALLOCTENSOR
-#include "mlir/Dialect/Linalg/Passes.h.inc"
+#include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc"
+} // namespace bufferization
} // namespace mlir
using namespace mlir;
@@ -35,7 +37,8 @@ struct EmptyTensorLoweringPattern : public OpRewritePattern<tensor::EmptyOp> {
};
struct EmptyTensorToAllocTensor
- : public impl::EmptyTensorToAllocTensorBase<EmptyTensorToAllocTensor> {
+ : public bufferization::impl::EmptyTensorToAllocTensorBase<
+ EmptyTensorToAllocTensor> {
EmptyTensorToAllocTensor() = default;
void runOnOperation() override;
@@ -55,6 +58,7 @@ void EmptyTensorToAllocTensor::runOnOperation() {
signalPassFailure();
}
-std::unique_ptr<Pass> mlir::createEmptyTensorToAllocTensorPass() {
+std::unique_ptr<Pass>
+mlir::bufferization::createEmptyTensorToAllocTensorPass() {
return std::make_unique<EmptyTensorToAllocTensor>();
}
diff --git a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
index bf5164ab72295..c218ad2ff199c 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
@@ -15,7 +15,6 @@ add_mlir_dialect_library(MLIRLinalgTransforms
Generalization.cpp
Hoisting.cpp
HoistPadding.cpp
- InitTensorToAllocTensor.cpp
InlineScalarOperands.cpp
Interchange.cpp
Loops.cpp
More information about the Mlir-commits
mailing list