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 addInterfaces<ArithInlinerInterface>();
42 declarePromisedInterface<ConvertToEmitCPatternInterface, ArithDialect>();
43 declarePromisedInterface<ConvertToLLVMPatternInterface, ArithDialect>();
44 declarePromisedInterface<bufferization::BufferDeallocationOpInterface,
45 SelectOp>();
46 declarePromisedInterfaces<bufferization::BufferizableOpInterface, ConstantOp,
47 IndexCastOp, SelectOp>();
48 declarePromisedInterfaces<ValueBoundsOpInterface, ConstantOp, ExtSIOp, AddIOp,
49 SubIOp, MulIOp, SelectOp, FloorDivSIOp, CeilDivSIOp,
50 MinSIOp, MaxSIOp, MinUIOp, MaxUIOp, RemSIOp,
51 RemUIOp, DivUIOp, DivSIOp>();
52}
53
54/// Materialize an integer or floating point constant.
55Operation *arith::ArithDialect::materializeConstant(OpBuilder &builder,
56 Attribute value, Type type,
57 Location loc) {
58 if (auto poison = dyn_cast<ub::PoisonAttr>(value))
59 return ub::PoisonOp::create(builder, loc, type, poison);
60
61 return ConstantOp::materialize(builder, value, type, loc);
62}
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.