Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp
Show All 14 Lines | |||||
#include "mlir/Dialect/Linalg/IR/LinalgOps.h" | #include "mlir/Dialect/Linalg/IR/LinalgOps.h" | ||||
#include "mlir/Dialect/Linalg/Passes.h" | #include "mlir/Dialect/Linalg/Passes.h" | ||||
#include "mlir/IR/Function.h" | #include "mlir/IR/Function.h" | ||||
#include "mlir/IR/Operation.h" | #include "mlir/IR/Operation.h" | ||||
#include "mlir/Pass/Pass.h" | #include "mlir/Pass/Pass.h" | ||||
#include "mlir/Transforms/BufferPlacement.h" | #include "mlir/Transforms/BufferPlacement.h" | ||||
using namespace mlir; | using namespace mlir; | ||||
using ReturnOpConverter = | |||||
BufferAssignmentReturnOpConverter<mlir::ReturnOp, mlir::ReturnOp, | |||||
linalg::CopyOp>; | |||||
namespace { | namespace { | ||||
/// A pattern to convert Generic Linalg operations which work on tensors to | /// A pattern to convert Generic Linalg operations which work on tensors to | ||||
/// use buffers. A buffer is allocated using BufferAssignmentPlacer for | /// use buffers. A buffer is allocated using BufferAssignmentPlacer for | ||||
/// each operation result. BufferPlacement pass should be later used to move | /// each operation result. BufferPlacement pass should be later used to move | ||||
/// Alloc operations to the correct positions and insert the missing Dealloc | /// Alloc operations to the correct positions and insert the missing Dealloc | ||||
/// operations in the correct places. | /// operations in the correct places. | ||||
class GenericOpConverter | class GenericOpConverter | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
}; | }; | ||||
/// Populate the given list with patterns to convert Linalg operations on | /// Populate the given list with patterns to convert Linalg operations on | ||||
/// tensors to buffers. | /// tensors to buffers. | ||||
static void populateConvertLinalgOnTensorsToBuffersPattern( | static void populateConvertLinalgOnTensorsToBuffersPattern( | ||||
MLIRContext *context, BufferAssignmentPlacer *placer, | MLIRContext *context, BufferAssignmentPlacer *placer, | ||||
TypeConverter *converter, OwningRewritePatternList *patterns) { | TypeConverter *converter, OwningRewritePatternList *patterns) { | ||||
// clang-format off | populateWithBufferAssignmentOpConversionPatterns< | ||||
patterns->insert<FunctionAndBlockSignatureConverter, | mlir::ReturnOp, mlir::ReturnOp, linalg::CopyOp, | ||||
pifon2a: /*allowMemrefFunctionResults=*/false | |||||
GenericOpConverter, | /*allowMemrefFunctionResults=*/false>(context, placer, converter, | ||||
ReturnOpConverter>(context, placer, converter); | patterns); | ||||
// clang-format on | patterns->insert<GenericOpConverter>(context, placer, converter); | ||||
} | } | ||||
/// Converts Linalg operations that work on tensor-type operands or results to | /// Converts Linalg operations that work on tensor-type operands or results to | ||||
/// work on buffers. | /// work on buffers. | ||||
struct ConvertLinalgOnTensorsToBuffers | struct ConvertLinalgOnTensorsToBuffers | ||||
: public LinalgOnTensorsToBuffersBase<ConvertLinalgOnTensorsToBuffers> { | : public LinalgOnTensorsToBuffersBase<ConvertLinalgOnTensorsToBuffers> { | ||||
void runOnOperation() override { | void runOnOperation() override { | ||||
MLIRContext &context = getContext(); | MLIRContext &context = getContext(); | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |
/*allowMemrefFunctionResults=*/false