This is an archive of the discontinued LLVM Phabricator instance.

[mlir][AsmPrinter] Don't use string comparison when filtering list attributes
ClosedPublic

Authored by rriddle on Mar 4 2021, 2:06 PM.

Details

Summary

In .mlir modules with large 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.

Diff Detail

Event Timeline

rriddle created this revision.Mar 4 2021, 2:06 PM
rriddle requested review of this revision.Mar 4 2021, 2:06 PM
jpienaar accepted this revision.Mar 4 2021, 2:18 PM
This revision is now accepted and ready to land.Mar 4 2021, 2:18 PM
mehdi_amini added inline comments.Mar 4 2021, 2:31 PM
mlir/lib/IR/AsmPrinter.cpp
451

NamedAttribute are keyed on identifier, which are allowing pointer hashing/comparison instead of string, can you use these in the DenseSet?

rriddle marked an inline comment as done.Mar 4 2021, 2:50 PM
rriddle added inline comments.
mlir/lib/IR/AsmPrinter.cpp
451

elidedAttrs is an array of StringRef, so we would have to unique identifiers for each of them. The additional overhead of uniquing elidedAttrs is noticeable, and DenseSet<StringRef> ends up being faster(~200-250 ms).

mehdi_amini accepted this revision.Mar 4 2021, 5:33 PM
mehdi_amini added inline comments.
mlir/lib/IR/AsmPrinter.cpp
451

Surprising to me, it is because we have a lock in the context when retrieving the Identifiers from the elidedAttr?

mehdi_amini added inline comments.Mar 4 2021, 5:34 PM
mlir/lib/IR/AsmPrinter.cpp
451

Actually there would be two hashes using Identifier: one to convert the StringRef to an Identifier, and then another one to hash the Identifier pointer to insert in the DenseSet...

rriddle marked 3 inline comments as done.Mar 5 2021, 12:41 PM
rriddle added inline comments.
mlir/lib/IR/AsmPrinter.cpp
451

I think it is a combo of all of the above, multiple hashes+locking+etc.

This revision was automatically updated to reflect the committed changes.
rriddle marked an inline comment as done.