This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Refactor the representation of function-like argument/result attributes.
ClosedPublic

Authored by rriddle on May 6 2021, 5:04 PM.

Details

Summary

The current design uses a unique entry for each argument/result attribute, with the name of the entry being something like "arg0". This provides for a somewhat sparse design, but ends up being much more expensive (from a runtime perspective) in-practice. The design requires building a string every time we lookup the dictionary for a specific arg/result, and also requires N attribute lookups when collecting all of the arg/result attribute dictionaries.

This revision restructures the design to instead have an ArrayAttr that contains all of the attribute dictionaries for arguments and another for results. This design reduces the number of attribute name lookups to 1, and allows for O(1) lookup for individual element dictionaries. The major downside is that we can end up with larger memory usage, as the ArrayAttr contains an entry for each element even if that element has no attributes. If the memory usage becomes too problematic, we can experiment with a more sparse structure that still provides a lot of the wins in this revision.

This dropped the compilation time of a somewhat large TensorFlow model from ~650 seconds to ~400 seconds.

Diff Detail

Event Timeline

rriddle created this revision.May 6 2021, 5:04 PM
rriddle requested review of this revision.May 6 2021, 5:04 PM
mehdi_amini accepted this revision.May 6 2021, 6:11 PM
mehdi_amini added inline comments.
mlir/include/mlir/IR/FunctionSupport.h
47

Looks like a candidate to be in a "detail" namespace, this really looks like a low-level helper for the other methods.

49

Add that the ArrayRef size must matching the number of arguments to the function

This revision is now accepted and ready to land.May 6 2021, 6:11 PM
rriddle updated this revision to Diff 343801.May 7 2021, 7:31 PM
rriddle marked 2 inline comments as done.

update

This revision was landed with ongoing or failed builds.May 7 2021, 7:40 PM
This revision was automatically updated to reflect the committed changes.