MLIR 24.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"
14
15#include "mlir/Dialect/UB/IR/UBOpsDialect.cpp.inc"
16
17using namespace mlir;
18using namespace mlir::ub;
19
20namespace {
21/// This class defines the interface for handling inlining with UB
22/// operations.
23struct UBInlinerInterface : public DialectInlinerInterface {
24 using DialectInlinerInterface::DialectInlinerInterface;
25
26 /// All UB ops can be inlined.
27 bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
28 return true;
29 }
30};
31} // namespace
32
33//===----------------------------------------------------------------------===//
34// UBDialect
35//===----------------------------------------------------------------------===//
36
37void UBDialect::initialize() {
38 addOperations<
39#define GET_OP_LIST
40#include "mlir/Dialect/UB/IR/UBOps.cpp.inc"
41 >();
42 addAttributes<
43#define GET_ATTRDEF_LIST
44#include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"
45 >();
46 addInterfaces<UBInlinerInterface>();
47 declarePromisedInterface<ConvertToLLVMPatternInterface, UBDialect>();
48}
49
50Operation *UBDialect::materializeConstant(OpBuilder &builder, Attribute value,
51 Type type, Location loc) {
52 if (auto attr = dyn_cast<PoisonAttr>(value))
53 return PoisonOp::create(builder, loc, type, attr);
54
55 return nullptr;
56}
57
58OpFoldResult PoisonOp::fold(FoldAdaptor /*adaptor*/) { return getValue(); }
59
60#include "mlir/Dialect/UB/IR/UBOpsInterfaces.cpp.inc"
61
62#define GET_ATTRDEF_CLASSES
63#include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"
64
65#define GET_OP_CLASSES
66#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:210
This class represents a single result from folding an operation.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
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.