1 //===- ArithToEmitCPass.cpp - Arith to EmitC Pass ---------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements a pass to convert the Arith dialect to the EmitC
12 //===----------------------------------------------------------------------===//
14 #include "mlir/Conversion/ArithToEmitC/ArithToEmitCPass.h"
16 #include "mlir/Conversion/ArithToEmitC/ArithToEmitC.h"
17 #include "mlir/Dialect/Arith/IR/Arith.h"
18 #include "mlir/Dialect/EmitC/IR/EmitC.h"
19 #include "mlir/Pass/Pass.h"
20 #include "mlir/Transforms/DialectConversion.h"
23 #define GEN_PASS_DEF_CONVERTARITHTOEMITC
24 #include "mlir/Conversion/Passes.h.inc"
30 struct ConvertArithToEmitC
31 : public impl::ConvertArithToEmitCBase
<ConvertArithToEmitC
> {
32 void runOnOperation() override
;
36 void ConvertArithToEmitC::runOnOperation() {
37 ConversionTarget
target(getContext());
39 target
.addLegalDialect
<emitc::EmitCDialect
>();
40 target
.addIllegalDialect
<arith::ArithDialect
>();
42 RewritePatternSet
patterns(&getContext());
44 TypeConverter typeConverter
;
45 typeConverter
.addConversion([](Type type
) { return type
; });
47 populateArithToEmitCPatterns(typeConverter
, patterns
);
50 applyPartialConversion(getOperation(), target
, std::move(patterns
))))