[Mlir-commits] [mlir] [mlir] Add NamedAttribute ctor taking StringRef. NFC. (PR #123974)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jan 22 09:52:01 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Jakub Kuderski (kuhar)
<details>
<summary>Changes</summary>
This is a small QoL improvement so that we don't have to go through helpers when building `NamedAttribute`s.
---
Full diff: https://github.com/llvm/llvm-project/pull/123974.diff
5 Files Affected:
- (modified) mlir/include/mlir/IR/Attributes.h (+1)
- (modified) mlir/include/mlir/IR/OperationSupport.h (+3-1)
- (modified) mlir/lib/IR/Attributes.cpp (+6)
- (modified) mlir/lib/IR/Builders.cpp (+1-1)
- (modified) mlir/lib/IR/OperationSupport.cpp (-5)
``````````diff
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index d347013295d5fc..262d31b20ab084 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -207,6 +207,7 @@ inline ::llvm::hash_code hash_value(Attribute arg) {
class NamedAttribute {
public:
NamedAttribute(StringAttr name, Attribute value);
+ NamedAttribute(StringRef name, Attribute value);
/// Return the name of the attribute.
StringAttr getName() const;
diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 5eb2d69134ea5f..d4035d14ab7465 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -819,7 +819,9 @@ class NamedAttrList {
}
/// Add an attribute with the specified name.
- void append(StringRef name, Attribute attr);
+ void append(StringRef name, Attribute attr) {
+ append(NamedAttribute(name, attr));
+ }
/// Add an attribute with the specified name.
void append(StringAttr name, Attribute attr) {
diff --git a/mlir/lib/IR/Attributes.cpp b/mlir/lib/IR/Attributes.cpp
index cc7a2a5e586b1c..ff1cd8432fb07d 100644
--- a/mlir/lib/IR/Attributes.cpp
+++ b/mlir/lib/IR/Attributes.cpp
@@ -46,6 +46,12 @@ NamedAttribute::NamedAttribute(StringAttr name, Attribute value)
assert(!name.empty() && "expected valid attribute name");
}
+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);
+}
+
StringAttr NamedAttribute::getName() const {
return llvm::cast<StringAttr>(name);
}
diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp
index d57a7ca07ede58..16bd8201ad50a6 100644
--- a/mlir/lib/IR/Builders.cpp
+++ b/mlir/lib/IR/Builders.cpp
@@ -88,7 +88,7 @@ NoneType Builder::getNoneType() { return NoneType::get(context); }
//===----------------------------------------------------------------------===//
NamedAttribute Builder::getNamedAttr(StringRef name, Attribute val) {
- return NamedAttribute(getStringAttr(name), val);
+ return NamedAttribute(name, val);
}
UnitAttr Builder::getUnitAttr() { return UnitAttr::get(context); }
diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp
index 957195202d78d2..1b2cda19de1e80 100644
--- a/mlir/lib/IR/OperationSupport.cpp
+++ b/mlir/lib/IR/OperationSupport.cpp
@@ -62,11 +62,6 @@ DictionaryAttr NamedAttrList::getDictionary(MLIRContext *context) const {
return llvm::cast<DictionaryAttr>(dictionarySorted.getPointer());
}
-/// Add an attribute with the specified name.
-void NamedAttrList::append(StringRef name, Attribute attr) {
- append(StringAttr::get(attr.getContext(), name), attr);
-}
-
/// Replaces the attributes with new list of attributes.
void NamedAttrList::assign(const_iterator inStart, const_iterator inEnd) {
DictionaryAttr::sort(ArrayRef<NamedAttribute>{inStart, inEnd}, attrs);
``````````
</details>
https://github.com/llvm/llvm-project/pull/123974
More information about the Mlir-commits
mailing list