brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · bd0499f Raw
56 lines · cpp
1//===-- CUFAttr.cpp -------------------------------------------------------===//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// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/10//11//===----------------------------------------------------------------------===//12 13#include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h"14#include "flang/Optimizer/Dialect/CUF/CUFDialect.h"15#include "mlir/IR/Builders.h"16#include "mlir/IR/BuiltinTypes.h"17#include "mlir/IR/DialectImplementation.h"18#include "mlir/IR/OpDefinition.h"19#include "mlir/IR/Operation.h"20#include "llvm/ADT/TypeSwitch.h"21 22#include "flang/Optimizer/Dialect/CUF/Attributes/CUFEnumAttr.cpp.inc"23#define GET_ATTRDEF_CLASSES24#include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.cpp.inc"25 26namespace cuf {27 28void CUFDialect::registerAttributes() {29  addAttributes<ClusterDimsAttr, DataAttributeAttr, DataTransferKindAttr,30                LaunchBoundsAttr, ProcAttributeAttr>();31}32 33cuf::DataAttributeAttr getDataAttr(mlir::Operation *op) {34  if (!op)35    return {};36 37  if (auto dataAttr =38          op->getAttrOfType<cuf::DataAttributeAttr>(cuf::getDataAttrName()))39    return dataAttr;40 41  // When the attribute is declared on the operation, it doesn't have a prefix.42  if (auto dataAttr =43          op->getAttrOfType<cuf::DataAttributeAttr>(cuf::dataAttrName))44    return dataAttr;45 46  return {};47}48 49bool hasDataAttr(mlir::Operation *op, cuf::DataAttribute value) {50  if (auto dataAttr = getDataAttr(op))51    return dataAttr.getValue() == value;52  return false;53}54 55} // namespace cuf56