[PATCH] D137086: [llvm][ADT] Add NonintrusiveFoldingSet

Troy Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 09:48:24 PDT 2022


troyj created this revision.
troyj added a reviewer: bruno.
Herald added a subscriber: hiraditya.
Herald added a project: All.
troyj requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137086

Files:
  llvm/include/llvm/ADT/FoldingSet.h
  llvm/lib/Support/FoldingSet.cpp
  llvm/unittests/ADT/FoldingSet.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137086.472035.patch
Type: text/x-patch
Size: 17530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221031/1f6eff28/attachment.bin>


More information about the llvm-commits mailing list