This is an archive of the discontinued LLVM Phabricator instance.

[llvm][ADT] Add NonintrusiveFoldingSet
Needs ReviewPublic

Authored by troyj on Oct 31 2022, 9:48 AM.

Details

Reviewers
bruno
Summary

NonintrusiveFoldingSet is a faster alternative to FoldingSet with a similar memory profile. This patch introduces the class with tests copied from the existing FoldingSet tests. The intent is to follow this LLVM patch with multiple Clang patches that replace critical-path AST FoldingSets, which together speed up *total* front end time by 5% for large, template-heavy TUs, where the time spent doing FoldingSet operations was reduced by 33% and memory usage regressed by less than 1%.

Direct improvement of FoldingSet was investigated, but was avoided for two reasons. First, client code may depend on the intrusive nature of FoldingSet, which requires the held type to be derived from FoldingSetNode. Second, there exist a variety of buggy Profile functions throughout LLVM and Clang whose erroneous behavior is presently hidden because FoldingSet rehashes all values upon rebucketing. It is possible to observe a FoldingSetNode that does not hash to its current bucket, but then gets "fixed" by the FoldingSet growing and rebucketing. NonintrusiveFoldingSet never rehashes, so it more quickly exposes this behavior. Thus, giving FoldingSet the internal behavior of NonintrusiveFoldingSet would break existing code, despite the class itself operating correctly. By presenting it as a new class with a similar interface, existing code can adopt it incrementally.

Diff Detail

Event Timeline

troyj created this revision.Oct 31 2022, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 9:48 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
troyj requested review of this revision.Oct 31 2022, 9:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 9:48 AM