1 //===- Attributes.cpp - MLIR Affine Expr Classes --------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "mlir/IR/Attributes.h"
10 #include "mlir/IR/Dialect.h"
13 using namespace mlir::detail
;
15 //===----------------------------------------------------------------------===//
17 //===----------------------------------------------------------------------===//
19 void AbstractAttribute::walkImmediateSubElements(
20 Attribute attr
, function_ref
<void(Attribute
)> walkAttrsFn
,
21 function_ref
<void(Type
)> walkTypesFn
) const {
22 walkImmediateSubElementsFn(attr
, walkAttrsFn
, walkTypesFn
);
26 AbstractAttribute::replaceImmediateSubElements(Attribute attr
,
27 ArrayRef
<Attribute
> replAttrs
,
28 ArrayRef
<Type
> replTypes
) const {
29 return replaceImmediateSubElementsFn(attr
, replAttrs
, replTypes
);
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
36 /// Return the context this attribute belongs to.
37 MLIRContext
*Attribute::getContext() const { return getDialect().getContext(); }
39 //===----------------------------------------------------------------------===//
41 //===----------------------------------------------------------------------===//
43 NamedAttribute::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");
49 StringAttr
NamedAttribute::getName() const {
50 return llvm::cast
<StringAttr
>(name
);
53 Dialect
*NamedAttribute::getNameDialect() const {
54 return getName().getReferencedDialect();
57 void NamedAttribute::setName(StringAttr newName
) {
58 assert(name
&& "expected valid attribute name");
62 bool NamedAttribute::operator<(const NamedAttribute
&rhs
) const {
63 return getName().compare(rhs
.getName()) < 0;
66 bool NamedAttribute::operator<(StringRef rhs
) const {
67 return getName().getValue().compare(rhs
) < 0;