This is an archive of the discontinued LLVM Phabricator instance.

[mlir][DictionaryAttr] Add a new getWithSorted and use it when possible
ClosedPublic

Authored by rriddle on Apr 23 2020, 6:59 PM.

Details

Summary

The elements of a DictionaryAttr are sorted by name. In many situations, e.g NamedAttributeList, we can guarantee that the elements are sorted on construction and remove the need to perform extra checks. In places with lots of calls to attribute methods, this leads to a good performance improvement.

Diff Detail

Event Timeline

rriddle created this revision.Apr 23 2020, 6:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2020, 6:59 PM
jpienaar accepted this revision.Apr 24 2020, 6:30 AM

Thanks, this will fit the bill well :-)

mlir/include/mlir/IR/Attributes.h
281

Set confuses me here, is it meant to convey unordered? (an alternative is just to say array or vector as by default there is no assumption that it would be sorted specially IMHO)

This revision is now accepted and ready to land.Apr 24 2020, 6:30 AM
mehdi_amini added inline comments.Apr 24 2020, 9:01 AM
mlir/include/mlir/IR/Attributes.h
281

I would document here that is the client can guarantee that the array is sorted they should use the other method for performance

mlir/lib/IR/Attributes.cpp
101

If Attr is a non zero terminated string that is a prefix of name, won’t this read out of bound?

rriddle marked 4 inline comments as done.Apr 24 2020, 11:19 AM
rriddle added inline comments.
mlir/lib/IR/Attributes.cpp
101

Attr guarantees null termination because it uses Identifier.

rriddle updated this revision to Diff 259943.Apr 24 2020, 11:20 AM
rriddle marked an inline comment as done.

Resolve comments

This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.Apr 24 2020, 5:14 PM
mlir/lib/IR/Attributes.cpp
101

Oh I was on my phone and mis-read This is correct even when attr.first.data() is not a zero terminated string

Actually the comment is adding more confusion than it helps for me: the comparison is obviously correct as long as attr is null terminated.