-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir] Add NamedAttribute ctor taking StringRef. NFC. #123974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a small QoL improvement so that we don't have to go through helpers when building `NamedAttribute`s.
Member
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Jakub Kuderski (kuhar) ChangesThis is a small QoL improvement so that we don't have to go through helpers when building Full diff: https://github.com/llvm/llvm-project/pull/123974.diff 5 Files Affected:
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);
|
River707
approved these changes
Jan 22, 2025
kuhar
added a commit
to kuhar/iree
that referenced
this pull request
Jan 25, 2025
With llvm/llvm-project#123974, we no longer have to construct a StringAttr for the name and can simplify a bunch of code. Also avoid some needless memory allocations and needless small vectors in related code.
kuhar
added a commit
to iree-org/iree
that referenced
this pull request
Jan 25, 2025
With llvm/llvm-project#123974, we no longer have to construct a StringAttr for the name and can simplify a bunch of code. Also avoid some needless memory allocations and needless small vectors in related code.
ita9naiwa
pushed a commit
to ita9naiwa/iree
that referenced
this pull request
Feb 4, 2025
With llvm/llvm-project#123974, we no longer have to construct a StringAttr for the name and can simplify a bunch of code. Also avoid some needless memory allocations and needless small vectors in related code. Signed-off-by: Hyunsung Lee <[email protected]>
AWoloszyn
pushed a commit
to iree-org/iree
that referenced
this pull request
Dec 1, 2025
With llvm/llvm-project#123974, we no longer have to construct a StringAttr for the name and can simplify a bunch of code. Also avoid some needless memory allocations and needless small vectors in related code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a small QoL improvement so that we don't have to go through helpers when building
NamedAttributes.