1//===- FuncToEmitCPass.cpp - Func 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 Func dialect to the EmitC dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir/Conversion/FuncToEmitC/FuncToEmitCPass.h"
14
15#include "mlir/Conversion/FuncToEmitC/FuncToEmitC.h"
16#include "mlir/Dialect/EmitC/IR/EmitC.h"
17#include "mlir/Dialect/Func/IR/FuncOps.h"
18#include "mlir/Pass/Pass.h"
19#include "mlir/Transforms/DialectConversion.h"
20
21namespace mlir {
22#define GEN_PASS_DEF_CONVERTFUNCTOEMITC
23#include "mlir/Conversion/Passes.h.inc"
24} // namespace mlir
25
26using namespace mlir;
27
28namespace {
29struct ConvertFuncToEmitC
30 : public impl::ConvertFuncToEmitCBase<ConvertFuncToEmitC> {
31 void runOnOperation() override;
32};
33} // namespace
34
35void ConvertFuncToEmitC::runOnOperation() {
36 ConversionTarget target(getContext());
37
38 target.addLegalDialect<emitc::EmitCDialect>();
39 target.addIllegalOp<func::CallOp, func::FuncOp, func::ReturnOp>();
40
41 RewritePatternSet patterns(&getContext());
42
43 TypeConverter typeConverter;
44 typeConverter.addConversion(callback: [](Type type) { return type; });
45
46 populateFuncToEmitCPatterns(typeConverter, patterns);
47
48 if (failed(
49 applyPartialConversion(getOperation(), target, std::move(patterns))))
50 signalPassFailure();
51}
52

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of mlir/lib/Conversion/FuncToEmitC/FuncToEmitCPass.cpp