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 populateFuncToEmitCPatterns(patterns);
43
44 if (failed(
45 applyPartialConversion(getOperation(), target, std::move(patterns))))
46 signalPassFailure();
47}
48

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