diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -257,6 +257,12 @@ void set(Identifier name, Attribute value); void set(StringRef name, Attribute value); + /// Erase the attribute with the given name from the list. Return the + /// attribute that was erase, or nullptr if there was no attribute with such + /// name. + Attribute erase(Identifier name); + Attribute erase(StringRef name); + const_iterator begin() const { return attrs.begin(); } const_iterator end() const { return attrs.end(); } @@ -268,6 +274,9 @@ /// Return whether the attributes are sorted. bool isSorted() const { return dictionarySorted.getInt(); } + /// Erase the attribute at the given iterator position. + Attribute eraseImpl(SmallVectorImpl::iterator it); + // These are marked mutable as they may be modified (e.g., sorted) mutable SmallVector attrs; // Pair with cached DictionaryAttr and status of whether attrs is sorted. diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -143,6 +143,17 @@ parser.getCurrentLocation(&trailingTypeLoc) || parser.parseType(type)) return failure(); + Optional alignmentAttr = + result.attributes.getNamed("alignment"); + if (alignmentAttr.hasValue()) { + auto alignmentInt = alignmentAttr.getValue().second.dyn_cast(); + if (!alignmentInt) + return parser.emitError(parser.getNameLoc(), + "expected integer alignemnt"); + if (alignmentInt.getValue().isNullValue()) + result.attributes.erase("alignment"); + } + // Extract the result type from the trailing function type. auto funcType = type.dyn_cast(); if (!funcType || funcType.getNumInputs() != 1 || diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -150,6 +150,26 @@ return set(mlir::Identifier::get(name, value.getContext()), value); } +Attribute +NamedAttrList::eraseImpl(SmallVectorImpl::iterator it) { + if (it == attrs.end()) + return nullptr; + + // Erasing does not affect the sorted property. + Attribute attr = it->second; + attrs.erase(it); + dictionarySorted.setPointer(nullptr); + return attr; +} + +Attribute NamedAttrList::erase(Identifier name) { + return eraseImpl(findAttr(attrs, name, isSorted())); +} + +Attribute NamedAttrList::erase(StringRef name) { + return eraseImpl(findAttr(attrs, name, isSorted())); +} + NamedAttrList & NamedAttrList::operator=(const SmallVectorImpl &rhs) { assign(rhs.begin(), rhs.end());