MLIR 24.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"
18
19using namespace mlir;
20using namespace mlir::arith;
21
22#include "mlir/Dialect/Arith/IR/ArithOpsDialect.cpp.inc"
23#include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.cpp.inc"
24#define GET_ATTRDEF_CLASSES
25#include "mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc"
26
27namespace {
28/// This class defines the interface for handling inlining for arithmetic
29/// dialect operations.
30struct ArithInlinerInterface : public DialectInlinerInterface {
31 using DialectInlinerInterface::DialectInlinerInterface;
32
33 /// All arithmetic dialect ops can be inlined.
34 bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
35 return true;
36 }
37};
38} // namespace
39
40void arith::ArithDialect::initialize() {
41 addOperations<
42#define GET_OP_LIST
43#include "mlir/Dialect/Arith/IR/ArithOps.cpp.inc"
44 >();
45 addAttributes<
46#define GET_ATTRDEF_LIST
47#include "mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc"
48 >();
49 addInterfaces<ArithInlinerInterface>();
50 declarePromisedInterface<ConvertToEmitCPatternInterface, ArithDialect>();
51 declarePromisedInterface<ConvertToLLVMPatternInterface, ArithDialect>();
52 declarePromisedInterface<bufferization::BufferDeallocationOpInterface,
53 SelectOp>();
54 declarePromisedInterfaces<bufferization::BufferizableOpInterface, ConstantOp,
55 IndexCastOp, SelectOp>();
56 declarePromisedInterfaces<ValueBoundsOpInterface, ConstantOp, ExtSIOp, AddIOp,
57 SubIOp, MulIOp, SelectOp, FloorDivSIOp, CeilDivSIOp,
58 MinSIOp, MaxSIOp, MinUIOp, MaxUIOp, RemSIOp,
59 RemUIOp, DivUIOp, DivSIOp>();
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 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:210
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
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.