MLIR  20.0.0git
UBOps.cpp
Go to the documentation of this file.
1 //===- UBOps.cpp - UB Dialect Operations ----------------------------------===//
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 
12 
13 #include "mlir/IR/Builders.h"
15 #include "llvm/ADT/TypeSwitch.h"
16 
17 #include "mlir/Dialect/UB/IR/UBOpsDialect.cpp.inc"
18 
19 using namespace mlir;
20 using namespace mlir::ub;
21 
22 namespace {
23 /// This class defines the interface for handling inlining with UB
24 /// operations.
25 struct UBInlinerInterface : public DialectInlinerInterface {
27 
28  /// All UB ops can be inlined.
29  bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
30  return true;
31  }
32 };
33 } // namespace
34 
35 //===----------------------------------------------------------------------===//
36 // UBDialect
37 //===----------------------------------------------------------------------===//
38 
39 void UBDialect::initialize() {
40  addOperations<
41 #define GET_OP_LIST
42 #include "mlir/Dialect/UB/IR/UBOps.cpp.inc"
43  >();
44  addAttributes<
45 #define GET_ATTRDEF_LIST
46 #include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"
47  >();
48  addInterfaces<UBInlinerInterface>();
49  declarePromisedInterface<ConvertToLLVMPatternInterface, UBDialect>();
50 }
51 
53  Type type, Location loc) {
54  if (auto attr = dyn_cast<PoisonAttr>(value))
55  return builder.create<PoisonOp>(loc, type, attr);
56 
57  return nullptr;
58 }
59 
60 OpFoldResult PoisonOp::fold(FoldAdaptor /*adaptor*/) { return getValue(); }
61 
62 #include "mlir/Dialect/UB/IR/UBOpsInterfaces.cpp.inc"
63 
64 #define GET_ATTRDEF_CLASSES
65 #include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"
66 
67 #define GET_OP_CLASSES
68 #include "mlir/Dialect/UB/IR/UBOps.cpp.inc"
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:66
This class helps build Operations.
Definition: Builders.h:215
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
Definition: Builders.cpp:497
This class represents a single result from folding an operation.
Definition: OpDefinition.h:268
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.