[Mlir-commits] [mlir] 0e9a4a3 - [mlir] Move the Buffer related source files out of Transforms/
River Riddle
llvmlistbot at llvm.org
Mon Jan 24 19:30:14 PST 2022
Author: River Riddle
Date: 2022-01-24T19:25:52-08:00
New Revision: 0e9a4a3b65363c082087864b9ff5e0da33be90da
URL: https://github.com/llvm/llvm-project/commit/0e9a4a3b65363c082087864b9ff5e0da33be90da
DIFF: https://github.com/llvm/llvm-project/commit/0e9a4a3b65363c082087864b9ff5e0da33be90da.diff
LOG: [mlir] Move the Buffer related source files out of Transforms/
Transforms/ should only contain dialect-independent transformations,
and these files are a much better fit for the bufferization dialect anyways.
Differential Revision: https://reviews.llvm.org/D117839
Added:
mlir/include/mlir/Dialect/Bufferization/Transforms/BufferUtils.h
mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
Modified:
mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
mlir/include/mlir/Dialect/StandardOps/Transforms/Passes.h
mlir/include/mlir/Transforms/Passes.h
mlir/include/mlir/Transforms/Passes.td
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ArithInterfaceImpl.cpp
mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
mlir/lib/Transforms/CMakeLists.txt
mlir/lib/Transforms/PassDetail.h
Removed:
mlir/include/mlir/Transforms/BufferUtils.h
mlir/lib/Transforms/BufferOptimizations.cpp
mlir/lib/Transforms/BufferResultsToOutParams.cpp
mlir/lib/Transforms/BufferUtils.cpp
################################################################################
diff --git a/mlir/include/mlir/Transforms/BufferUtils.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/BufferUtils.h
similarity index 95%
rename from mlir/include/mlir/Transforms/BufferUtils.h
rename to mlir/include/mlir/Dialect/Bufferization/Transforms/BufferUtils.h
index d9d06963fb28..681b94953f20 100644
--- a/mlir/include/mlir/Transforms/BufferUtils.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/BufferUtils.h
@@ -11,13 +11,12 @@
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_TRANSFORMS_BUFFERUTILS_H
-#define MLIR_TRANSFORMS_BUFFERUTILS_H
+#ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_BUFFERUTILS_H
+#define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_BUFFERUTILS_H
#include "mlir/Analysis/BufferViewFlowAnalysis.h"
#include "mlir/Analysis/Liveness.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
-#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/Dominance.h"
@@ -25,6 +24,11 @@
#include "mlir/Transforms/DialectConversion.h"
namespace mlir {
+namespace memref {
+class GlobalOp;
+} // namespace memref
+
+namespace bufferization {
/// A simple analysis that detects allocation operations.
class BufferPlacementAllocs {
@@ -117,10 +121,6 @@ class BufferPlacementTransformationBase {
Liveness liveness;
};
-namespace memref {
-class GlobalOp;
-} // namespace memref
-
// Support class to create global ops for tensor-valued constants in the
// program. Globals are created lazily at the top of the `moduleOp` with pretty
// names. Duplicates are avoided.
@@ -137,6 +137,7 @@ class GlobalCreator {
// dependence to the memref dialect for this.
DenseMap<Attribute, Operation *> globals;
};
+} // namespace bufferization
} // namespace mlir
-#endif // MLIR_TRANSFORMS_BUFFERUTILS_H
+#endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_BUFFERUTILS_H
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
index 72c5136eb198..481eaa284d98 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h
@@ -14,10 +14,34 @@ namespace bufferization {
/// buffers.
std::unique_ptr<Pass> createBufferDeallocationPass();
+/// Creates a pass that moves allocations upwards to reduce the number of
+/// required copies that are inserted during the BufferDeallocation pass.
+std::unique_ptr<Pass> createBufferHoistingPass();
+
+/// Creates a pass that moves allocations upwards out of loops. This avoids
+/// reallocations inside of loops.
+std::unique_ptr<Pass> createBufferLoopHoistingPass();
+
+/// Creates a pass that converts memref function results to out-params.
+std::unique_ptr<Pass> createBufferResultsToOutParamsPass();
+
/// Creates a pass that finalizes a partial bufferization by removing remaining
/// bufferization.to_tensor and bufferization.to_memref operations.
std::unique_ptr<OperationPass<FuncOp>> createFinalizingBufferizePass();
+/// Creates a pass that promotes heap-based allocations to stack-based ones.
+/// Only buffers smaller than the provided size are promoted.
+/// Dynamic shaped buffers are promoted up to the given rank.
+std::unique_ptr<Pass>
+createPromoteBuffersToStackPass(unsigned maxAllocSizeInBytes = 1024,
+ unsigned bitwidthOfIndexType = 64,
+ unsigned maxRankOfAllocatedMemRef = 1);
+
+/// Creates a pass that promotes heap-based allocations to stack-based ones.
+/// Only buffers smaller with `isSmallAlloc(alloc) == true` are promoted.
+std::unique_ptr<Pass>
+createPromoteBuffersToStackPass(std::function<bool(Value)> isSmallAlloc);
+
//===----------------------------------------------------------------------===//
// Registration
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
index 22db1dc2c5bf..dcbdd52a5c81 100644
--- a/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
+++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td
@@ -88,6 +88,51 @@ def BufferDeallocation : Pass<"buffer-deallocation", "FuncOp"> {
let constructor = "mlir::bufferization::createBufferDeallocationPass()";
}
+def BufferHoisting : Pass<"buffer-hoisting", "FuncOp"> {
+ let summary = "Optimizes placement of allocation operations by moving them "
+ "into common dominators and out of nested regions";
+ let description = [{
+ This pass implements an approach to aggressively move allocations upwards
+ into common dominators and out of nested regions.
+ }];
+ let constructor = "mlir::bufferization::createBufferHoistingPass()";
+}
+
+def BufferLoopHoisting : Pass<"buffer-loop-hoisting", "FuncOp"> {
+ let summary = "Optimizes placement of allocation operations by moving them "
+ "out of loop nests";
+ let description = [{
+ This pass implements an approach to aggressively move allocations upwards
+ out of loop nests. It does not move allocations into common dominators.
+ }];
+ let constructor = "mlir::bufferization::createBufferLoopHoistingPass()";
+}
+
+def BufferResultsToOutParams : Pass<"buffer-results-to-out-params", "ModuleOp"> {
+ let summary = "Converts memref-typed function results to out-params";
+ let description = [{
+ Some calling conventions prefer to pass output memrefs as "out params". The
+ conversion to this calling convention must be done as an atomic
+ transformation of the entire program (hence this is a module pass).
+
+ For example, if a call is rewritten, the callee needs to be rewritten
+ otherwise the IR will end up invalid. Thus, this transformation
+ require an atomic change to the entire program (e.g. the whole module).
+
+ This pass is expected to run immediately after bufferization is finished.
+ At that point, tensor-typed results will have been converted to memref-typed
+ results, and can be consistently converted to out params.
+
+ All memref-typed results are appended to the function argument list.
+
+ The main issue with this pass (and the out-param calling convention) is that
+ buffers for results need to be allocated in the caller. This currently only
+ works for static shaped memrefs.
+ }];
+ let constructor = "mlir::bufferization::createBufferResultsToOutParamsPass()";
+ let dependentDialects = ["memref::MemRefDialect"];
+}
+
def FinalizingBufferize : Pass<"finalizing-bufferize", "FuncOp"> {
let summary = "Finalize a partial bufferization";
let description = [{
@@ -104,4 +149,28 @@ def FinalizingBufferize : Pass<"finalizing-bufferize", "FuncOp"> {
let constructor = "mlir::bufferization::createFinalizingBufferizePass()";
}
+def PromoteBuffersToStack : Pass<"promote-buffers-to-stack", "FuncOp"> {
+ let summary = "Promotes heap-based allocations to automatically managed "
+ "stack-based allocations";
+ let description = [{
+ This pass implements a simple algorithm to convert heap-based memory
+ allocations to stack-based ones. It uses a built-in heuristic to decide
+ whether it makes sense to convert an allocation. Furthermore, dynamic
+ shaped buffers that are limited by the rank of the tensor can be
+ converted. They are only transformed if they are considered to be small.
+ }];
+ let constructor = "mlir::bufferization::createPromoteBuffersToStackPass()";
+ let options = [
+ Option<"maxAllocSizeInBytes", "max-alloc-size-in-bytes", "unsigned",
+ /*default=*/"1024",
+ "Maximal size in bytes to promote allocations to stack.">,
+ Option<"bitwidthOfIndexType", "bitwidth-of-index-type", "unsigned",
+ /*default=*/"64",
+ "Bitwidth of the index type. Used for size estimation.">,
+ Option<"maxRankOfAllocatedMemRef", "max-rank-of-allocated-memref", "unsigned",
+ /*default=*/"1",
+ "Maximal memref rank to promote dynamic buffers.">,
+ ];
+}
+
#endif // MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_PASSES
diff --git a/mlir/include/mlir/Dialect/StandardOps/Transforms/Passes.h b/mlir/include/mlir/Dialect/StandardOps/Transforms/Passes.h
index b80cd0bf6d62..b47303c70250 100644
--- a/mlir/include/mlir/Dialect/StandardOps/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/StandardOps/Transforms/Passes.h
@@ -19,9 +19,9 @@
namespace mlir {
namespace bufferization {
class BufferizeTypeConverter;
+class GlobalCreator;
} // namespace bufferization
-class GlobalCreator;
class RewritePatternSet;
using OwningRewritePatternList = RewritePatternSet;
@@ -38,7 +38,7 @@ std::unique_ptr<Pass> createFuncBufferizePass();
/// Add patterns to bufferize tensor constants into global memrefs to the given
/// pattern list.
void populateTensorConstantBufferizePatterns(
- GlobalCreator &globalCreator,
+ bufferization::GlobalCreator &globalCreator,
bufferization::BufferizeTypeConverter &typeConverter,
RewritePatternSet &patterns);
diff --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h
index 46bab0047c1b..222434324451 100644
--- a/mlir/include/mlir/Transforms/Passes.h
+++ b/mlir/include/mlir/Transforms/Passes.h
@@ -33,30 +33,6 @@ enum FusionMode { Greedy, ProducerConsumer, Sibling };
// Passes
//===----------------------------------------------------------------------===//
-/// Creates a pass that moves allocations upwards to reduce the number of
-/// required copies that are inserted during the BufferDeallocation pass.
-std::unique_ptr<Pass> createBufferHoistingPass();
-
-/// Creates a pass that moves allocations upwards out of loops. This avoids
-/// reallocations inside of loops.
-std::unique_ptr<Pass> createBufferLoopHoistingPass();
-
-/// Creates a pass that promotes heap-based allocations to stack-based ones.
-/// Only buffers smaller than the provided size are promoted.
-/// Dynamic shaped buffers are promoted up to the given rank.
-std::unique_ptr<Pass>
-createPromoteBuffersToStackPass(unsigned maxAllocSizeInBytes = 1024,
- unsigned bitwidthOfIndexType = 64,
- unsigned maxRankOfAllocatedMemRef = 1);
-
-/// Creates a pass that promotes heap-based allocations to stack-based ones.
-/// Only buffers smaller with `isSmallAlloc(alloc) == true` are promoted.
-std::unique_ptr<Pass>
-createPromoteBuffersToStackPass(std::function<bool(Value)> isSmallAlloc);
-
-/// Creates a pass that converts memref function results to out-params.
-std::unique_ptr<Pass> createBufferResultsToOutParamsPass();
-
/// Creates an instance of the Canonicalizer pass, configured with default
/// settings (which can be overridden by pass options on the command line).
std::unique_ptr<Pass> createCanonicalizerPass();
diff --git a/mlir/include/mlir/Transforms/Passes.td b/mlir/include/mlir/Transforms/Passes.td
index 4b1d6ca71e2e..9942c0fc8892 100644
--- a/mlir/include/mlir/Transforms/Passes.td
+++ b/mlir/include/mlir/Transforms/Passes.td
@@ -217,75 +217,6 @@ def AffinePipelineDataTransfer
let constructor = "mlir::createPipelineDataTransferPass()";
}
-def BufferHoisting : Pass<"buffer-hoisting", "FuncOp"> {
- let summary = "Optimizes placement of allocation operations by moving them "
- "into common dominators and out of nested regions";
- let description = [{
- This pass implements an approach to aggressively move allocations upwards
- into common dominators and out of nested regions.
- }];
- let constructor = "mlir::createBufferHoistingPass()";
-}
-
-def BufferLoopHoisting : Pass<"buffer-loop-hoisting", "FuncOp"> {
- let summary = "Optimizes placement of allocation operations by moving them "
- "out of loop nests";
- let description = [{
- This pass implements an approach to aggressively move allocations upwards
- out of loop nests. It does not move allocations into common dominators.
- }];
- let constructor = "mlir::createBufferLoopHoistingPass()";
-}
-
-def PromoteBuffersToStack : Pass<"promote-buffers-to-stack", "FuncOp"> {
- let summary = "Promotes heap-based allocations to automatically managed "
- "stack-based allocations";
- let description = [{
- This pass implements a simple algorithm to convert heap-based memory
- allocations to stack-based ones. It uses a built-in heuristic to decide
- whether it makes sense to convert an allocation. Furthermore, dynamic
- shaped buffers that are limited by the rank of the tensor can be
- converted. They are only transformed if they are considered to be small.
- }];
- let constructor = "mlir::createPromoteBuffersToStackPass()";
- let options = [
- Option<"maxAllocSizeInBytes", "max-alloc-size-in-bytes", "unsigned",
- /*default=*/"1024",
- "Maximal size in bytes to promote allocations to stack.">,
- Option<"bitwidthOfIndexType", "bitwidth-of-index-type", "unsigned",
- /*default=*/"64",
- "Bitwidth of the index type. Used for size estimation.">,
- Option<"maxRankOfAllocatedMemRef", "max-rank-of-allocated-memref", "unsigned",
- /*default=*/"1",
- "Maximal memref rank to promote dynamic buffers.">,
- ];
-}
-
-def BufferResultsToOutParams : Pass<"buffer-results-to-out-params", "ModuleOp"> {
- let summary = "Converts memref-typed function results to out-params";
- let description = [{
- Some calling conventions prefer to pass output memrefs as "out params". The
- conversion to this calling convention must be done as an atomic
- transformation of the entire program (hence this is a module pass).
-
- For example, if a call is rewritten, the callee needs to be rewritten
- otherwise the IR will end up invalid. Thus, this transformation
- require an atomic change to the entire program (e.g. the whole module).
-
- This pass is expected to run immediately after bufferization is finished.
- At that point, tensor-typed results will have been converted to memref-typed
- results, and can be consistently converted to out params.
-
- All memref-typed results are appended to the function argument list.
-
- The main issue with this pass (and the out-param calling convention) is that
- buffers for results need to be allocated in the caller. This currently only
- works for static shaped memrefs.
- }];
- let constructor = "mlir::createBufferResultsToOutParamsPass()";
- let dependentDialects = ["memref::MemRefDialect"];
-}
-
def Canonicalizer : Pass<"canonicalize"> {
let summary = "Canonicalize operations";
let description = [{
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
index 73decbac7382..ed7bd5c20d58 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
@@ -54,12 +54,13 @@
#include "mlir/Dialect/Bufferization/IR/AllocationOpInterface.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
+#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
-#include "mlir/Transforms/BufferUtils.h"
#include "llvm/ADT/SetOperations.h"
using namespace mlir;
+using namespace mlir::bufferization;
/// Walks over all immediate return-like terminators in the given region.
static LogicalResult
diff --git a/mlir/lib/Transforms/BufferOptimizations.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
similarity index 96%
rename from mlir/lib/Transforms/BufferOptimizations.cpp
rename to mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
index 4fa035a93992..158c78673934 100644
--- a/mlir/lib/Transforms/BufferOptimizations.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferOptimizations.cpp
@@ -12,14 +12,15 @@
// convert heap-based allocations to stack-based allocations, if possible.
#include "PassDetail.h"
+#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Pass/Pass.h"
-#include "mlir/Transforms/BufferUtils.h"
-#include "mlir/Transforms/Passes.h"
using namespace mlir;
+using namespace mlir::bufferization;
/// Returns true if the given operation implements a known high-level region-
/// based control-flow interface.
@@ -422,23 +423,22 @@ class PromoteBuffersToStackPass
} // namespace
-std::unique_ptr<Pass> mlir::createBufferHoistingPass() {
+std::unique_ptr<Pass> mlir::bufferization::createBufferHoistingPass() {
return std::make_unique<BufferHoistingPass>();
}
-std::unique_ptr<Pass> mlir::createBufferLoopHoistingPass() {
+std::unique_ptr<Pass> mlir::bufferization::createBufferLoopHoistingPass() {
return std::make_unique<BufferLoopHoistingPass>();
}
-std::unique_ptr<Pass>
-mlir::createPromoteBuffersToStackPass(unsigned maxAllocSizeInBytes,
- unsigned bitwidthOfIndexType,
- unsigned maxRankOfAllocatedMemRef) {
+std::unique_ptr<Pass> mlir::bufferization::createPromoteBuffersToStackPass(
+ unsigned maxAllocSizeInBytes, unsigned bitwidthOfIndexType,
+ unsigned maxRankOfAllocatedMemRef) {
return std::make_unique<PromoteBuffersToStackPass>(
maxAllocSizeInBytes, bitwidthOfIndexType, maxRankOfAllocatedMemRef);
}
-std::unique_ptr<Pass>
-mlir::createPromoteBuffersToStackPass(std::function<bool(Value)> isSmallAlloc) {
+std::unique_ptr<Pass> mlir::bufferization::createPromoteBuffersToStackPass(
+ std::function<bool(Value)> isSmallAlloc) {
return std::make_unique<PromoteBuffersToStackPass>(std::move(isSmallAlloc));
}
diff --git a/mlir/lib/Transforms/BufferResultsToOutParams.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
similarity index 97%
rename from mlir/lib/Transforms/BufferResultsToOutParams.cpp
rename to mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
index c462955d068a..08780db5f94d 100644
--- a/mlir/lib/Transforms/BufferResultsToOutParams.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp
@@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//
#include "PassDetail.h"
+#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Operation.h"
#include "mlir/Pass/Pass.h"
-#include "mlir/Transforms/Passes.h"
using namespace mlir;
@@ -139,6 +139,7 @@ struct BufferResultsToOutParamsPass
};
} // namespace
-std::unique_ptr<Pass> mlir::createBufferResultsToOutParamsPass() {
+std::unique_ptr<Pass>
+mlir::bufferization::createBufferResultsToOutParamsPass() {
return std::make_unique<BufferResultsToOutParamsPass>();
}
diff --git a/mlir/lib/Transforms/BufferUtils.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
similarity index 74%
rename from mlir/lib/Transforms/BufferUtils.cpp
rename to mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index c24293cb4bd6..a373a8dbe86b 100644
--- a/mlir/lib/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -10,18 +10,18 @@
//
//===----------------------------------------------------------------------===//
-#include "mlir/Transforms/BufferUtils.h"
-#include "PassDetail.h"
+#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
+#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
+#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h"
-#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Pass/Pass.h"
-#include "mlir/Transforms/Passes.h"
#include "llvm/ADT/SetOperations.h"
using namespace mlir;
+using namespace mlir::bufferization;
//===----------------------------------------------------------------------===//
// BufferPlacementAllocs
@@ -139,3 +139,49 @@ bool BufferPlacementTransformationBase::isLoop(Operation *op) {
return false;
}
+
+//===----------------------------------------------------------------------===//
+// BufferPlacementTransformationBase
+//===----------------------------------------------------------------------===//
+
+memref::GlobalOp GlobalCreator::getGlobalFor(arith::ConstantOp constantOp) {
+ auto type = constantOp.getType().cast<RankedTensorType>();
+
+ BufferizeTypeConverter typeConverter;
+
+ // If we already have a global for this constant value, no need to do
+ // anything else.
+ auto it = globals.find(constantOp.getValue());
+ if (it != globals.end())
+ return cast<memref::GlobalOp>(it->second);
+
+ // Create a builder without an insertion point. We will insert using the
+ // symbol table to guarantee unique names.
+ OpBuilder globalBuilder(moduleOp.getContext());
+ SymbolTable symbolTable(moduleOp);
+
+ // Create a pretty name.
+ SmallString<64> buf;
+ llvm::raw_svector_ostream os(buf);
+ interleave(type.getShape(), os, "x");
+ os << "x" << type.getElementType();
+
+ // Add an optional alignment to the global memref.
+ IntegerAttr memrefAlignment =
+ alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
+ : IntegerAttr();
+
+ auto global = globalBuilder.create<memref::GlobalOp>(
+ constantOp.getLoc(), (Twine("__constant_") + os.str()).str(),
+ /*sym_visibility=*/globalBuilder.getStringAttr("private"),
+ /*type=*/typeConverter.convertType(type).cast<MemRefType>(),
+ /*initial_value=*/constantOp.getValue().cast<ElementsAttr>(),
+ /*constant=*/true,
+ /*alignment=*/memrefAlignment);
+ symbolTable.insert(global);
+ // The symbol table inserts at the end of the module, but globals are a bit
+ // nicer if they are at the beginning.
+ global->moveBefore(&moduleOp.front());
+ globals[constantOp.getValue()] = global;
+ return global;
+}
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
index b212ef952a05..56fc326b4fa9 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/Bufferization/Transforms/CMakeLists.txt
@@ -1,6 +1,9 @@
add_mlir_dialect_library(MLIRBufferizationTransforms
Bufferize.cpp
BufferDeallocation.cpp
+ BufferOptimizations.cpp
+ BufferResultsToOutParams.cpp
+ BufferUtils.cpp
OneShotAnalysis.cpp
ADDITIONAL_HEADER_DIRS
diff --git a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ArithInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ArithInterfaceImpl.cpp
index 256916c5e7b3..de3fbcd8b121 100644
--- a/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ArithInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/Linalg/ComprehensiveBufferize/ArithInterfaceImpl.cpp
@@ -10,10 +10,10 @@
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
+#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/Operation.h"
-#include "mlir/Transforms/BufferUtils.h"
using namespace mlir::bufferization;
diff --git a/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp b/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
index c7752f592a9e..5bae6f3f6154 100644
--- a/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
+++ b/mlir/lib/Dialect/StandardOps/Transforms/TensorConstantBufferize.cpp
@@ -12,57 +12,16 @@
#include "PassDetail.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
+#include "mlir/Dialect/Bufferization/Transforms/BufferUtils.h"
#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/Dialect/StandardOps/Transforms/Passes.h"
#include "mlir/IR/BlockAndValueMapping.h"
-#include "mlir/Transforms/BufferUtils.h"
#include "mlir/Transforms/DialectConversion.h"
using namespace mlir;
-
-memref::GlobalOp GlobalCreator::getGlobalFor(arith::ConstantOp constantOp) {
- auto type = constantOp.getType().cast<RankedTensorType>();
-
- bufferization::BufferizeTypeConverter typeConverter;
-
- // If we already have a global for this constant value, no need to do
- // anything else.
- auto it = globals.find(constantOp.getValue());
- if (it != globals.end())
- return cast<memref::GlobalOp>(it->second);
-
- // Create a builder without an insertion point. We will insert using the
- // symbol table to guarantee unique names.
- OpBuilder globalBuilder(moduleOp.getContext());
- SymbolTable symbolTable(moduleOp);
-
- // Create a pretty name.
- SmallString<64> buf;
- llvm::raw_svector_ostream os(buf);
- interleave(type.getShape(), os, "x");
- os << "x" << type.getElementType();
-
- // Add an optional alignment to the global memref.
- IntegerAttr memrefAlignment =
- alignment > 0 ? IntegerAttr::get(globalBuilder.getI64Type(), alignment)
- : IntegerAttr();
-
- auto global = globalBuilder.create<memref::GlobalOp>(
- constantOp.getLoc(), (Twine("__constant_") + os.str()).str(),
- /*sym_visibility=*/globalBuilder.getStringAttr("private"),
- /*type=*/typeConverter.convertType(type).cast<MemRefType>(),
- /*initial_value=*/constantOp.getValue().cast<ElementsAttr>(),
- /*constant=*/true,
- /*alignment=*/memrefAlignment);
- symbolTable.insert(global);
- // The symbol table inserts at the end of the module, but globals are a bit
- // nicer if they are at the beginning.
- global->moveBefore(&moduleOp.front());
- globals[constantOp.getValue()] = global;
- return global;
-}
+using namespace mlir::bufferization;
namespace {
class BufferizeTensorConstantOp
diff --git a/mlir/lib/Transforms/CMakeLists.txt b/mlir/lib/Transforms/CMakeLists.txt
index 3e10b4a32131..1eba1ad94e5a 100644
--- a/mlir/lib/Transforms/CMakeLists.txt
+++ b/mlir/lib/Transforms/CMakeLists.txt
@@ -1,9 +1,6 @@
add_subdirectory(Utils)
add_mlir_library(MLIRTransforms
- BufferOptimizations.cpp
- BufferResultsToOutParams.cpp
- BufferUtils.cpp
Canonicalizer.cpp
ControlFlowSink.cpp
CSE.cpp
@@ -31,7 +28,6 @@ add_mlir_library(MLIRTransforms
LINK_LIBS PUBLIC
MLIRAffine
MLIRAnalysis
- MLIRBufferization
MLIRCopyOpInterface
MLIRLoopLikeInterface
MLIRMemRef
diff --git a/mlir/lib/Transforms/PassDetail.h b/mlir/lib/Transforms/PassDetail.h
index 9b846198fc08..4496c4223cbe 100644
--- a/mlir/lib/Transforms/PassDetail.h
+++ b/mlir/lib/Transforms/PassDetail.h
@@ -27,10 +27,6 @@ namespace memref {
class MemRefDialect;
} // namespace memref
-namespace bufferization {
-class BufferizationDialect;
-} // namespace bufferization
-
#define GEN_PASS_CLASSES
#include "mlir/Transforms/Passes.h.inc"
More information about the Mlir-commits
mailing list