summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/FoldingSet.cpp
AgeCommit message (Collapse)Author
2025-05-07[NFC][Support] Add llvm::uninitialized_copy (#138174)Rahul Joshi
Add `llvm::uninitialized_copy` that accepts a range instead of start/end iterator for the source of the copy.
2023-01-28[llvm] Use llvm::bit_floor instead of llvm::PowerOf2Floor (NFC)Kazu Hirata
2022-11-21[Support] Reduce Dependence on Host.hArchibald Elliott
The intention behind this commit is to reduce the use of Host.h/Host.cpp in Support, to where it is only necessary. In this case, the endian-detection and support functionality needed by these implementations can be provided by `Support/SwapByteOrder.h` in a cleaner manner. This patch also changes the byte swap in SHA256.cpp to use the byte swap function from that header, rather than an inlined implementation. Differential Revision: https://reviews.llvm.org/D137834
2022-08-08[llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-02-04[NFC] Move FoldingSetNodeIDRef::ComputeHash and ↵Dawid Jurczak
FoldingSetNodeID::ComputeHash definitions to header Lack of ComputeHash inlining slows down slightly FoldingSetBase::FindNodeOrInsertPos calls. Inlining makes it faster which matters in particular for FoldingSet users in ASTContext. Extracted from: https://reviews.llvm.org/D118385 Differential Revision: https://reviews.llvm.org/D118612
2022-02-03[NFC] Move FoldingSetNodeID::AddInteger and FoldingSetNodeID::AddPointer ↵Dawid Jurczak
definitions to header Lack of AddInteger/AddPointer inlining slows down NodeEquals/Profile/:operator== calls. Inlining makes FunctionProtoTypes/PointerTypes/ElaboratedTypes/ParenTypes Profile functions faster but since NodeEquals is still called indirectly through function pointer from FindNodeOrInsertPos there is room for further inlining improvements. Extracted from: https://reviews.llvm.org/D118385 Differential Revision: https://reviews.llvm.org/D118610
2020-06-08[Support] FoldingSetNodeID::AddString(): reserve memoryRoman Lebedev
Summary: It is traditionally potentially very inefficient to not preallocate the memory, but rely on reallocation every time you push something into vector. For example, looking at unity build of RawSpeed (`-O3 -g0 -emit-llvm -Xclang -disable-llvm-optzns`), the memory story is as follows: ``` total runtime: 11.34s. calls to allocation functions: 2694053 (237612/s) temporary memory allocations: 645188 (56904/s) peak heap memory consumption: 231.36MB peak RSS (including heaptrack overhead): 397.39MB ``` Looking at details, `FoldingSetNodeID::AddString()` is noteworthy, frequently called and is allocation-heavy. But it is quite obvious how many times we will push into `Bits` - we will push `String.size()` itself, and then we will push once per every 4 bytes of `String` (padding last block). And if we preallocate, we get: ``` total runtime: 11.20s. calls to allocation functions: 2594704 (231669/s) temporary memory allocations: 560004 (50000/s) peak heap memory consumption: 231.36MB peak RSS (including heaptrack overhead): 398.06MB ``` Which is a measurable win: ``` total runtime: -0.14s. # -1.23 % calls to allocation functions: -99349 (719920/s) # -3.69 % temporary memory allocations: -85184 (617275/s) # -13.2 % (!) peak heap memory consumption: 0B peak RSS (including heaptrack overhead): 0B total memory leaked: 0B ``` Reviewers: efriedma, nikic, bkramer Reviewed By: bkramer Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D81342
2020-04-15Remove vptr dispatch from FoldingSet.Richard Smith
Summary: Instead of storing a vptr in each FoldingSet instance, form an equivalent struct and pass it implicitly from FoldingSet into the various FoldingSetBase methods. This has three benefits: * FoldingSet becomes one pointer smaller. * Under LTO, the "virtual" functions are much easier to inline. * The element type no longer needs to be complete when instantiating FoldingSet<T>, only when instantiating an insert / lookup member. Reviewers: rnk Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78247
2020-03-11Drop a StringMap.h include, NFCReid Kleckner
$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \ | grep '^[-+] ' | sort | uniq -c | sort -nr 231 - llvm/include/llvm/ADT/StringMap.h 171 - llvm/include/llvm/Support/AllocatorBase.h 142 - llvm/include/llvm/Support/PointerLikeTypeTraits.h
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-09-14fix typosAdrian Prantl
llvm-svn: 342241
2018-07-30Remove trailing spaceFangrui Song
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
2018-06-09Use uniform mechanism for OOM errors handlingSerge Pavlov
This is a recommit of r333506, which was reverted in r333518. The original commit message is below. In r325551 many calls of malloc/calloc/realloc were replaces with calls of their safe counterparts defined in the namespace llvm. There functions generate crash if memory cannot be allocated, such behavior facilitates handling of out of memory errors on Windows. If the result of *alloc function were checked for success, the function was not replaced with the safe variant. In these cases the calling function made the error handling, like: T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T))); if (NewElts == nullptr) report_bad_alloc_error("Allocation of SmallVector element failed."); Actually knowledge about the function where OOM occurred is useless. Moreover having a single entry point for OOM handling is convenient for investigation of memory problems. This change removes custom OOM errors handling and replaces them with calls to functions `llvm::safe_*alloc`. Declarations of `safe_*alloc` are moved to a separate include file, to avoid cyclic dependency in SmallVector.h Differential Revision: https://reviews.llvm.org/D47440 llvm-svn: 334344
2018-05-30Revert commit 333506Serge Pavlov
It looks like this commit is responsible for the fail: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/24382. llvm-svn: 333518
2018-05-30Use uniform mechanism for OOM errors handlingSerge Pavlov
This is a recommit of r333390, which was reverted in r333395, because it caused cyclic dependency when building shared library `LLVMDemangle.so`. In this commit `ItaniumDemangler.cpp` was not changed. The original commit message is below. In r325551 many calls of malloc/calloc/realloc were replaces with calls of their safe counterparts defined in the namespace llvm. There functions generate crash if memory cannot be allocated, such behavior facilitates handling of out of memory errors on Windows. If the result of *alloc function were checked for success, the function was not replaced with the safe variant. In these cases the calling function made the error handling, like: T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T))); if (NewElts == nullptr) report_bad_alloc_error("Allocation of SmallVector element failed."); Actually knowledge about the function where OOM occurred is useless. Moreover having a single entry point for OOM handling is convenient for investigation of memory problems. This change removes custom OOM errors handling and replaces them with calls to functions `llvm::safe_*alloc`. Declarations of `safe_*alloc` are moved to a separate include file, to avoid cyclic dependency in SmallVector.h Differential Revision: https://reviews.llvm.org/D47440 llvm-svn: 333506
2018-05-29Reverted commits 333390, 333391 and 333394Serge Pavlov
Build of shared library LLVMDemangle.so fails due to dependency problem. llvm-svn: 333395
2018-05-29Use uniform mechanism for OOM errors handlingSerge Pavlov
In r325551 many calls of malloc/calloc/realloc were replaces with calls of their safe counterparts defined in the namespace llvm. There functions generate crash if memory cannot be allocated, such behavior facilitates handling of out of memory errors on Windows. If the result of *alloc function were checked for success, the function was not replaced with the safe variant. In these cases the calling function made the error handling, like: T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T))); if (NewElts == nullptr) report_bad_alloc_error("Allocation of SmallVector element failed."); Actually knowledge about the function where OOM occurred is useless. Moreover having a single entry point for OOM handling is convenient for investigation of memory problems. This change removes custom OOM errors handling and replaces them with calls to functions `llvm::safe_*alloc`. Declarations of `safe_*alloc` are moved to a separate include file, to avoid cyclic dependency in SmallVector.h Differential Revision: https://reviews.llvm.org/D47440 llvm-svn: 333390
2018-02-15Revert r325224 "Report fatal error in the case of out of memory"Serge Pavlov
It caused fails on some buildbots. llvm-svn: 325227
2018-02-15Report fatal error in the case of out of memorySerge Pavlov
Analysis of fails in the case of out of memory errors can be tricky on Windows. Such error emerges at the point where memory allocation function fails, but manifests itself when null pointer is used. These two points may be distant from each other. Besides, next runs may not exhibit allocation error. Usual programming practice does not require checking result of 'operator new' because it throws 'std::bad_alloc' in the case of allocation error. However, LLVM is usually built with exceptions turned off, so 'new' can return null pointer. This change installs custom new handler, which causes fatal error in the case of out of memory. The handler is installed automatically prior to call to 'main' during construction of a static object defined in 'lib/Support/ErrorHandling.cpp'. If the application does not use this file, the handler may be installed manually by a call to 'llvm::install_out_of_memory_new_handler', declared in 'include/llvm/Support/ErrorHandling.h". There are calls to C allocation functions, malloc, calloc and realloc. They are used for interoperability with C code, when allocated object has variable size and when it is necessary to avoid call of constructors. In many calls the result is not checked against null pointer. To simplify checks, new functions are defined in the namespace 'llvm' with the same names as these C function. These functions produce fatal error if allocation fails. User should use 'llvm::malloc' instead of 'std::malloc' in order to use the safe variant. This change replaces 'std::malloc' in the cases when the result of allocation function is not checked against null pointer. Finally, there are plain C code, that uses malloc and similar functions. If the result is not checked, assert statements are added. Differential Revision: https://reviews.llvm.org/D43010 llvm-svn: 325224
2017-07-20Support, IR, ADT: Check nullptr after allocation with malloc/realloc or callocMatthias Braun
As a follow up of the bad alloc handler patch, this patch introduces nullptr checks on pointers returned from the malloc/realloc/calloc functions. In addition some memory size assignments are moved behind the allocation of the corresponding memory to fulfill exception safe memory management (RAII). patch by Klaus Kretzschmar Differential Revision: https://reviews.llvm.org/D35414 llvm-svn: 308576
2017-06-12[ADT] Reduce duplication between {Contextual,}FoldingSet; NFCGeorge Burgess IV
This is a precursor to another change (coming soon) that aims to make FoldingSet's API more type-safe. Without this, the type-safety change would just duplicate 4 more public methods between the already very similar classes. This renames FoldingSetImpl to FoldingSetBase so it's consistent with the FooBase -> FooImpl<T> -> Foo<T> convention we seem to have with other containers. llvm-svn: 305231
2016-10-16PR30711: Fix incorrect profiling of 'long long' in FoldingSet, then use it toRichard Smith
fix TBAA violation in profiling of pointers. llvm-svn: 284336
2016-08-17Replace a few more "fall through" comments with LLVM_FALLTHROUGHJustin Bogner
Follow up to r278902. I had missed "fall through", with a space. llvm-svn: 278970
2016-06-03Adding reserve and capacity methods to FoldingSetBen Craig
http://reviews.llvm.org/D20930 llvm-svn: 271669
2015-08-16[ADT] Teach FoldingSet to be movable.Chandler Carruth
This is a very minimal move support - it leaves the moved-from object in a zombie state that is only valid for destruction and move assignment. This seems fine to me, and leaving it in the default constructed state would require adding more state to the object and potentially allocating memory (!!!) and so seems like a Bad Idea. llvm-svn: 245192
2015-04-06fix typos; NFCSanjay Patel
llvm-svn: 234171
2015-03-22FoldingSet: Make FoldingSetImpl's dtor protected and non-virtualBenjamin Kramer
It's not intended to be polymorphically deleted. Make FoldingSet and ContextualFoldingSet final to avoid noise from -Wnon-virtual-dtor. No functional change intended. llvm-svn: 232922
2015-03-16[llvm] Replacing asserts with static_asserts where appropriateGabor Horvath
Summary: This patch consists of the suggestions of clang-tidy/misc-static-assert check. Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, llvm-commits Differential Revision: http://reviews.llvm.org/D8343 llvm-svn: 232366
2014-04-15[C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper
instead of comparing to nullptr. llvm-svn: 206252
2014-04-09[C++11] Replace some comparisons with 'nullptr' with simple boolean checks ↵Craig Topper
to reduce verbosity. llvm-svn: 205829
2014-04-07[C++11] Make use of 'nullptr' in the Support library.Craig Topper
llvm-svn: 205697
2013-04-15Make the host endianness check an integer constant expression.Rafael Espindola
I will remove the isBigEndianHost function once I update clang. The ifdef logic is designed to * not use configure/cmake to avoid breaking -arch i686 -arch ppc. * default to little endian * be as small as possible It looks like sys/endian.h is the preferred header on most modern BSD systems, but it is better to change this in a followup patch as machine/endian.h is available on FreeBSD, OpenBSD, NetBSD and OS X. llvm-svn: 179527
2012-12-25Fix whitespace. No functionality change.Nick Lewycky
llvm-svn: 171051
2012-12-03Use the new script to sort the includes of every file under lib.Chandler Carruth
Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] llvm-svn: 169131
2012-11-16move irrelevant attribution.Chris Lattner
llvm-svn: 168182
2012-09-08Add operator< for FoldingSetNodeID.Ted Kremenek
llvm-svn: 163454
2012-04-11FoldingSet: Push the hash through FoldingSetTraits::Equals, so clients can ↵Benjamin Kramer
use it. llvm-svn: 154496
2012-03-08Revert commit 152300 (ddunbar) since it still seems to be breakingDuncan Sands
buildbots. Original commit message: [ADT] Change the trivial FoldingSetNodeID::Add* methods to be inline, reapplied with a fix for the longstanding over-read of 32-bit pointer values. llvm-svn: 152304
2012-03-08[ADT] Change the trivial FoldingSetNodeID::Add* methods to be inline, reappliedDaniel Dunbar
with a fix for the longstanding over-read of 32-bit pointer values. llvm-svn: 152300
2012-03-08Revert r152288, "[ADT] Change the trivial FoldingSetNodeID::Add* methods to beDaniel Dunbar
inline.", which is breaking the bots in a way I don't understand. llvm-svn: 152295
2012-03-08[ADT] Change the trivial FoldingSetNodeID::Add* methods to be inline.Daniel Dunbar
llvm-svn: 152288
2012-03-01Switch FoldingSet over to the new hashing infrastructure. We might wantChandler Carruth
to do more invasive refactoring here to get FoldingSet to use size_t or even hash_code directly, but for now this is a good first step to remove Yet Another Hashing Algorithm from LLVM. llvm-svn: 151859
2011-07-18Simplify & microoptimize code. No intended functionality change.Benjamin Kramer
llvm-svn: 135364
2011-06-03singed int causes signed extension, which contradicts the intention to pick upZhongxing Xu
integers with high 32 bits being zero. llvm-svn: 132538
2011-04-25allow adding a FoldingSetNodeID to a FastFoldingSetNode, resolving PR9499,Chris Lattner
patch by Johannes Schaub! llvm-svn: 130151
2010-11-29Merge System into Support.Michael J. Spencer
llvm-svn: 120298
2010-11-19Aligned and unaligned copies of the same stringDale Johannesen
were not hashing to the same value. Analysis and patch by Frits van Bommel! llvm-svn: 119770
2010-08-24Use Bits.data() instead of &Bits[0].Dan Gohman
llvm-svn: 111993
2010-08-16Add hooks to FoldingSetTrait to allow specializations to provideDan Gohman
implementations of equality comparison and hash computation. This can be used to optimize node lookup by avoiding creating lots of temporary ID values just for hashing and comparison purposes. llvm-svn: 111130
2010-08-16Reverse the order of GetNodeProfile's arguments, for consistencyDan Gohman
with FoldingSetTrait::Profile. llvm-svn: 111127