summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/StringMap.cpp
AgeCommit message (Collapse)Author
2025-10-01[ADT] Use "if constexpr" with shouldReverseIterate (#161477)Kazu Hirata
This patch uses "if constexpr" whenever we call shouldReverseIterate in "if" conditions. Note that shouldReverseIterate is a constexpr function.
2025-07-19StringMap: Remove redundant member init in constructor (#149491)Matt Arsenault
These are already zeroinitialized in the field definitions.
2024-02-02Reapply "lldb: Cache string hash during ConstString pool queries/insertions"David Blaikie
Reverted due to an internally discovered lld crash due to the underlying StringMap changes, which turned out to be an existing lld bug that got tickled by the StringMap changes. That's addressed in dee8786f70a3d62b639113343fa36ef55bdbad63 so let's have another go with this change. Original commit message: lldb was rehashing the string 3 times (once to determine which StringMap to use, once to query the StringMap, once to insert) on insertion (twice on successful lookup). This patch allows the lldb to benefit from hash improvements in LLVM (from djbHash to xxh3). Though further changes would be needed to cache this value to disk - we shouldn't rely on the StringMap::hash remaining the same in the future/this value should not be serialized to disk. If we want cache this value StringMap should take a hashing template parameter to allow for a fixed hash to be requested. This reverts commit 5bc1adff69315dcef670e9fcbe04067b5d5963fb. Effectively reapplying the original 2e197602305be18b963928e6ae024a004a95af6d.
2024-02-02Reapply "[ADT][StringMap] Add ability to precompute and reuse the string hash"David Blaikie
Reverted due to an internally discovered lld crash, which turned out to be an existing lld bug that got tickled by this changes. That's addressed in dee8786f70a3d62b639113343fa36ef55bdbad63 so let's have another go with this change. Original commit message: Useful for lldb's const string pool, using the hash to determine which string map to lock and query/insert. Derived from https://reviews.llvm.org/D122974 by Luboš Luňák This reverts commit f976719fb2cb23364957e5993f7fc3684ee15391. Effectively reapplying 67c631d283fc96d652304199cd625be426b98f8e.
2023-12-14Revert "[ADT][StringMap] Add ability to precompute and reuse the string hash"David Blaikie
Crash identified internally in lld's use of StringMap in `compareSections`. Will investigate offline before recommitting. This reverts commit 67c631d283fc96d652304199cd625be426b98f8e.
2023-12-14Revert "lldb: Cache string hash during ConstString pool queries/insertions"David Blaikie
Underlying StringMap API for providing a hash has caused some problems (observed a crash in lld) - so reverting this until I can figure out/fix what's going on there. This reverts commit 52ba075571958e2fec8d871ddfa1ef56486b86d3. This reverts commit 2e197602305be18b963928e6ae024a004a95af6d.
2023-12-12Add missing parenDavid Blaikie
2023-12-12[ADT][StringMap] Add ability to precompute and reuse the string hashDavid Blaikie
Useful for lldb's const string pool, using the hash to determine which string map to lock and query/insert. Derived from https://reviews.llvm.org/D122974 by Luboš Luňák
2023-07-22[Support] Change StringMap hash function from xxHash64 to xxh3_64bitsFangrui Song
Similar to D142862. xxh3 is significantly faster than xxh64. Switch to xxh3, as we did for for lld and llvm-dwarfutil to increase performance (D154813 D155675). While I think StringMap is not a bottleneck for most applications, it seems good to eliminate the slower xxh64. In addition, according to Erik Desjardins, an artificial benchmark of Rust with very large constant strings improves by ~3% locally. I have fixed all found issues (~20) separately, but one is remaining: * ExecutionEngine/RuntimeDyld/ARM/MachO_ARM_PIC_relocations.s has a failure due to StringMap iteration order. It now passes with LLVM_ENABLE_REVERSE_ITERATION=on while failing with LLVM_ENABLE_REVERSE_ITERATION=off. Reviewed By: erikdesjardins Differential Revision: https://reviews.llvm.org/D155781
2023-07-21[Support] Implement LLVM_ENABLE_REVERSE_ITERATION for StringMapFangrui Song
ProgrammersManual.html says > StringMap iteration order, however, is not guaranteed to be deterministic, so any uses which require that should instead use a std::map. This patch makes -DLLVM_REVERSE_ITERATION=on (currently -DLLVM_ENABLE_REVERSE_ITERATION=on works as well) shuffle StringMap iteration order (actually flipping the hash so that elements not in the same bucket are reversed) to catch violations, similar to D35043 for DenseMap. This should help change the hash function (e.g., D142862, D155781). With a lot of fixes, there are still some violations. This patch implements the "reverse_iteration" lit feature to skip such tests. Eventually we should remove this feature. `ninja check-{llvm,clang,clang-tools}` are clean with `#define LLVM_ENABLE_REVERSE_ITERATION 1`. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D155789
2023-02-19Recommit "[Support] change StringMap hash function from djbHash to xxHash"Erik Desjardins
This reverts commit 37eb9d13f891f7656f811516e765b929b169afe0. Test failures have been fixed: - ubsan failure fixed by 72eac42f21c0f45a27f3eaaff9364cbb5189b9e4 - warn-unsafe-buffer-usage-fixits-local-var-span.cpp fixed by 03cc52dfd1dbb4a59b479da55e87838fb93d2067 (wasn't related) - test-output-format.ll failure was spurious, build failed at https://lab.llvm.org/buildbot/#/builders/54/builds/3545 (b4431b2d945b6fc19b1a55ac6ce969a8e06e1e93) but passed at https://lab.llvm.org/buildbot/#/builders/54/builds/3546 (5ae99be0377248c74346096dc475af254a3fc799) which is before my revert https://github.com/llvm/llvm-project/compare/b4431b2d945b6fc19b1a55ac6ce969a8e06e1e93...5ae99be0377248c74346096dc475af254a3fc799 Original commit message: Depends on https://reviews.llvm.org/D142861. Alternative to https://reviews.llvm.org/D137601. xxHash is much faster than djbHash. This makes a simple Rust test case with a large constant string 10% faster to compile. Previous attempts at changing this hash function (e.g. https://reviews.llvm.org/D97396) had to be reverted due to breaking tests that depended on iteration order. No additional tests fail with this patch compared to `main` when running `check-all` with `-DLLVM_ENABLE_PROJECTS="all"` (on a Linux host), so I hope I found everything that needs to be changed. Differential Revision: https://reviews.llvm.org/D142862
2023-02-08Revert "[Support] change StringMap hash function from djbHash to xxHash"Erik Desjardins
This reverts commit d768b97424f9e1a0aae45440a18b99f21c4027ce. Causes sanitizer failure: https://lab.llvm.org/buildbot/#/builders/238/builds/1114 ``` /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/xxhash.cpp:107:12: runtime error: applying non-zero offset 8 to null pointer #0 0xaaaab28ec6c8 in llvm::xxHash64(llvm::StringRef) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/xxhash.cpp:107:12 #1 0xaaaab28cbd38 in llvm::StringMapImpl::LookupBucketFor(llvm::StringRef) /b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/StringMap.cpp:87:28 ``` Probably causes test failure in `warn-unsafe-buffer-usage-fixits-local-var-span.cpp`: https://lab.llvm.org/buildbot/#/builders/60/builds/10619 Probably causes reverse-iteration test failure in `test-output-format.ll`: https://lab.llvm.org/buildbot/#/builders/54/builds/3545
2023-02-07[Support] change StringMap hash function from djbHash to xxHashErik Desjardins
Depends on https://reviews.llvm.org/D142861. Alternative to https://reviews.llvm.org/D137601. xxHash is much faster than djbHash. This makes a simple Rust test case with a large constant string 10% faster to compile. Previous attempts at changing this hash function (e.g. https://reviews.llvm.org/D97396) had to be reverted due to breaking tests that depended on iteration order. No additional tests fail with this patch compared to `main` when running `check-all` with `-DLLVM_ENABLE_PROJECTS="all"` (on a Linux host), so I hope I found everything that needs to be changed. Differential Revision: https://reviews.llvm.org/D142862
2022-03-23[NFC][llvm][StringMap]Extract createTable and getHashTable functions and add ↵wangyihan
the inline attribute to the getMinBucketToReserveForEntries function. 1. Extract createTable and getHashTable functions. 2. Add the inline attribute to the getMinBucketToReserveForEntries function. 3. Remove unnecessary local variable HTSize. Statements in the following order appear in llvm::StringMapImpl::init and llvm::StringMapImpl::RehashTable, so I extracted this code into a function. getHashTable is for the same reason, it appears in llvm::StringMapImpl::FindKey, llvm::StringMapImpl::LookupBucketFor and llvm::StringMapImpl::RehashTable. ``` auto **Table = static_cast<StringMapEntryBase **>(safe_calloc( NewNumBuckets + 1, sizeof(StringMapEntryBase **) + sizeof(unsigned))); // Allocate one extra bucket, set it to look filled so the iterators stop at // end. Table[NewNumBuckets] = (StringMapEntryBase *)2; ``` ``` unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1); ``` Reviewed By: skan, sepavloff Differential Revision: https://reviews.llvm.org/D121934
2022-03-16[llvm][ADT] Remove duplicate code in llvm::StringMapImpl::RehashTablewangyihan
Remove duplicate code in llvm::StringMapImpl::RehashTable, near StringMap.cpp:229 ``` if (!NewTableArray[NewBucket]) { NewTableArray[FullHash & (NewSize - 1)] = Bucket; NewHashArray[FullHash & (NewSize - 1)] = FullHash; if (I == BucketNo) NewBucketNo = NewBucket; continue; } ``` Reviewed By: MaskRay, dexonsmith Differential Revision: https://reviews.llvm.org/D121726
2022-01-21[llvm] Cleanup header dependencies in ADT and Supportserge-sans-paille
The cleanup was manual, but assisted by "include-what-you-use". It consists in 1. Removing unused forward declaration. No impact expected. 2. Removing unused headers in .cpp files. No impact expected. 3. Removing unused headers in .h files. This removes implicit dependencies and is generally considered a good thing, but this may break downstream builds. I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the modification in the second part of the commit. 4. Replacing header inclusion by forward declaration. This has the same impact as 3. Notable changes: - llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h - llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h - llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h - llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h You may need to add some of these headers in your compilation units, if needs be. As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 8000919 lines after: 7917500 lines Reduced dependencies also helps incremental rebuilds and is more ccache friendly, something not shown by the above metric :-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2021-03-01Revert "Use the default seed value for djb hash for StringMap"serge-sans-paille
This reverts commit d84440ec919019ac446241db72cfd905c6ac9dfa. It breaks (at least) lldb and lld validation https://lab.llvm.org/buildbot/#/builders/68/builds/7837 https://lab.llvm.org/buildbot/#/builders/36/builds/5495
2021-03-01Use the default seed value for djb hash for StringMapserge-sans-paille
See original comment in 560ce2c70fb1fe8e4b9b5e39c54e494a50373ba8 Baiscally the default seed value results in less collision, but changes the iteration order, which matters for a few test cases. Differential Revision: https://reviews.llvm.org/D97396
2020-04-12Refactor StringMap.h, splitting StringMapEntry out to its own header.Chris Lattner
Summary: StringMapEntry.h can have lower dependencies, than StringMap.h, which is useful for public headers that want to expose inline methods on StringMapEntry<> but don't need to expose all of StringMap.h. One example of this is mlir's Identifier.h, another example is the existing LLVM StringPool.h. StringPool also could use a cleanup, I'll deal with that in a follow-on patch. Reviewers: rriddle Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77963
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-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-26Re-land: "[Support] Replace HashString with djbHash."Jonas Devlieghere
This patch removes the HashString function from StringExtraces and replaces its uses with calls to djbHash from DJB.h. This change is *almost* NFC. While the algorithm is identical, the djbHash implementation in StringExtras used 0 as its default seed while the implementation in DJB uses 5381. The latter has been shown to result in less collisions and improved avalanching and is used by the DWARF accelerator tables. Because some test were implicitly relying on the hash order, I've reverted to using zero as a seed for the following two files: lld/include/lld/Core/SymbolTable.h llvm/lib/Support/StringMap.cpp Differential revision: https://reviews.llvm.org/D43615 llvm-svn: 326091
2018-02-26Revert "[Support] Replace HashString with djbHash."Jonas Devlieghere
It looks like some of our tests depend on the ordering of hashed values. I'm reverting my changes while I try to reproduce and fix this locally. Failing builds: lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/18388 lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/6743 lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/15607 llvm-svn: 326082
2018-02-26[Support] Replace HashString with djbHash.Jonas Devlieghere
This removes the HashString function from StringExtraces and replaces its uses with calls to djbHash from DJB.h This is *almost* NFC. While the algorithm is identical, the djbHash implementation in StringExtras used 0 as its seed while the implementation in DJB uses 5381. The latter has been shown to result in less collisions and improved avalanching. https://reviews.llvm.org/D43615 (cherry picked from commit 77f7f965bc9499a9ae768a296ca5a1f7347d1d2c) llvm-svn: 326081
2018-02-20Report fatal error in the case of out of memorySerge Pavlov
This is the second part of recommit of r325224. The previous part was committed in r325426, which deals with C++ memory allocation. Solution for C memory allocation involved functions `llvm::malloc` and similar. This was a fragile solution because it caused ambiguity errors in some cases. In this commit the new functions have names like `llvm::safe_malloc`. The relevant part of original comment is below, updated for new function names. 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. In some cases memory is allocated by a call to some of 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 for null pointer. To simplify checks, new functions are defined in the namespace 'llvm': `safe_malloc`, `safe_calloc` and `safe_realloc`. They behave as corresponding standard functions but produce fatal error if allocation fails. This change replaces the standard functions like 'malloc' in the cases when the result of the allocation function is not checked for null pointer. Finally, there are plain C code, that uses malloc and similar functions. If the result is not checked, assert statement is added. Differential Revision: https://reviews.llvm.org/D43010 llvm-svn: 325551
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
2016-08-23Fix some Clang-tidy modernize-use-using and Include What You Use warnings; ↵Eugene Zelenko
other minor fixes. Differential revision: https://reviews.llvm.org/D23789 llvm-svn: 279535
2016-03-25Adjust initial size in StringMap constructor to guarantee no grow()Mehdi Amini
Summary: StringMap ctor accepts an initialize size, but expect it to be rounded to the next power of 2. The ctor can handle that directly instead of expecting clients to round it. Also, since the map will resize itself when 75% full, take this into account an initialize a larger initial size to avoid any growth. Reviewers: dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18344 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 264385
2015-02-23Sync the __builtin_expects for our 3 quadratically probed hash table ↵Benjamin Kramer
implementations. This assumes that a) finding the bucket containing the value is LIKELY b) finding an empty bucket is LIKELY c) growing the table is UNLIKELY I also switched the a) and b) cases for SmallPtrSet as we seem to use the set mostly more for insertion than for checking existence. In a simple benchmark consisting of 2^21 insertions of 2^20 unique pointers into a DenseMap or SmallPtrSet a few percent speedup on average, but nothing statistically significant. llvm-svn: 230232
2014-06-23Recommit 211309 (StringMap::insert), reverted in 211328 due to issues with ↵David Blaikie
private, but non-deleted, move members. Certain versions of GCC (~4.7) couldn't handle the SFINAE on access control, but with "= delete" (hidden behind a macro for portability) this issue is worked around/addressed. Patch by Agustín Bergé llvm-svn: 211525
2014-06-20Revert "Add StringMap::insert(pair) consistent with the standard associative ↵Rafael Espindola
container concept." This reverts commit r211309. It looks like it broke some bots: http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/15563/steps/compile/logs/stdio llvm-svn: 211328
2014-06-19Add StringMap::insert(pair) consistent with the standard associative ↵David Blaikie
container concept. Patch by Agustín Bergé. llvm-svn: 211309
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
2012-08-29Add some __builtin_expect magic to StringMap.Benjamin Kramer
Tombstones and full hash collisions are rare, mark the "empty" and "no collision" paths as likely. The bug in simplifycfg that prevented the hints from being picked during selfhost up was fixed recently :) llvm-svn: 162874
2012-06-19Fix PR13148, an inf-loop in StringMap.Chandler Carruth
StringMap suffered from the same bug as DenseMap: when you explicitly construct it with a small number of buckets, you can arrange for the tombstone-based growth path to be followed when the number of buckets was less than '8'. In that case, even with a full map, it would compare '0' as not less than '0', and refuse to grow the table, leading to inf-loops trying to find an empty bucket on the next insertion. The fix is very simple: use '<=' as the comparison. The same fix was applied to DenseMap as well during its recent refactoring. Thanks to Alex Bolz for the great report and test case. =] llvm-svn: 158725
2011-12-27Switch StringMap from an array of structures to a structure of arrays.Benjamin Kramer
- -25% memory usage of the main table on x86_64 (was wasted in struct padding). - no significant performance change. llvm-svn: 147294
2011-03-30Reset StringMap's NumTombstones on clears and rehashes.Jakob Stoklund Olesen
StringMap was not properly updating NumTombstones after a clear or rehash. This was not fatal until now because the table was growing faster than NumTombstones could, but with the previous change of preventing infinite growth of the table the invariant (NumItems + NumTombstones <= NumBuckets) stopped being observed, causing infinite loops in certain situations. Patch by José Fonseca! llvm-svn: 128567
2011-03-30Prevent infinite growth of SmallMap instances.Jakob Stoklund Olesen
Rehash but don't grow when full of tombstones. Patch by José Fonseca! llvm-svn: 128565
2010-12-23Change all self assignments X=X to (void)X, so that we can turn on aJeffrey Yasskin
new gcc warning that complains on self-assignments and self-initializations. llvm-svn: 122458
2009-11-06Pass StringRef by value.Daniel Dunbar
llvm-svn: 86251
2009-10-17Move StringMap's string has function into StringExtras.hDaniel Dunbar
llvm-svn: 84344
2009-07-23Convert StringMap to using StringRef for its APIs.Daniel Dunbar
- Yay for '-'s and simplifications! - I kept StringMap::GetOrCreateValue for compatibility purposes, this can eventually go away. Likewise the StringMapEntry Create functions still follow the old style. - NIFC. llvm-svn: 76888
2007-12-29Remove attribution from file headers, per discussion on llvmdev.Chris Lattner
llvm-svn: 45418