1 | //===- Bufferize.cpp - Bufferization of linalg ops ------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "mlir/Dialect/Linalg/Passes.h" |
10 | |
11 | #include "mlir/Dialect/Affine/IR/AffineOps.h" |
12 | #include "mlir/Dialect/Bufferization/IR/Bufferization.h" |
13 | #include "mlir/Dialect/Bufferization/Transforms/Bufferize.h" |
14 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
15 | #include "mlir/Dialect/Linalg/IR/Linalg.h" |
16 | #include "mlir/Dialect/Linalg/Transforms/BufferizableOpInterfaceImpl.h" |
17 | #include "mlir/Dialect/Linalg/Transforms/Transforms.h" |
18 | #include "mlir/Dialect/Tensor/IR/Tensor.h" |
19 | #include "mlir/IR/BuiltinDialect.h" |
20 | #include "mlir/IR/Operation.h" |
21 | #include "mlir/Pass/Pass.h" |
22 | |
23 | namespace mlir { |
24 | #define GEN_PASS_DEF_LINALGBUFFERIZEPASS |
25 | #include "mlir/Dialect/Linalg/Passes.h.inc" |
26 | } // namespace mlir |
27 | |
28 | using namespace mlir; |
29 | using namespace bufferization; |
30 | |
31 | namespace { |
32 | /// Converts Linalg operations that work on tensor-type operands or results to |
33 | /// work on buffers. |
34 | struct LinalgBufferizePass |
35 | : public impl::LinalgBufferizePassBase<LinalgBufferizePass> { |
36 | using impl::LinalgBufferizePassBase< |
37 | LinalgBufferizePass>::LinalgBufferizePassBase; |
38 | void runOnOperation() override { |
39 | BufferizationOptions options = getPartialBufferizationOptions(); |
40 | options.opFilter.allowDialect<linalg::LinalgDialect>(); |
41 | |
42 | if (failed(bufferizeOp(getOperation(), options))) |
43 | signalPassFailure(); |
44 | } |
45 | |
46 | void getDependentDialects(DialectRegistry ®istry) const override { |
47 | registry.insert<bufferization::BufferizationDialect, memref::MemRefDialect, |
48 | tensor::TensorDialect, linalg::LinalgDialect>(); |
49 | linalg::registerBufferizableOpInterfaceExternalModels(registry); |
50 | } |
51 | }; |
52 | } // namespace |
53 |