1 //===- ArithmeticDialect.cpp - MLIR Arithmetic dialect 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/Dialect/Arithmetic/IR/Arithmetic.h"
10 #include "mlir/IR/Builders.h"
11 #include "mlir/Transforms/InliningUtils.h"
12
13 using namespace mlir;
14 using namespace mlir::arith;
15
16 #include "mlir/Dialect/Arithmetic/IR/ArithmeticOpsDialect.cpp.inc"
17
18 namespace {
19 /// This class defines the interface for handling inlining for arithmetic
20 /// dialect operations.
21 struct ArithmeticInlinerInterface : public DialectInlinerInterface {
22 using DialectInlinerInterface::DialectInlinerInterface;
23
24 /// All arithmetic dialect ops can be inlined.
isLegalToInline__anond5bc71810111::ArithmeticInlinerInterface25 bool isLegalToInline(Operation *, Region *, bool,
26 BlockAndValueMapping &) const final {
27 return true;
28 }
29 };
30 } // namespace
31
initialize()32 void arith::ArithmeticDialect::initialize() {
33 addOperations<
34 #define GET_OP_LIST
35 #include "mlir/Dialect/Arithmetic/IR/ArithmeticOps.cpp.inc"
36 >();
37 addInterfaces<ArithmeticInlinerInterface>();
38 }
39
40 /// Materialize an integer or floating point constant.
materializeConstant(OpBuilder & builder,Attribute value,Type type,Location loc)41 Operation *arith::ArithmeticDialect::materializeConstant(OpBuilder &builder,
42 Attribute value,
43 Type type,
44 Location loc) {
45 return builder.create<arith::ConstantOp>(loc, value, type);
46 }
47