MLIR  19.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 
14 #include "mlir/IR/Builders.h"
18 #include "llvm/ADT/TypeSwitch.h"
19 
20 using namespace mlir;
21 using namespace mlir::arith;
22 
23 #include "mlir/Dialect/Arith/IR/ArithOpsDialect.cpp.inc"
24 #include "mlir/Dialect/Arith/IR/ArithOpsInterfaces.cpp.inc"
25 #define GET_ATTRDEF_CLASSES
26 #include "mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc"
27 
28 namespace {
29 /// This class defines the interface for handling inlining for arithmetic
30 /// dialect operations.
31 struct ArithInlinerInterface : public DialectInlinerInterface {
33 
34  /// All arithmetic dialect ops can be inlined.
35  bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
36  return true;
37  }
38 };
39 } // namespace
40 
41 void arith::ArithDialect::initialize() {
42  addOperations<
43 #define GET_OP_LIST
44 #include "mlir/Dialect/Arith/IR/ArithOps.cpp.inc"
45  >();
46  addAttributes<
47 #define GET_ATTRDEF_LIST
48 #include "mlir/Dialect/Arith/IR/ArithOpsAttributes.cpp.inc"
49  >();
50  addInterfaces<ArithInlinerInterface>();
51  declarePromisedInterface<ConvertToLLVMPatternInterface, ArithDialect>();
52  declarePromisedInterface<bufferization::BufferDeallocationOpInterface,
53  SelectOp>();
54  declarePromisedInterfaces<bufferization::BufferizableOpInterface, ConstantOp,
55  IndexCastOp, SelectOp>();
56  declarePromisedInterfaces<ValueBoundsOpInterface, AddIOp, ConstantOp, SubIOp,
57  MulIOp>();
58 }
59 
60 /// Materialize an integer or floating point constant.
62  Attribute value, Type type,
63  Location loc) {
64  if (auto poison = dyn_cast<ub::PoisonAttr>(value))
65  return builder.create<ub::PoisonOp>(loc, type, poison);
66 
67  return ConstantOp::materialize(builder, value, type, loc);
68 }
static Operation * materializeConstant(Dialect *dialect, OpBuilder &builder, Attribute value, Type type, Location loc)
A utility function used to materialize a constant for a given attribute and type.
Definition: FoldUtils.cpp:50
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.
Definition: InliningUtils.h:44
DialectInlinerInterface(Dialect *dialect)
Definition: InliningUtils.h:46
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:63
This class helps build Operations.
Definition: Builders.h:209
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition: Builders.cpp:464
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.