This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] ODS-level Attribute Optimizations
ClosedPublic

Authored by Mogball on Mar 24 2022, 1:29 PM.

Details

Summary

This patch contains several ODS-level optimizations to attribute getters and getting.

  1. OpAdaptors, when provided a DictionaryAttr, will instantiate an OperationName so that adaptor attribute getters can used cached identifiers.
  2. Verifiers will take advantage of attributes stored in sorted order to get all required (non-optional, non-default valued, and non-derived) attributes in one pass over the attribute dictionary and verify that they are present.
  3. ODS-generated attribute getters will use "subrange" lookup. Because the attributes are stored in sorted order and ODS knows which attributes are required, the number of required attributes less than and greater than each attribute can be computed. When searching for an attribute, the ends of the search range can be dropped.

Diff Detail

Event Timeline

Mogball created this revision.Mar 24 2022, 1:29 PM
Herald added a project: Restricted Project. · View Herald Transcript
Mogball requested review of this revision.Mar 24 2022, 1:29 PM

Nice, ooc do you have some profiling info?

I used to but the benchmarks I had were very heavy on unregistered attribute lookups and not ODS attributes (I think Chris had some for CIRCT since he was the one who initially pushed for this). Still, I remember seeing ~2-3% improvement with this change. Small, but ODS getters were not a big part of those benchmarks.

jpienaar added inline comments.Mar 25 2022, 4:12 PM
mlir/include/mlir/IR/OperationSupport.h
434

I'd consider making this more explicit getAttrFromSorted (or FromSortedRange). This is mostly internal/users shouldn't be calling it so making it self-documenting is useful.

mlir/test/mlir-tblgen/op-attribute.td
87–88

+1 is as we know that an attribute has to be found before this, but if we had returned the iterator at which the previous one was found, we would have an even tighter search range. What are the considerarions for returning iterator instead?

Mogball marked an inline comment as done.Mar 28 2022, 9:08 AM
Mogball added inline comments.
mlir/test/mlir-tblgen/op-attribute.td
87–88

Hm, that's a good point. I can make it do that as well (in the verifier at least). It'll just be a bit more wrangling in the verifier generator.

Mogball updated this revision to Diff 419331.Mar 30 2022, 11:13 PM
Mogball marked 2 inline comments as done.

Further optimizer verifier generator to make one pass over the
attributes array (including optional attributes).

Nice!

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
198

Use /// for top-level comments.

198

?

247–258

?

802–808

? Or does that format it weirdly?

Mogball updated this revision to Diff 420628.Apr 5 2022, 1:58 PM
Mogball marked 4 inline comments as done.

review comments

The test failures look real, can you take a look?

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
204

Can you switch these to ///?

Mogball updated this revision to Diff 421557.Apr 8 2022, 9:39 AM

Fix build and review comments

Mogball marked an inline comment as done.Apr 8 2022, 9:39 AM
Mogball updated this revision to Diff 421558.Apr 8 2022, 9:44 AM

Fix build warning

jpienaar accepted this revision.Apr 8 2022, 10:18 AM
This revision is now accepted and ready to land.Apr 8 2022, 10:18 AM
This revision was automatically updated to reflect the committed changes.