MLIR 23.0.0git
ArithToEmitCPass.cpp
Go to the documentation of this file.
1//===- ArithToEmitCPass.cpp - Arith to EmitC Pass ---------------*- 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// This file implements a pass to convert the Arith dialect to the EmitC
10// dialect.
11//
12//===----------------------------------------------------------------------===//
13
15
19#include "mlir/Pass/Pass.h"
21
22namespace mlir {
23#define GEN_PASS_DEF_CONVERTARITHTOEMITC
24#include "mlir/Conversion/Passes.h.inc"
25} // namespace mlir
26
27using namespace mlir;
28
29namespace {
30struct ConvertArithToEmitC
31 : public impl::ConvertArithToEmitCBase<ConvertArithToEmitC> {
32 void runOnOperation() override;
33};
34} // namespace
35
36void ConvertArithToEmitC::runOnOperation() {
37 ConversionTarget target(getContext());
38
39 target.addLegalDialect<emitc::EmitCDialect>();
40 target.addIllegalDialect<arith::ArithDialect>();
41
42 RewritePatternSet patterns(&getContext());
43
44 TypeConverter typeConverter;
45 // Fallback for other types.
46 typeConverter.addConversion([](Type type) -> std::optional<Type> {
48 return {};
49 return type;
50 });
51
52 populateArithToEmitCPatterns(typeConverter, patterns);
53
54 if (failed(
55 applyPartialConversion(getOperation(), target, std::move(patterns))))
56 signalPassFailure();
57}
b getContext())
bool isSupportedEmitCType(mlir::Type type)
Determines whether type is valid in EmitC.
Definition EmitC.cpp:62
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:717
Include the generated interface declarations.
void populateArithToEmitCPatterns(TypeConverter &typeConverter, RewritePatternSet &patterns)