MLIR  21.0.0git
MathToEmitCPass.cpp
Go to the documentation of this file.
1 //===- MathToEmitCPass.cpp - Math 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 Math dialect to the EmitC dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
17 #include "mlir/Pass/Pass.h"
19 
20 namespace mlir {
21 #define GEN_PASS_DEF_CONVERTMATHTOEMITC
22 #include "mlir/Conversion/Passes.h.inc"
23 } // namespace mlir
24 
25 using namespace mlir;
26 namespace {
27 
28 // Replaces Math operations with `emitc.call_opaque` operations.
29 struct ConvertMathToEmitC
30  : public impl::ConvertMathToEmitCBase<ConvertMathToEmitC> {
31  using ConvertMathToEmitCBase::ConvertMathToEmitCBase;
32 
33 public:
34  void runOnOperation() final;
35 };
36 
37 } // namespace
38 
39 void ConvertMathToEmitC::runOnOperation() {
40  ConversionTarget target(getContext());
41  target.addLegalOp<emitc::CallOpaqueOp>();
42 
43  target.addIllegalOp<math::FloorOp, math::ExpOp, math::RoundOp, math::CosOp,
44  math::SinOp, math::Atan2Op, math::CeilOp, math::AcosOp,
45  math::AsinOp, math::AbsFOp, math::PowFOp>();
46 
49 
50  if (failed(
51  applyPartialConversion(getOperation(), target, std::move(patterns))))
52  signalPassFailure();
53 }
static MLIRContext * getContext(OpFoldResult val)
This class describes a specific conversion target.
Include the generated interface declarations.
void populateConvertMathToEmitCPatterns(RewritePatternSet &patterns, emitc::LanguageTarget languageTarget)
Definition: MathToEmitC.cpp:60
const FrozenRewritePatternSet & patterns
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.