1 | //===- Bufferize.cpp - scf bufferize pass ---------------------------------===// |
---|---|
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/SCF/Transforms/Passes.h" |
10 | |
11 | #include "mlir/Dialect/Bufferization/IR/Bufferization.h" |
12 | #include "mlir/Dialect/Bufferization/Transforms/Bufferize.h" |
13 | #include "mlir/Dialect/MemRef/IR/MemRef.h" |
14 | #include "mlir/Dialect/SCF/IR/SCF.h" |
15 | #include "mlir/Dialect/SCF/Transforms/Patterns.h" |
16 | #include "mlir/Transforms/DialectConversion.h" |
17 | |
18 | namespace mlir { |
19 | #define GEN_PASS_DEF_SCFBUFFERIZE |
20 | #include "mlir/Dialect/SCF/Transforms/Passes.h.inc" |
21 | } // namespace mlir |
22 | |
23 | using namespace mlir; |
24 | using namespace mlir::scf; |
25 | |
26 | namespace { |
27 | struct SCFBufferizePass : public impl::SCFBufferizeBase<SCFBufferizePass> { |
28 | void runOnOperation() override { |
29 | auto *func = getOperation(); |
30 | auto *context = &getContext(); |
31 | |
32 | bufferization::BufferizeTypeConverter typeConverter; |
33 | RewritePatternSet patterns(context); |
34 | ConversionTarget target(*context); |
35 | |
36 | bufferization::populateBufferizeMaterializationLegality(target); |
37 | populateSCFStructuralTypeConversionsAndLegality(typeConverter, patterns, |
38 | target); |
39 | if (failed(applyPartialConversion(func, target, std::move(patterns)))) |
40 | return signalPassFailure(); |
41 | }; |
42 | }; |
43 | } // namespace |
44 | |
45 | std::unique_ptr<Pass> mlir::createSCFBufferizePass() { |
46 | return std::make_unique<SCFBufferizePass>(); |
47 | } |
48 |