brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · ee523f9 Raw
69 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Dialect/UB/IR/UBOps.h"10#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"11#include "mlir/Transforms/InliningUtils.h"12 13#include "mlir/IR/Builders.h"14#include "mlir/IR/DialectImplementation.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 UB24/// 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} // namespace34 35//===----------------------------------------------------------------------===//36// UBDialect37//===----------------------------------------------------------------------===//38 39void UBDialect::initialize() {40  addOperations<41#define GET_OP_LIST42#include "mlir/Dialect/UB/IR/UBOps.cpp.inc"43      >();44  addAttributes<45#define GET_ATTRDEF_LIST46#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_CLASSES65#include "mlir/Dialect/UB/IR/UBOpsAttributes.cpp.inc"66 67#define GET_OP_CLASSES68#include "mlir/Dialect/UB/IR/UBOps.cpp.inc"69