MLIR 22.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
19using namespace mlir;
20using namespace mlir::ub;
21
22namespace {
23/// This class defines the interface for handling inlining with UB
24/// operations.
25struct UBInlinerInterface : public DialectInlinerInterface {
26 using DialectInlinerInterface::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
39void 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
52Operation *UBDialect::materializeConstant(OpBuilder &builder, Attribute value,
53 Type type, Location loc) {
54 if (auto attr = dyn_cast<PoisonAttr>(value))
55 return PoisonOp::create(builder, loc, type, attr);
56
57 return nullptr;
58}
59
60OpFoldResult 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 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 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
This class represents a single result from folding an operation.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
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.