This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Split out DenseMapInfo<variant> specialization
ClosedPublic

Authored by IncludeGuardian on May 19 2023, 1:39 PM.

Details

Summary

Remove the DenseMapInfo<std::variant<Ts...>> variant out from
llvm/ADT/DenseMapInfo.h into a separate header
llvm/ADT/DenseMapInfoVariant.h

This allows us to remove the <variant> include, which is being
transitively and unncessary included in all translation units that
include llvm/ADT/DenseMap.h.

There have been similar changes to move out specializations for

to reduce the compilation time. As we are unable to move the
specialization into <variant>, we create a separate
DenseMapInfoVariant.h header that can be used by anyone who needs this
specialization.

This reduces the total number of preprocessing tokens across the LLVM
source files in lib from (roughly) 1,964,876,961 to 1,936,551,496 - a
reduction of ~1.44%. This should result in a small improvement in
compilation time.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2023, 1:39 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
IncludeGuardian requested review of this revision.May 19 2023, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2023, 1:39 PM

I couldn't actually find a user of this specialization in llvm or clang. If the CI doesn't pick up any user then perhaps we would want to remove this specialization completely?

The implementation of isEqual is incorrect as it doesn't defer to other isEqual specializations, instead relying on operator==. If this component is needed then I can follow up with a fix + tests.

The runs of IncludeGuardian for before and after this change.

This was suggested in the analysis before on this line. Suggesting a reduction in 1.42% preprocessing token count across all translation units in llvm/lib and we ended up getting 1.44%. It's a bit higher because not only was the include directive removed, but we removed the specialization itself from the header.

nikic added a subscriber: kadircet.

It looks like you forgot to git add the new file maybe?

This was added in https://reviews.llvm.org/D133200, maybe @kadircet can comment on what this was intended for.

Fix one missing <variant> include in tools and add DenseMapInfoVariant.h, which I forgot previously

Herald added a project: Restricted Project. · View Herald TranscriptMay 20 2023, 4:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
llvm/include/llvm/ADT/DenseMapInfo.h
321–336

Regardless of this change, I think the equality here needs to be fixed in the future to delegate to DenseMapInfo for checking equality of the contents of the std::variant

nikic added a comment.May 20 2023, 8:40 AM

The pre-merge checks have a build failure in clang-tools-extra.

Add missing specialization for clang-include-cleaner/Types.h

lattner accepted this revision.May 20 2023, 11:19 AM

Awesome, this makes a lot of sense and is a great pattern to make these more modular.

This revision is now accepted and ready to land.May 20 2023, 11:19 AM
Herald added a project: Restricted Project. · View Herald Transcript
IncludeGuardian requested review of this revision.May 21 2023, 1:24 PM
IncludeGuardian added inline comments.
flang/include/flang/Optimizer/HLFIR/HLFIROps.h
22

I wasn't sure if it is possible to include <vector> within HLFIROps.td so it has been included here instead.

barannikov88 added inline comments.
flang/include/flang/Optimizer/HLFIR/HLFIROps.h
22

That's fine, we do that everywhere :)

It looks like you forgot to git add the new file maybe?

This was added in https://reviews.llvm.org/D133200, maybe @kadircet can comment on what this was intended for.

It was already pointed out by you :) this is used by clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h, and your changes there LG.
You should also update llvm/unittests/ADT/DenseMapTest.cpp, you can see build breakage information at the top (search for pre-merge checks).

Also, thanks for pointing out the discrepancy in implementation of isEqual. Sent out https://reviews.llvm.org/D151079. Happy to land it before or after your change.

This comment was removed by kadircet.

@kadircet Thanks I will run this through the formatter.

Thanks for fixing isEqual. I am currently on holiday for a few weeks so cannot guarantee when I'll be able to update this PR. I say go ahead with your fix and I'll incorporate those changes into this review when I am back.

nikic requested changes to this revision.May 23 2023, 11:28 AM

(Moving this off the review queue per above comments. There is a missing include in a unit test.)

This revision now requires changes to proceed.May 23 2023, 11:28 AM

Fix missing includes in test, fix formatting, and rebase on top of https://reviews.llvm.org/D151557

Run clang-format over patch

This is good to review now. Phabricator has become a bit confused after rebasing on top of https://reviews.llvm.org/D151557, I don't know whether it's worth creating a new, cleaner review and close this on?

nikic accepted this revision.Jun 19 2023, 5:52 AM

LGTM. The diff looks weird for some reason, but the downloadable .diff file looks fine.

This revision is now accepted and ready to land.Jun 19 2023, 5:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 10:52 PM