brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · ff1cd84 Raw
75 lines · cpp
1//===- Attributes.cpp - MLIR Affine Expr Classes --------------------------===//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/IR/Attributes.h"10#include "mlir/IR/Dialect.h"11 12using namespace mlir;13using namespace mlir::detail;14 15//===----------------------------------------------------------------------===//16// AbstractAttribute17//===----------------------------------------------------------------------===//18 19void AbstractAttribute::walkImmediateSubElements(20    Attribute attr, function_ref<void(Attribute)> walkAttrsFn,21    function_ref<void(Type)> walkTypesFn) const {22  walkImmediateSubElementsFn(attr, walkAttrsFn, walkTypesFn);23}24 25Attribute26AbstractAttribute::replaceImmediateSubElements(Attribute attr,27                                               ArrayRef<Attribute> replAttrs,28                                               ArrayRef<Type> replTypes) const {29  return replaceImmediateSubElementsFn(attr, replAttrs, replTypes);30}31 32//===----------------------------------------------------------------------===//33// Attribute34//===----------------------------------------------------------------------===//35 36/// Return the context this attribute belongs to.37MLIRContext *Attribute::getContext() const { return getDialect().getContext(); }38 39//===----------------------------------------------------------------------===//40// NamedAttribute41//===----------------------------------------------------------------------===//42 43NamedAttribute::NamedAttribute(StringAttr name, Attribute value)44    : name(name), value(value) {45  assert(name && value && "expected valid attribute name and value");46  assert(!name.empty() && "expected valid attribute name");47}48 49NamedAttribute::NamedAttribute(StringRef name, Attribute value) : value(value) {50  assert(value && "expected valid attribute value");51  assert(!name.empty() && "expected valid attribute name");52  this->name = StringAttr::get(value.getContext(), name);53}54 55StringAttr NamedAttribute::getName() const {56  return llvm::cast<StringAttr>(name);57}58 59Dialect *NamedAttribute::getNameDialect() const {60  return getName().getReferencedDialect();61}62 63void NamedAttribute::setName(StringAttr newName) {64  assert(name && "expected valid attribute name");65  name = newName;66}67 68bool NamedAttribute::operator<(const NamedAttribute &rhs) const {69  return getName().compare(rhs.getName()) < 0;70}71 72bool NamedAttribute::operator<(StringRef rhs) const {73  return getName().getValue().compare(rhs) < 0;74}75