2018-10-25 15:46:10 -07:00
|
|
|
//===- Attributes.cpp - MLIR Affine Expr Classes --------------------------===//
|
|
|
|
//
|
2020-01-26 03:58:30 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-23 09:35:36 -08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-10-25 15:46:10 -07:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-10-25 15:46:10 -07:00
|
|
|
|
|
|
|
#include "mlir/IR/Attributes.h"
|
2019-02-11 22:51:34 -08:00
|
|
|
#include "mlir/IR/Dialect.h"
|
2018-10-25 15:46:10 -07:00
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
using namespace mlir::detail;
|
|
|
|
|
2023-01-20 21:39:13 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AbstractAttribute
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void AbstractAttribute::walkImmediateSubElements(
|
|
|
|
Attribute attr, function_ref<void(Attribute)> walkAttrsFn,
|
|
|
|
function_ref<void(Type)> walkTypesFn) const {
|
|
|
|
walkImmediateSubElementsFn(attr, walkAttrsFn, walkTypesFn);
|
|
|
|
}
|
|
|
|
|
|
|
|
Attribute
|
|
|
|
AbstractAttribute::replaceImmediateSubElements(Attribute attr,
|
|
|
|
ArrayRef<Attribute> replAttrs,
|
|
|
|
ArrayRef<Type> replTypes) const {
|
|
|
|
return replaceImmediateSubElementsFn(attr, replAttrs, replTypes);
|
|
|
|
}
|
|
|
|
|
2019-05-02 14:02:57 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Attribute
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-05-06 12:40:43 -07:00
|
|
|
/// Return the context this attribute belongs to.
|
2020-12-17 17:10:12 -08:00
|
|
|
MLIRContext *Attribute::getContext() const { return getDialect().getContext(); }
|
2019-05-06 12:40:43 -07:00
|
|
|
|
2019-05-15 09:10:52 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-12-03 17:22:57 -08:00
|
|
|
// NamedAttribute
|
2019-05-15 09:10:52 -07:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-11-18 05:23:32 +00:00
|
|
|
NamedAttribute::NamedAttribute(StringAttr name, Attribute value)
|
|
|
|
: name(name), value(value) {
|
|
|
|
assert(name && value && "expected valid attribute name and value");
|
2023-09-27 07:15:03 +00:00
|
|
|
assert(!name.empty() && "expected valid attribute name");
|
2020-05-06 13:48:36 -07:00
|
|
|
}
|
2021-11-18 05:23:32 +00:00
|
|
|
|
2025-01-22 19:02:17 -05:00
|
|
|
NamedAttribute::NamedAttribute(StringRef name, Attribute value) : value(value) {
|
|
|
|
assert(value && "expected valid attribute value");
|
|
|
|
assert(!name.empty() && "expected valid attribute name");
|
|
|
|
this->name = StringAttr::get(value.getContext(), name);
|
|
|
|
}
|
|
|
|
|
2023-05-11 11:10:46 +02:00
|
|
|
StringAttr NamedAttribute::getName() const {
|
|
|
|
return llvm::cast<StringAttr>(name);
|
|
|
|
}
|
2021-11-18 05:23:32 +00:00
|
|
|
|
|
|
|
Dialect *NamedAttribute::getNameDialect() const {
|
|
|
|
return getName().getReferencedDialect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NamedAttribute::setName(StringAttr newName) {
|
|
|
|
assert(name && "expected valid attribute name");
|
|
|
|
name = newName;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NamedAttribute::operator<(const NamedAttribute &rhs) const {
|
|
|
|
return getName().compare(rhs.getName()) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NamedAttribute::operator<(StringRef rhs) const {
|
|
|
|
return getName().getValue().compare(rhs) < 0;
|
2020-05-06 13:48:36 -07:00
|
|
|
}
|