1 | //===- MemRefToEmitC.cpp - MemRef to EmitC conversion ---------------------===// |
---|---|
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 | // This file implements a pass to convert memref ops into emitc ops. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "mlir/Conversion/MemRefToEmitC/MemRefToEmitCPass.h" |
14 | |
15 | #include "mlir/Conversion/MemRefToEmitC/MemRefToEmitC.h" |
16 | #include "mlir/Dialect/EmitC/IR/EmitC.h" |
17 | #include "mlir/Dialect/MemRef/IR/MemRef.h" |
18 | #include "mlir/Pass/Pass.h" |
19 | #include "mlir/Transforms/DialectConversion.h" |
20 | |
21 | namespace mlir { |
22 | #define GEN_PASS_DEF_CONVERTMEMREFTOEMITC |
23 | #include "mlir/Conversion/Passes.h.inc" |
24 | } // namespace mlir |
25 | |
26 | using namespace mlir; |
27 | |
28 | namespace { |
29 | struct ConvertMemRefToEmitCPass |
30 | : public impl::ConvertMemRefToEmitCBase<ConvertMemRefToEmitCPass> { |
31 | void runOnOperation() override { |
32 | TypeConverter converter; |
33 | |
34 | // Fallback for other types. |
35 | converter.addConversion([](Type type) -> std::optional<Type> { |
36 | if (isa<MemRefType>(type)) |
37 | return {}; |
38 | return type; |
39 | }); |
40 | |
41 | populateMemRefToEmitCTypeConversion(typeConverter&: converter); |
42 | |
43 | RewritePatternSet patterns(&getContext()); |
44 | populateMemRefToEmitCConversionPatterns(patterns, converter); |
45 | |
46 | ConversionTarget target(getContext()); |
47 | target.addIllegalDialect<memref::MemRefDialect>(); |
48 | target.addLegalDialect<emitc::EmitCDialect>(); |
49 | |
50 | if (failed(applyPartialConversion(getOperation(), target, |
51 | std::move(patterns)))) |
52 | return signalPassFailure(); |
53 | } |
54 | }; |
55 | } // namespace |
56 |