This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Add is_splat overload accepting initializer_list
ClosedPublic

Authored by kuhar on Aug 5 2022, 1:32 PM.

Details

Summary

Allow for is_splat to be used inline, similar to is_contained, e.g.,

if (is_splat({type1, type2, type3, type4}))
  ...

which is much more concise and less typo-prone than an equivalent chain of equality comparisons.

My immediate motivation is to clean up some code in the SPIR-V dialect that currently needs to either construct a temporary container or use makeArrayRef before calling is_splat.

Diff Detail

Event Timeline

kuhar created this revision.Aug 5 2022, 1:32 PM
Herald added a project: Restricted Project. · View Herald Transcript
kuhar requested review of this revision.Aug 5 2022, 1:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 1:32 PM
dblaikie added inline comments.Aug 5 2022, 4:08 PM
llvm/include/llvm/ADT/STLExtras.h
1801

hmm, Values is already a valid range, so it's a bit awkward/unfortunate to make a new range from it.

could we make this add the template parameter explicitly?

return is_splat<std::initializer_list<T>>(std::move(Values));

(the move doesn't do much (since std::initializer_list is immutable, yeah?), but I think it's that or you have to make the parameter a reference type, to work with the universal reference stuff?)

kuhar updated this revision to Diff 450653.Aug 7 2022, 10:55 AM
kuhar added inline comments.
llvm/include/llvm/ADT/STLExtras.h
1801

This looked like an infinite recursion to me initially, but you are right, move does fix it. Thanks for the suggestion!

kuhar marked an inline comment as done.Aug 7 2022, 10:56 AM
dblaikie accepted this revision.Aug 7 2022, 11:02 AM

Looks good, thanks!

This revision is now accepted and ready to land.Aug 7 2022, 11:02 AM
This revision was landed with ongoing or failed builds.Aug 8 2022, 7:24 AM
This revision was automatically updated to reflect the committed changes.