1 | //====----- Bufferize.cpp - Bufferization of shape ops ---------*- C++-*--===// |
---|---|
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/Shape/Transforms/Passes.h" |
10 | |
11 | #include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.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/MemRef/IR/MemRef.h" |
16 | #include "mlir/Dialect/Shape/IR/Shape.h" |
17 | #include "mlir/Dialect/Shape/Transforms/BufferizableOpInterfaceImpl.h" |
18 | #include "mlir/Pass/Pass.h" |
19 | |
20 | namespace mlir { |
21 | #define GEN_PASS_DEF_SHAPEBUFFERIZE |
22 | #include "mlir/Dialect/Shape/Transforms/Passes.h.inc" |
23 | } // namespace mlir |
24 | |
25 | using namespace mlir; |
26 | using namespace bufferization; |
27 | |
28 | namespace { |
29 | struct ShapeBufferizePass |
30 | : public impl::ShapeBufferizeBase<ShapeBufferizePass> { |
31 | void runOnOperation() override { |
32 | BufferizationOptions options = getPartialBufferizationOptions(); |
33 | options.opFilter.allowDialect<shape::ShapeDialect>(); |
34 | |
35 | if (failed(bufferizeOp(getOperation(), options))) |
36 | signalPassFailure(); |
37 | } |
38 | |
39 | void getDependentDialects(DialectRegistry ®istry) const override { |
40 | registry.insert<bufferization::BufferizationDialect, memref::MemRefDialect, |
41 | shape::ShapeDialect>(); |
42 | shape::registerBufferizableOpInterfaceExternalModels(registry); |
43 | } |
44 | }; |
45 | } // namespace |
46 | |
47 | std::unique_ptr<OperationPass<func::FuncOp>> mlir::createShapeBufferizePass() { |
48 | return std::make_unique<ShapeBufferizePass>(); |
49 | } |
50 |