MLIR 22.0.0git
ArithDialect.cpp
Go to the documentation of this file.
1//===- ArithDialect.cpp - MLIR Arith 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
15#include "mlir/IR/Builders.h"
19#include "llvm/ADT/TypeSwitch.h"
20
21using namespace mlir;
22using namespace mlir::arith;
23
24#include "mlir/Dialect/Arith/IR/ArithOpsDialect.cpp.inc"
25#include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.cpp.inc"
26#define GET_ATTRDEF_CLASSES
27#include "mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc"
28
29namespace {
30/// This class defines the interface for handling inlining for arithmetic
31/// dialect operations.
32struct ArithInlinerInterface : public DialectInlinerInterface {
34
35 /// All arithmetic dialect ops can be inlined.
36 bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
37 return true;
38 }
39};
40} // namespace
41
42void arith::ArithDialect::initialize() {
43 addOperations<
44#define GET_OP_LIST
45#include "mlir/Dialect/Arith/IR/ArithOps.cpp.inc"
46 >();
47 addAttributes<
48#define GET_ATTRDEF_LIST
49#include "mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc"
50 >();
51 addInterfaces<ArithInlinerInterface>();
52 declarePromisedInterface<ConvertToEmitCPatternInterface, ArithDialect>();
53 declarePromisedInterface<ConvertToLLVMPatternInterface, ArithDialect>();
54 declarePromisedInterface<bufferization::BufferDeallocationOpInterface,
55 SelectOp>();
56 declarePromisedInterfaces<bufferization::BufferizableOpInterface, ConstantOp,
57 IndexCastOp, SelectOp>();
58 declarePromisedInterfaces<ValueBoundsOpInterface, AddIOp, ConstantOp, SubIOp,
59 MulIOp>();
60}
61
62/// Materialize an integer or floating point constant.
63Operation *arith::ArithDialect::materializeConstant(OpBuilder &builder,
64 Attribute value, Type type,
65 Location loc) {
66 if (auto poison = dyn_cast<ub::PoisonAttr>(value))
67 return ub::PoisonOp::create(builder, loc, type, poison);
68
69 return ConstantOp::materialize(builder, value, type, loc);
70}
static bool isLegalToInline(InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, IRMapping &valueMapping)
Utility to check that all of the operations within 'src' can be inlined.
Attributes are known-constant values of operations.
Definition Attributes.h:25
This is the interface that must be implemented by the dialects of operations to be inlined.
DialectInlinerInterface(Dialect *dialect)
This is a utility class for mapping one set of IR entities to another.
Definition IRMapping.h:26
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:207
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
Include the generated interface declarations.