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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "mlir/IR/Attributes.h"
10 #include "mlir/IR/Dialect.h"
11 
12 using namespace mlir;
13 using namespace mlir::detail;
14 
15 //===----------------------------------------------------------------------===//
16 // Attribute
17 //===----------------------------------------------------------------------===//
18 
19 /// Return the context this attribute belongs to.
getContext() const20 MLIRContext *Attribute::getContext() const { return getDialect().getContext(); }
21 
22 //===----------------------------------------------------------------------===//
23 // NamedAttribute
24 //===----------------------------------------------------------------------===//
25 
NamedAttribute(StringAttr name,Attribute value)26 NamedAttribute::NamedAttribute(StringAttr name, Attribute value)
27     : name(name), value(value) {
28   assert(name && value && "expected valid attribute name and value");
29   assert(name.size() != 0 && "expected valid attribute name");
30 }
31 
getName() const32 StringAttr NamedAttribute::getName() const { return name.cast<StringAttr>(); }
33 
getNameDialect() const34 Dialect *NamedAttribute::getNameDialect() const {
35   return getName().getReferencedDialect();
36 }
37 
setName(StringAttr newName)38 void NamedAttribute::setName(StringAttr newName) {
39   assert(name && "expected valid attribute name");
40   name = newName;
41 }
42 
operator <(const NamedAttribute & rhs) const43 bool NamedAttribute::operator<(const NamedAttribute &rhs) const {
44   return getName().compare(rhs.getName()) < 0;
45 }
46 
operator <(StringRef rhs) const47 bool NamedAttribute::operator<(StringRef rhs) const {
48   return getName().getValue().compare(rhs) < 0;
49 }
50