forked from OSchip/llvm-project
[mlir][AsmPrinter] Don't use string comparison when filtering list attributes
In .mlir modules with larges amounts of attributes, e.g. a function with a larger number of argument attributes, the string comparison filtering greatly affects compile time. This revision switches to using a SmallDenseSet in these situations, resulting in over a 10x speed up in some situations. Differential Revision: https://reviews.llvm.org/D97980
This commit is contained in:
parent
29812a6195
commit
f175ba4a54
|
@ -441,12 +441,17 @@ private:
|
|||
/// 'elidedAttrs'.
|
||||
void printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
||||
ArrayRef<StringRef> elidedAttrs = {}) override {
|
||||
// Filter out any attributes that shouldn't be included.
|
||||
SmallVector<NamedAttribute, 8> filteredAttrs(
|
||||
llvm::make_filter_range(attrs, [&](NamedAttribute attr) {
|
||||
return !llvm::is_contained(elidedAttrs, attr.first.strref());
|
||||
}));
|
||||
for (const NamedAttribute &attr : filteredAttrs)
|
||||
if (attrs.empty())
|
||||
return;
|
||||
if (elidedAttrs.empty()) {
|
||||
for (const NamedAttribute &attr : attrs)
|
||||
printAttribute(attr.second);
|
||||
return;
|
||||
}
|
||||
llvm::SmallDenseSet<StringRef> elidedAttrsSet(elidedAttrs.begin(),
|
||||
elidedAttrs.end());
|
||||
for (const NamedAttribute &attr : attrs)
|
||||
if (!elidedAttrsSet.contains(attr.first.strref()))
|
||||
printAttribute(attr.second);
|
||||
}
|
||||
void printOptionalAttrDictWithKeyword(
|
||||
|
@ -1916,16 +1921,8 @@ void ModulePrinter::printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
|||
if (attrs.empty())
|
||||
return;
|
||||
|
||||
// Filter out any attributes that shouldn't be included.
|
||||
SmallVector<NamedAttribute, 8> filteredAttrs(
|
||||
llvm::make_filter_range(attrs, [&](NamedAttribute attr) {
|
||||
return !llvm::is_contained(elidedAttrs, attr.first.strref());
|
||||
}));
|
||||
|
||||
// If there are no attributes left to print after filtering, then we're done.
|
||||
if (filteredAttrs.empty())
|
||||
return;
|
||||
|
||||
// Functor used to print a filtered attribute list.
|
||||
auto printFilteredAttributesFn = [&](auto filteredAttrs) {
|
||||
// Print the 'attributes' keyword if necessary.
|
||||
if (withKeyword)
|
||||
os << " attributes";
|
||||
|
@ -1935,6 +1932,20 @@ void ModulePrinter::printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
|||
interleaveComma(filteredAttrs,
|
||||
[&](NamedAttribute attr) { printNamedAttribute(attr); });
|
||||
os << '}';
|
||||
};
|
||||
|
||||
// If no attributes are elided, we can directly print with no filtering.
|
||||
if (elidedAttrs.empty())
|
||||
return printFilteredAttributesFn(attrs);
|
||||
|
||||
// Otherwise, filter out any attributes that shouldn't be included.
|
||||
llvm::SmallDenseSet<StringRef> elidedAttrsSet(elidedAttrs.begin(),
|
||||
elidedAttrs.end());
|
||||
auto filteredAttrs = llvm::make_filter_range(attrs, [&](NamedAttribute attr) {
|
||||
return !elidedAttrsSet.contains(attr.first.strref());
|
||||
});
|
||||
if (!filteredAttrs.empty())
|
||||
printFilteredAttributesFn(filteredAttrs);
|
||||
}
|
||||
|
||||
void ModulePrinter::printNamedAttribute(NamedAttribute attr) {
|
||||
|
|
Loading…
Reference in New Issue