xref: /llvm-project/mlir/lib/Dialect/Math/IR/MathDialect.cpp (revision 35d55f2894a2a2cdca5db494f519aa5ec7273678)
1 //===- MathDialect.cpp - MLIR dialect for Math implementation -------------===//
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 #include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
10 #include "mlir/Dialect/Math/IR/Math.h"
11 #include "mlir/Dialect/UB/IR/UBOps.h"
12 #include "mlir/Transforms/InliningUtils.h"
13 
14 using namespace mlir;
15 using namespace mlir::math;
16 
17 #include "mlir/Dialect/Math/IR/MathOpsDialect.cpp.inc"
18 
19 namespace {
20 /// This class defines the interface for handling inlining with math
21 /// operations.
22 struct MathInlinerInterface : public DialectInlinerInterface {
23   using DialectInlinerInterface::DialectInlinerInterface;
24 
25   /// All operations within math ops can be inlined.
isLegalToInline__anon380f2e240111::MathInlinerInterface26   bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
27     return true;
28   }
29 };
30 } // namespace
31 
initialize()32 void mlir::math::MathDialect::initialize() {
33   addOperations<
34 #define GET_OP_LIST
35 #include "mlir/Dialect/Math/IR/MathOps.cpp.inc"
36       >();
37   addInterfaces<MathInlinerInterface>();
38   declarePromisedInterface<ConvertToLLVMPatternInterface, MathDialect>();
39 }
40