Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mlir/include/mlir/IR/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion mlir/include/mlir/IR/OperationSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions mlir/lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/IR/Builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
5 changes: 0 additions & 5 deletions mlir/lib/IR/OperationSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading