[Mlir-commits] [mlir] [mlir] fix Operation::getDiscardableAttrs in absence of properties (PR #76816)
Mehdi Amini
llvmlistbot at llvm.org
Wed Jan 3 06:05:35 PST 2024
================
@@ -475,19 +475,31 @@ class alignas(8) Operation final
return removeDiscardableAttr(StringAttr::get(getContext(), name));
}
- /// Return all of the discardable attributes on this operation.
- ArrayRef<NamedAttribute> getDiscardableAttrs() { return attrs.getValue(); }
+ /// Return a range of all of discardable attributes on this operation. Note
+ /// that for unregistered operations, all attributes are considered
+ /// discardable.
+ auto getDiscardableAttrs() {
+ std::optional<RegisteredOperationName> opName = getRegisteredInfo();
+ ArrayRef<StringAttr> attributeNames =
+ opName ? getRegisteredInfo()->getAttributeNames()
+ : ArrayRef<StringAttr>();
+ return llvm::make_filter_range(
+ attrs.getValue(),
+ [this, attributeNames](const NamedAttribute attribute) {
+ return getPropertiesStorage() ||
+ !llvm::is_contained(attributeNames, attribute.getName());
+ });
+ }
/// Return all of the discardable attributes on this operation as a
/// DictionaryAttr.
- DictionaryAttr getDiscardableAttrDictionary() { return attrs; }
+ DictionaryAttr getDiscardableAttrDictionary() {
+ return DictionaryAttr::get(getContext(),
+ llvm::to_vector(getDiscardableAttrs()));
----------------
joker-eph wrote:
We should keep the fast-path I think:
```
if (getPropertiesStorage()) return attrs;
```
https://github.com/llvm/llvm-project/pull/76816
More information about the Mlir-commits
mailing list