mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
[wpiutil] Reduce llvm collections patches (#4268)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
From 4f34f83152a851ce675c876f3bd0e53322110d04 Mon Sep 17 00:00:00 2001
|
||||
From e5c61a18376a34b94bf1761f30e017a741e52b0b Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 20:50:26 -0400
|
||||
Subject: [PATCH 01/31] Fix spelling / language errors
|
||||
Subject: [PATCH 01/27] Fix spelling / language errors
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/Chrono.h | 2 +-
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 3b9d1af2e3a1b031554e3f3b9d0eda4aa55d8b15 Mon Sep 17 00:00:00 2001
|
||||
From 8799ad77758b93e742394699451009a8d3fc7bb7 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:09:18 -0400
|
||||
Subject: [PATCH 02/31] Remove StringRef, ArrayRef, and Optional
|
||||
Subject: [PATCH 02/27] Remove StringRef, ArrayRef, and Optional
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallSet.h | 12 +--
|
||||
@@ -11,6 +11,7 @@ Subject: [PATCH 02/31] Remove StringRef, ArrayRef, and Optional
|
||||
llvm/include/llvm/Support/Chrono.h | 10 +--
|
||||
llvm/include/llvm/Support/Compiler.h | 2 +-
|
||||
llvm/include/llvm/Support/ConvertUTF.h | 25 +++---
|
||||
llvm/include/llvm/Support/DJB.h | 6 +-
|
||||
llvm/include/llvm/Support/ErrorHandling.h | 7 +-
|
||||
.../llvm/Support/SmallVectorMemoryBuffer.h | 6 +-
|
||||
llvm/include/llvm/Support/VersionTuple.h | 20 ++---
|
||||
@@ -27,7 +28,7 @@ Subject: [PATCH 02/31] Remove StringRef, ArrayRef, and Optional
|
||||
llvm/unittests/ADT/SmallVectorTest.cpp | 20 +----
|
||||
llvm/unittests/ADT/StringMapTest.cpp | 27 ++++---
|
||||
llvm/unittests/Support/ConvertUTFTest.cpp | 37 +++++----
|
||||
23 files changed, 234 insertions(+), 285 deletions(-)
|
||||
24 files changed, 237 insertions(+), 288 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
|
||||
index 0600e528ee69..e4c209c5f2a9 100644
|
||||
@@ -689,6 +690,27 @@ index 1add185330fa..7f1527f51cdf 100644
|
||||
std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len,
|
||||
SmallVectorImpl<char> &utf8);
|
||||
/// Convert from UTF16 to the current code page used in the system
|
||||
diff --git a/llvm/include/llvm/Support/DJB.h b/llvm/include/llvm/Support/DJB.h
|
||||
index 8a04a324a5dc..8737cd144c37 100644
|
||||
--- a/llvm/include/llvm/Support/DJB.h
|
||||
+++ b/llvm/include/llvm/Support/DJB.h
|
||||
@@ -13,13 +13,13 @@
|
||||
#ifndef LLVM_SUPPORT_DJB_H
|
||||
#define LLVM_SUPPORT_DJB_H
|
||||
|
||||
-#include "llvm/ADT/StringRef.h"
|
||||
+#include <string_view>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// The Bernstein hash function used by the DWARF accelerator tables.
|
||||
-inline uint32_t djbHash(StringRef Buffer, uint32_t H = 5381) {
|
||||
- for (unsigned char C : Buffer.bytes())
|
||||
+inline uint32_t djbHash(std::string_view Buffer, uint32_t H = 5381) {
|
||||
+ for (unsigned char C : Buffer)
|
||||
H = (H << 5) + H + C;
|
||||
return H;
|
||||
}
|
||||
diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h
|
||||
index dd85a5892e01..411c78a81b24 100644
|
||||
--- a/llvm/include/llvm/Support/ErrorHandling.h
|
||||
@@ -1506,7 +1528,7 @@ index 06b98efe66ef..1914f38fac6c 100644
|
||||
class SmallVectorReferenceInvalidationTest : public SmallVectorTestBase {
|
||||
protected:
|
||||
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
index 98fbd6e1df5a..4c4aec2184b7 100644
|
||||
index 98fbd6e1df5a..18beb3878067 100644
|
||||
--- a/llvm/unittests/ADT/StringMapTest.cpp
|
||||
+++ b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
@@ -7,7 +7,6 @@
|
||||
@@ -1561,7 +1583,7 @@ index 98fbd6e1df5a..4c4aec2184b7 100644
|
||||
StringMap<uint32_t>::value_type *entry =
|
||||
StringMap<uint32_t>::value_type::Create(
|
||||
- StringRef(testKeyFirst, testKeyLength), Allocator, 1u);
|
||||
+ std::string_view(testKeyFirst, testKeyLength), 1u);
|
||||
+ std::string_view(testKeyFirst, testKeyLength), Allocator, 1u);
|
||||
EXPECT_STREQ(testKey, entry->first().data());
|
||||
EXPECT_EQ(1u, entry->second);
|
||||
entry->Destroy(Allocator);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 81df3d81b0bffd848890d7c01d946e65744fb649 Mon Sep 17 00:00:00 2001
|
||||
From 48f55e6aa592d66f46f392330317e4efe0502faf Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:12:41 -0400
|
||||
Subject: [PATCH 03/31] Wrap std::min/max calls in parens, for windows warnings
|
||||
Subject: [PATCH 03/27] Wrap std::min/max calls in parens, for windows warnings
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/DenseMap.h | 4 ++--
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 086a4a7ee635c68d81b85044c9f8f4317b2b164c Mon Sep 17 00:00:00 2001
|
||||
From 1c61002f2933aedbcc64ff52de7f69666479e55a Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:13:55 -0400
|
||||
Subject: [PATCH 04/31] Change uniqe_function storage size
|
||||
Subject: [PATCH 04/27] Change uniqe_function storage size
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/FunctionExtras.h | 4 ++--
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From a53483a33c8d5778e5594a49376b5bafe742d126 Mon Sep 17 00:00:00 2001
|
||||
From 5ca3ff668002f9bf89c134aec9976526c61929da Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:17:19 -0400
|
||||
Subject: [PATCH 05/31] Threading updates
|
||||
Subject: [PATCH 05/27] Threading updates
|
||||
|
||||
- Remove guards for threads and exception
|
||||
- Prefer scope gaurd over lock gaurd
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
From 04f1186ea8f0160da1a1863a344ff9a9f55b6733 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:24:34 -0400
|
||||
Subject: [PATCH 06/31] Remove DJB hash dependency
|
||||
|
||||
---
|
||||
llvm/lib/Support/StringMap.cpp | 21 ++++++++++++++++++---
|
||||
1 file changed, 18 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
|
||||
index d9eeba619428..f0d5ae6de646 100644
|
||||
--- a/llvm/lib/Support/StringMap.cpp
|
||||
+++ b/llvm/lib/Support/StringMap.cpp
|
||||
@@ -12,11 +12,26 @@
|
||||
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
-#include "llvm/Support/DJB.h"
|
||||
+#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
+/// HashString - Hash function for strings.
|
||||
+///
|
||||
+/// This is the Bernstein hash function.
|
||||
+//
|
||||
+// FIXME: Investigate whether a modified bernstein hash function performs
|
||||
+// better: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
|
||||
+// X*33+c -> X*33^c
|
||||
+static inline unsigned HashString(std::string_view str,
|
||||
+ unsigned result = 0) noexcept {
|
||||
+ for (std::string_view::size_type i = 0, e = str.size(); i != e; ++i) {
|
||||
+ result = result * 33 + static_cast<unsigned char>(str[i]);
|
||||
+ }
|
||||
+ return result;
|
||||
+}
|
||||
+
|
||||
/// Returns the number of buckets to allocate to ensure that the DenseMap can
|
||||
/// accommodate \p NumEntries without need to grow().
|
||||
static unsigned getMinBucketToReserveForEntries(unsigned NumEntries) {
|
||||
@@ -77,7 +92,7 @@ unsigned StringMapImpl::LookupBucketFor(std::string_view Name) {
|
||||
init(16);
|
||||
HTSize = NumBuckets;
|
||||
}
|
||||
- unsigned FullHashValue = djbHash(Name, 0);
|
||||
+ unsigned FullHashValue = HashString(Name);
|
||||
unsigned BucketNo = FullHashValue & (HTSize - 1);
|
||||
unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1);
|
||||
|
||||
@@ -133,7 +148,7 @@ int StringMapImpl::FindKey(std::string_view Key) const {
|
||||
unsigned HTSize = NumBuckets;
|
||||
if (HTSize == 0)
|
||||
return -1; // Really empty table?
|
||||
- unsigned FullHashValue = djbHash(Key, 0);
|
||||
+ unsigned FullHashValue = HashString(Key);
|
||||
unsigned BucketNo = FullHashValue & (HTSize - 1);
|
||||
unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1);
|
||||
|
||||
--
|
||||
2.20.1.windows.1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From d16ac9833a8469fe49b564ad21e2331875b450b8 Mon Sep 17 00:00:00 2001
|
||||
From 20727a44aa8138cbda12065a6087390b4632b958 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:28:13 -0400
|
||||
Subject: [PATCH 07/31] #ifdef guard safety
|
||||
Subject: [PATCH 06/27] #ifdef guard safety
|
||||
|
||||
Prevents redefinition if someone is pulling in real LLVM, since the macros are in global namespace
|
||||
---
|
||||
@@ -1,7 +1,7 @@
|
||||
From 945a1d5a54ad830f857625417da414d05d367a37 Mon Sep 17 00:00:00 2001
|
||||
From 6098845aed7416fde8a9c1f276571c8a1bc27799 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:37:34 -0400
|
||||
Subject: [PATCH 08/31] Explicitly use std::
|
||||
Subject: [PATCH 07/27] Explicitly use std::
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallSet.h | 2 +-
|
||||
@@ -64,7 +64,7 @@ index 6f3c94eed273..531f81ab5b3f 100644
|
||||
EXPECT_EQ(F - Found + 1, *F);
|
||||
}
|
||||
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
index 4c4aec2184b7..5211f01bbd73 100644
|
||||
index 18beb3878067..081b699adee3 100644
|
||||
--- a/llvm/unittests/ADT/StringMapTest.cpp
|
||||
+++ b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
@@ -308,7 +308,7 @@ TEST_F(StringMapTest, IterMapKeys) {
|
||||
@@ -1,7 +1,7 @@
|
||||
From 1f42fe3358dc55b9686d9c2dd0725dd7e4a14efa Mon Sep 17 00:00:00 2001
|
||||
From c7d5902712292ad85b8580437c1f09a16d79def9 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:53:50 -0400
|
||||
Subject: [PATCH 09/31] Remove format_provider
|
||||
Subject: [PATCH 08/27] Remove format_provider
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/Chrono.h | 109 ------------------------
|
||||
@@ -1,7 +1,7 @@
|
||||
From 2e9ec7d3e5c58424fde4312784e2a9faab58fe2c Mon Sep 17 00:00:00 2001
|
||||
From a55cc2394a9fca533d8d07e3b61e47fedb99cd1b Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 13:34:07 -0400
|
||||
Subject: [PATCH 13/31] Add compiler warning pragrams
|
||||
Subject: [PATCH 09/27] Add compiler warning pragrams
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/FunctionExtras.h | 10 ++++++++++
|
||||
@@ -1,266 +0,0 @@
|
||||
From 29e7b322eab2284b434cc270bb36ade7c8a62755 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 23:02:07 -0400
|
||||
Subject: [PATCH 10/31] Remove reverse iterator
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/DenseMap.h | 74 ++++-------------------------
|
||||
llvm/include/llvm/ADT/SmallPtrSet.h | 21 +-------
|
||||
2 files changed, 11 insertions(+), 84 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
|
||||
index 588c39faea2f..5e5c020adf0b 100644
|
||||
--- a/llvm/include/llvm/ADT/DenseMap.h
|
||||
+++ b/llvm/include/llvm/ADT/DenseMap.h
|
||||
@@ -76,8 +76,6 @@ public:
|
||||
// empty buckets.
|
||||
if (empty())
|
||||
return end();
|
||||
- if (shouldReverseIterate<KeyT>())
|
||||
- return makeIterator(getBucketsEnd() - 1, getBuckets(), *this);
|
||||
return makeIterator(getBuckets(), getBucketsEnd(), *this);
|
||||
}
|
||||
inline iterator end() {
|
||||
@@ -86,8 +84,6 @@ public:
|
||||
inline const_iterator begin() const {
|
||||
if (empty())
|
||||
return end();
|
||||
- if (shouldReverseIterate<KeyT>())
|
||||
- return makeConstIterator(getBucketsEnd() - 1, getBuckets(), *this);
|
||||
return makeConstIterator(getBuckets(), getBucketsEnd(), *this);
|
||||
}
|
||||
inline const_iterator end() const {
|
||||
@@ -150,18 +146,14 @@ public:
|
||||
iterator find(const_arg_type_t<KeyT> Val) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
- return makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
const_iterator find(const_arg_type_t<KeyT> Val) const {
|
||||
const BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
- return makeConstIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return makeConstIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
@@ -175,9 +167,7 @@ public:
|
||||
iterator find_as(const LookupKeyT &Val) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
- return makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
@@ -185,9 +175,7 @@ public:
|
||||
const_iterator find_as(const LookupKeyT &Val) const {
|
||||
const BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
- return makeConstIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return makeConstIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
@@ -222,20 +210,14 @@ public:
|
||||
std::pair<iterator, bool> try_emplace(KeyT &&Key, Ts &&... Args) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Key, TheBucket))
|
||||
- return std::make_pair(makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>()
|
||||
- ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true),
|
||||
false); // Already in map.
|
||||
|
||||
// Otherwise, insert the new element.
|
||||
TheBucket =
|
||||
InsertIntoBucket(TheBucket, std::move(Key), std::forward<Ts>(Args)...);
|
||||
- return std::make_pair(makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>()
|
||||
- ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true),
|
||||
true);
|
||||
}
|
||||
@@ -247,19 +229,13 @@ public:
|
||||
std::pair<iterator, bool> try_emplace(const KeyT &Key, Ts &&... Args) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Key, TheBucket))
|
||||
- return std::make_pair(makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>()
|
||||
- ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true),
|
||||
false); // Already in map.
|
||||
|
||||
// Otherwise, insert the new element.
|
||||
TheBucket = InsertIntoBucket(TheBucket, Key, std::forward<Ts>(Args)...);
|
||||
- return std::make_pair(makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>()
|
||||
- ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true),
|
||||
true);
|
||||
}
|
||||
@@ -274,20 +250,14 @@ public:
|
||||
const LookupKeyT &Val) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
- return std::make_pair(makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>()
|
||||
- ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true),
|
||||
false); // Already in map.
|
||||
|
||||
// Otherwise, insert the new element.
|
||||
TheBucket = InsertIntoBucketWithLookup(TheBucket, std::move(KV.first),
|
||||
std::move(KV.second), Val);
|
||||
- return std::make_pair(makeIterator(TheBucket,
|
||||
- shouldReverseIterate<KeyT>()
|
||||
- ? getBuckets()
|
||||
- : getBucketsEnd(),
|
||||
+ return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
*this, true),
|
||||
true);
|
||||
}
|
||||
@@ -464,20 +434,12 @@ private:
|
||||
iterator makeIterator(BucketT *P, BucketT *E,
|
||||
DebugEpochBase &Epoch,
|
||||
bool NoAdvance=false) {
|
||||
- if (shouldReverseIterate<KeyT>()) {
|
||||
- BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
|
||||
- return iterator(B, E, Epoch, NoAdvance);
|
||||
- }
|
||||
return iterator(P, E, Epoch, NoAdvance);
|
||||
}
|
||||
|
||||
const_iterator makeConstIterator(const BucketT *P, const BucketT *E,
|
||||
const DebugEpochBase &Epoch,
|
||||
const bool NoAdvance=false) const {
|
||||
- if (shouldReverseIterate<KeyT>()) {
|
||||
- const BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
|
||||
- return const_iterator(B, E, Epoch, NoAdvance);
|
||||
- }
|
||||
return const_iterator(P, E, Epoch, NoAdvance);
|
||||
}
|
||||
|
||||
@@ -1214,10 +1176,6 @@ public:
|
||||
assert(isHandleInSync() && "invalid construction!");
|
||||
|
||||
if (NoAdvance) return;
|
||||
- if (shouldReverseIterate<KeyT>()) {
|
||||
- RetreatPastEmptyBuckets();
|
||||
- return;
|
||||
- }
|
||||
AdvancePastEmptyBuckets();
|
||||
}
|
||||
|
||||
@@ -1232,16 +1190,10 @@ public:
|
||||
|
||||
reference operator*() const {
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
- assert(Ptr != End && "dereferencing end() iterator");
|
||||
- if (shouldReverseIterate<KeyT>())
|
||||
- return Ptr[-1];
|
||||
return *Ptr;
|
||||
}
|
||||
pointer operator->() const {
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
- assert(Ptr != End && "dereferencing end() iterator");
|
||||
- if (shouldReverseIterate<KeyT>())
|
||||
- return &(Ptr[-1]);
|
||||
return Ptr;
|
||||
}
|
||||
|
||||
@@ -1261,12 +1213,6 @@ public:
|
||||
|
||||
inline DenseMapIterator& operator++() { // Preincrement
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
- assert(Ptr != End && "incrementing end() iterator");
|
||||
- if (shouldReverseIterate<KeyT>()) {
|
||||
- --Ptr;
|
||||
- RetreatPastEmptyBuckets();
|
||||
- return *this;
|
||||
- }
|
||||
++Ptr;
|
||||
AdvancePastEmptyBuckets();
|
||||
return *this;
|
||||
diff --git a/llvm/include/llvm/ADT/SmallPtrSet.h b/llvm/include/llvm/ADT/SmallPtrSet.h
|
||||
index 981b741669b0..e46a5171e301 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallPtrSet.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallPtrSet.h
|
||||
@@ -226,10 +226,6 @@ protected:
|
||||
public:
|
||||
explicit SmallPtrSetIteratorImpl(const void *const *BP, const void*const *E)
|
||||
: Bucket(BP), End(E) {
|
||||
- if (shouldReverseIterate()) {
|
||||
- RetreatIfNotValid();
|
||||
- return;
|
||||
- }
|
||||
AdvanceIfNotValid();
|
||||
}
|
||||
|
||||
@@ -281,22 +277,11 @@ public:
|
||||
// Most methods are provided by the base class.
|
||||
|
||||
const PtrTy operator*() const {
|
||||
- assert(isHandleInSync() && "invalid iterator access!");
|
||||
- if (shouldReverseIterate()) {
|
||||
- assert(Bucket > End);
|
||||
- return PtrTraits::getFromVoidPointer(const_cast<void *>(Bucket[-1]));
|
||||
- }
|
||||
assert(Bucket < End);
|
||||
return PtrTraits::getFromVoidPointer(const_cast<void*>(*Bucket));
|
||||
}
|
||||
|
||||
inline SmallPtrSetIterator& operator++() { // Preincrement
|
||||
- assert(isHandleInSync() && "invalid iterator access!");
|
||||
- if (shouldReverseIterate()) {
|
||||
- --Bucket;
|
||||
- RetreatIfNotValid();
|
||||
- return *this;
|
||||
- }
|
||||
++Bucket;
|
||||
AdvanceIfNotValid();
|
||||
return *this;
|
||||
@@ -400,8 +385,6 @@ public:
|
||||
}
|
||||
|
||||
iterator begin() const {
|
||||
- if (shouldReverseIterate())
|
||||
- return makeIterator(EndPointer() - 1);
|
||||
return makeIterator(CurArray);
|
||||
}
|
||||
iterator end() const { return makeIterator(EndPointer()); }
|
||||
@@ -409,9 +392,7 @@ public:
|
||||
private:
|
||||
/// Create an iterator that dereferences to same place as the given pointer.
|
||||
iterator makeIterator(const void *const *P) const {
|
||||
- if (shouldReverseIterate())
|
||||
- return iterator(P == EndPointer() ? CurArray : P + 1, CurArray, *this);
|
||||
- return iterator(P, EndPointer(), *this);
|
||||
+ return iterator(P, EndPointer());
|
||||
}
|
||||
};
|
||||
|
||||
--
|
||||
2.20.1.windows.1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From e8352137c16b81ab7af248e608eca3a1d8221e37 Mon Sep 17 00:00:00 2001
|
||||
From 1354697da0c8661ef6030eb6355a680bbed7b752 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 13:43:50 -0400
|
||||
Subject: [PATCH 14/31] Remove unused functions
|
||||
Subject: [PATCH 10/27] Remove unused functions
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallString.h | 80 ------
|
||||
@@ -1,7 +1,7 @@
|
||||
From b887e8f6e34e2ff2a3ad69f67f84f49ceb1f455e Mon Sep 17 00:00:00 2001
|
||||
From 0afb3b1de99d7f85899d3907e5e9a503a6ac599a Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 5 May 2022 23:18:34 -0400
|
||||
Subject: [PATCH 15/31] Detemplatize small vector base
|
||||
Subject: [PATCH 11/27] Detemplatize small vector base
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallVector.h | 21 +++++++-----------
|
||||
@@ -1,237 +0,0 @@
|
||||
From be653ec8d4b0a5944fcf084a911389cb0c5cc205 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 23:07:38 -0400
|
||||
Subject: [PATCH 11/31] Remove allocator from collections
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/StringMap.h | 33 +++++++-------------------
|
||||
llvm/include/llvm/ADT/StringMapEntry.h | 25 +++++++------------
|
||||
llvm/unittests/ADT/StringMapTest.cpp | 14 +++++------
|
||||
3 files changed, 23 insertions(+), 49 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h
|
||||
index 5f463cfef943..3b40bba37f58 100644
|
||||
--- a/llvm/include/llvm/ADT/StringMap.h
|
||||
+++ b/llvm/include/llvm/ADT/StringMap.h
|
||||
@@ -104,10 +104,8 @@ public:
|
||||
/// keys that are "strings", which are basically ranges of bytes. This does some
|
||||
/// funky memory allocation and hashing things to make it extremely efficient,
|
||||
/// storing the string data *after* the value in the map.
|
||||
-template <typename ValueTy, typename AllocatorTy = MallocAllocator>
|
||||
+template<typename ValueTy>
|
||||
class StringMap : public StringMapImpl {
|
||||
- AllocatorTy Allocator;
|
||||
-
|
||||
public:
|
||||
using MapEntryTy = StringMapEntry<ValueTy>;
|
||||
|
||||
@@ -116,14 +114,6 @@ public:
|
||||
explicit StringMap(unsigned InitialSize)
|
||||
: StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {}
|
||||
|
||||
- explicit StringMap(AllocatorTy A)
|
||||
- : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))), Allocator(A) {
|
||||
- }
|
||||
-
|
||||
- StringMap(unsigned InitialSize, AllocatorTy A)
|
||||
- : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))),
|
||||
- Allocator(A) {}
|
||||
-
|
||||
StringMap(std::initializer_list<std::pair<std::string_view, ValueTy>> List)
|
||||
: StringMapImpl(List.size(), static_cast<unsigned>(sizeof(MapEntryTy))) {
|
||||
for (const auto &P : List) {
|
||||
@@ -132,11 +122,10 @@ public:
|
||||
}
|
||||
|
||||
StringMap(StringMap &&RHS)
|
||||
- : StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator)) {}
|
||||
+ : StringMapImpl(std::move(RHS)) {}
|
||||
|
||||
- StringMap(const StringMap &RHS)
|
||||
- : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))),
|
||||
- Allocator(RHS.Allocator) {
|
||||
+ StringMap(const StringMap &RHS) :
|
||||
+ StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {
|
||||
if (RHS.empty())
|
||||
return;
|
||||
|
||||
@@ -156,7 +145,7 @@ public:
|
||||
}
|
||||
|
||||
TheTable[I] = MapEntryTy::Create(
|
||||
- static_cast<MapEntryTy *>(Bucket)->getKey(), Allocator,
|
||||
+ static_cast<MapEntryTy *>(Bucket)->getKey(),
|
||||
static_cast<MapEntryTy *>(Bucket)->getValue());
|
||||
HashTable[I] = RHSHashTable[I];
|
||||
}
|
||||
@@ -171,7 +160,6 @@ public:
|
||||
|
||||
StringMap &operator=(StringMap RHS) {
|
||||
StringMapImpl::swap(RHS);
|
||||
- std::swap(Allocator, RHS.Allocator);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -183,16 +171,13 @@ public:
|
||||
for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
|
||||
StringMapEntryBase *Bucket = TheTable[I];
|
||||
if (Bucket && Bucket != getTombstoneVal()) {
|
||||
- static_cast<MapEntryTy *>(Bucket)->Destroy(Allocator);
|
||||
+ static_cast<MapEntryTy *>(Bucket)->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
free(TheTable);
|
||||
}
|
||||
|
||||
- AllocatorTy &getAllocator() { return Allocator; }
|
||||
- const AllocatorTy &getAllocator() const { return Allocator; }
|
||||
-
|
||||
using key_type = const char *;
|
||||
using mapped_type = ValueTy;
|
||||
using value_type = StringMapEntry<ValueTy>;
|
||||
@@ -321,7 +306,7 @@ public:
|
||||
|
||||
if (Bucket == getTombstoneVal())
|
||||
--NumTombstones;
|
||||
- Bucket = MapEntryTy::Create(Key, Allocator, std::forward<ArgsTy>(Args)...);
|
||||
+ Bucket = MapEntryTy::Create(Key, std::forward<ArgsTy>(Args)...);
|
||||
++NumItems;
|
||||
assert(NumItems + NumTombstones <= NumBuckets);
|
||||
|
||||
@@ -339,7 +324,7 @@ public:
|
||||
for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
|
||||
StringMapEntryBase *&Bucket = TheTable[I];
|
||||
if (Bucket && Bucket != getTombstoneVal()) {
|
||||
- static_cast<MapEntryTy *>(Bucket)->Destroy(Allocator);
|
||||
+ static_cast<MapEntryTy *>(Bucket)->Destroy();
|
||||
}
|
||||
Bucket = nullptr;
|
||||
}
|
||||
@@ -355,7 +340,7 @@ public:
|
||||
void erase(iterator I) {
|
||||
MapEntryTy &V = *I;
|
||||
remove(&V);
|
||||
- V.Destroy(Allocator);
|
||||
+ V.Destroy();
|
||||
}
|
||||
|
||||
bool erase(std::string_view Key) {
|
||||
diff --git a/llvm/include/llvm/ADT/StringMapEntry.h b/llvm/include/llvm/ADT/StringMapEntry.h
|
||||
index 93e13b5bb16c..66a30698d787 100644
|
||||
--- a/llvm/include/llvm/ADT/StringMapEntry.h
|
||||
+++ b/llvm/include/llvm/ADT/StringMapEntry.h
|
||||
@@ -33,22 +33,14 @@ protected:
|
||||
/// Helper to tail-allocate \p Key. It'd be nice to generalize this so it
|
||||
/// could be reused elsewhere, maybe even taking an llvm::function_ref to
|
||||
/// type-erase the allocator and put it in a source file.
|
||||
- template <typename AllocatorTy>
|
||||
static void *allocateWithKey(size_t EntrySize, size_t EntryAlign,
|
||||
- std::string_view Key, AllocatorTy &Allocator);
|
||||
-};
|
||||
-
|
||||
-// Define out-of-line to dissuade inlining.
|
||||
-template <typename AllocatorTy>
|
||||
-void *StringMapEntryBase::allocateWithKey(size_t EntrySize, size_t EntryAlign,
|
||||
- std::string_view Key,
|
||||
- AllocatorTy &Allocator) {
|
||||
+ std::string_view Key) {
|
||||
size_t KeyLength = Key.size();
|
||||
|
||||
// Allocate a new item with space for the string at the end and a null
|
||||
// terminator.
|
||||
size_t AllocSize = EntrySize + KeyLength + 1;
|
||||
- void *Allocation = Allocator.Allocate(AllocSize, EntryAlign);
|
||||
+ void *Allocation = safe_malloc(AllocSize);
|
||||
assert(Allocation && "Unhandled out-of-memory");
|
||||
|
||||
// Copy the string information.
|
||||
@@ -58,6 +50,7 @@ void *StringMapEntryBase::allocateWithKey(size_t EntrySize, size_t EntryAlign,
|
||||
Buffer[KeyLength] = 0; // Null terminate for convenience of clients.
|
||||
return Allocation;
|
||||
}
|
||||
+};
|
||||
|
||||
/// StringMapEntryStorage - Holds the value in a StringMapEntry.
|
||||
///
|
||||
@@ -117,11 +110,11 @@ public:
|
||||
|
||||
/// Create a StringMapEntry for the specified key construct the value using
|
||||
/// \p InitiVals.
|
||||
- template <typename AllocatorTy, typename... InitTy>
|
||||
- static StringMapEntry *Create(std::string_view key, AllocatorTy &allocator,
|
||||
+ template <typename... InitTy>
|
||||
+ static StringMapEntry *Create(std::string_view key,
|
||||
InitTy &&... initVals) {
|
||||
return new (StringMapEntryBase::allocateWithKey(
|
||||
- sizeof(StringMapEntry), alignof(StringMapEntry), key, allocator))
|
||||
+ sizeof(StringMapEntry), alignof(StringMapEntry), key))
|
||||
StringMapEntry(key.size(), std::forward<InitTy>(initVals)...);
|
||||
}
|
||||
|
||||
@@ -134,12 +127,10 @@ public:
|
||||
|
||||
/// Destroy - Destroy this StringMapEntry, releasing memory back to the
|
||||
/// specified allocator.
|
||||
- template <typename AllocatorTy> void Destroy(AllocatorTy &allocator) {
|
||||
+ void Destroy() {
|
||||
// Free memory referenced by the item.
|
||||
- size_t AllocSize = sizeof(StringMapEntry) + this->getKeyLength() + 1;
|
||||
this->~StringMapEntry();
|
||||
- allocator.Deallocate(static_cast<void *>(this), AllocSize,
|
||||
- alignof(StringMapEntry));
|
||||
+ std::free(static_cast<void *>(this));
|
||||
}
|
||||
};
|
||||
|
||||
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
index 5211f01bbd73..28d710fe69e9 100644
|
||||
--- a/llvm/unittests/ADT/StringMapTest.cpp
|
||||
+++ b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
@@ -223,13 +223,12 @@ TEST_F(StringMapTest, IterationTest) {
|
||||
|
||||
// Test StringMapEntry::Create() method.
|
||||
TEST_F(StringMapTest, StringMapEntryTest) {
|
||||
- MallocAllocator Allocator;
|
||||
StringMap<uint32_t>::value_type *entry =
|
||||
StringMap<uint32_t>::value_type::Create(
|
||||
std::string_view(testKeyFirst, testKeyLength), 1u);
|
||||
EXPECT_STREQ(testKey, entry->first().data());
|
||||
EXPECT_EQ(1u, entry->second);
|
||||
- entry->Destroy(Allocator);
|
||||
+ entry->Destroy();
|
||||
}
|
||||
|
||||
// Test insert() method.
|
||||
@@ -238,7 +237,7 @@ TEST_F(StringMapTest, InsertTest) {
|
||||
testMap.insert(
|
||||
StringMap<uint32_t>::value_type::Create(
|
||||
std::string_view(testKeyFirst, testKeyLength),
|
||||
- testMap.getAllocator(), 1u));
|
||||
+ 1u));
|
||||
assertSingleItemMap();
|
||||
}
|
||||
|
||||
@@ -353,15 +352,14 @@ TEST_F(StringMapTest, MoveOnly) {
|
||||
StringMap<MoveOnly> t;
|
||||
t.insert(std::make_pair("Test", MoveOnly(42)));
|
||||
std::string_view Key = "Test";
|
||||
- StringMapEntry<MoveOnly>::Create(Key, t.getAllocator(), MoveOnly(42))
|
||||
- ->Destroy(t.getAllocator());
|
||||
+ StringMapEntry<MoveOnly>::Create(Key, MoveOnly(42))
|
||||
+ ->Destroy();
|
||||
}
|
||||
|
||||
TEST_F(StringMapTest, CtorArg) {
|
||||
std::string_view Key = "Test";
|
||||
- MallocAllocator Allocator;
|
||||
- StringMapEntry<MoveOnly>::Create(Key, Allocator, Immovable())
|
||||
- ->Destroy(Allocator);
|
||||
+ StringMapEntry<MoveOnly>::Create(Key, Immovable())
|
||||
+ ->Destroy();
|
||||
}
|
||||
|
||||
TEST_F(StringMapTest, MoveConstruct) {
|
||||
--
|
||||
2.20.1.windows.1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From eada33299195b46a8942e198ae8ae41185cd4f45 Mon Sep 17 00:00:00 2001
|
||||
From c01b703c5d54cb57f8a73215a4ca8aded32dd9ba Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 13:48:59 -0400
|
||||
Subject: [PATCH 16/31] Add vectors to raw_ostream
|
||||
Subject: [PATCH 12/27] Add vectors to raw_ostream
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/raw_ostream.h | 115 ++++++++++++++++++++++++
|
||||
@@ -1,91 +0,0 @@
|
||||
From ba61e94bf9e2273b6a2e5d3d4b2bb74f76536b19 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 23:08:15 -0400
|
||||
Subject: [PATCH 12/31] Remove EpochTracker
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallPtrSet.h | 14 ++++----------
|
||||
llvm/lib/Support/SmallPtrSet.cpp | 1 -
|
||||
2 files changed, 4 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/SmallPtrSet.h b/llvm/include/llvm/ADT/SmallPtrSet.h
|
||||
index e46a5171e301..2edc1f5e2066 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallPtrSet.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallPtrSet.h
|
||||
@@ -14,7 +14,6 @@
|
||||
#ifndef LLVM_ADT_SMALLPTRSET_H
|
||||
#define LLVM_ADT_SMALLPTRSET_H
|
||||
|
||||
-#include "llvm/ADT/EpochTracker.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/ReverseIteration.h"
|
||||
#include "llvm/Support/type_traits.h"
|
||||
@@ -46,7 +45,7 @@ namespace llvm {
|
||||
/// (-2), to allow deletion. The hash table is resized when the table is 3/4 or
|
||||
/// more. When this happens, the table is doubled in size.
|
||||
///
|
||||
-class SmallPtrSetImplBase : public DebugEpochBase {
|
||||
+class SmallPtrSetImplBase {
|
||||
friend class SmallPtrSetIteratorImpl;
|
||||
|
||||
protected:
|
||||
@@ -92,7 +91,6 @@ public:
|
||||
size_type size() const { return NumNonEmpty - NumTombstones; }
|
||||
|
||||
void clear() {
|
||||
- incrementEpoch();
|
||||
// If the capacity of the array is huge, and the # elements used is small,
|
||||
// shrink the array.
|
||||
if (!isSmall()) {
|
||||
@@ -139,14 +137,12 @@ protected:
|
||||
if (LastTombstone != nullptr) {
|
||||
*LastTombstone = Ptr;
|
||||
--NumTombstones;
|
||||
- incrementEpoch();
|
||||
return std::make_pair(LastTombstone, true);
|
||||
}
|
||||
|
||||
// Nope, there isn't. If we stay small, just 'pushback' now.
|
||||
if (NumNonEmpty < CurArraySize) {
|
||||
SmallArray[NumNonEmpty++] = Ptr;
|
||||
- incrementEpoch();
|
||||
return std::make_pair(SmallArray + (NumNonEmpty - 1), true);
|
||||
}
|
||||
// Otherwise, hit the big set case, which will call grow.
|
||||
@@ -259,8 +255,7 @@ protected:
|
||||
|
||||
/// SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
|
||||
template <typename PtrTy>
|
||||
-class SmallPtrSetIterator : public SmallPtrSetIteratorImpl,
|
||||
- DebugEpochBase::HandleBase {
|
||||
+class SmallPtrSetIterator : public SmallPtrSetIteratorImpl {
|
||||
using PtrTraits = PointerLikeTypeTraits<PtrTy>;
|
||||
|
||||
public:
|
||||
@@ -270,9 +265,8 @@ public:
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
- explicit SmallPtrSetIterator(const void *const *BP, const void *const *E,
|
||||
- const DebugEpochBase &Epoch)
|
||||
- : SmallPtrSetIteratorImpl(BP, E), DebugEpochBase::HandleBase(&Epoch) {}
|
||||
+ explicit SmallPtrSetIterator(const void *const *BP, const void *const *E)
|
||||
+ : SmallPtrSetIteratorImpl(BP, E) {}
|
||||
|
||||
// Most methods are provided by the base class.
|
||||
|
||||
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
|
||||
index f6e2dfb8a6c9..4549db08e3ee 100644
|
||||
--- a/llvm/lib/Support/SmallPtrSet.cpp
|
||||
+++ b/llvm/lib/Support/SmallPtrSet.cpp
|
||||
@@ -59,7 +59,6 @@ SmallPtrSetImplBase::insert_imp_big(const void *Ptr) {
|
||||
else
|
||||
++NumNonEmpty; // Track density.
|
||||
*Bucket = Ptr;
|
||||
- incrementEpoch();
|
||||
return std::make_pair(Bucket, true);
|
||||
}
|
||||
|
||||
--
|
||||
2.20.1.windows.1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From fc8a16f804f5d37e179f8eac521f8430e663d1a0 Mon Sep 17 00:00:00 2001
|
||||
From 1c2a3d6eb4737e5b822ca8729472ddcf5c4d78c2 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Tue, 3 May 2022 22:16:10 -0400
|
||||
Subject: [PATCH 17/31] Extra collections features
|
||||
Subject: [PATCH 13/27] Extra collections features
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/StringMap.h | 103 +++++++++++++++++++++++++++++-
|
||||
@@ -9,7 +9,7 @@ Subject: [PATCH 17/31] Extra collections features
|
||||
2 files changed, 110 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h
|
||||
index 3b40bba37f58..af4be84e469d 100644
|
||||
index 5f463cfef943..ac0d4b363145 100644
|
||||
--- a/llvm/include/llvm/ADT/StringMap.h
|
||||
+++ b/llvm/include/llvm/ADT/StringMap.h
|
||||
@@ -40,7 +40,7 @@ protected:
|
||||
@@ -21,7 +21,7 @@ index 3b40bba37f58..af4be84e469d 100644
|
||||
: TheTable(RHS.TheTable), NumBuckets(RHS.NumBuckets),
|
||||
NumItems(RHS.NumItems), NumTombstones(RHS.NumTombstones),
|
||||
ItemSize(RHS.ItemSize) {
|
||||
@@ -390,11 +390,27 @@ public:
|
||||
@@ -405,11 +405,27 @@ public:
|
||||
return Tmp;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ index 3b40bba37f58..af4be84e469d 100644
|
||||
};
|
||||
|
||||
template <typename ValueTy>
|
||||
@@ -459,6 +475,91 @@ private:
|
||||
@@ -474,6 +490,91 @@ private:
|
||||
std::string_view Key;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0986c8a95cad971a1bf84259e1ab698497ca205c Mon Sep 17 00:00:00 2001
|
||||
From 72ab19d035da6d31695f3622270978608d7ef0ef Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Wed, 4 May 2022 00:01:00 -0400
|
||||
Subject: [PATCH 18/31] EpochTracker abi macro
|
||||
Subject: [PATCH 14/27] EpochTracker abi macro
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/EpochTracker.h | 2 +-
|
||||
@@ -1,7 +1,7 @@
|
||||
From f2b2850258fe3aed54c64f8afac2565b00ddf4b0 Mon Sep 17 00:00:00 2001
|
||||
From bb8c33904fba6099ca17ddecd84fa20272c5a20c Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 5 May 2022 18:09:45 -0400
|
||||
Subject: [PATCH 19/31] Delete numbers from mathextras
|
||||
Subject: [PATCH 15/27] Delete numbers from mathextras
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/MathExtras.h | 36 --------------------------
|
||||
@@ -1,7 +1,7 @@
|
||||
From 2a2ac87a1ac74a1c6e29c205b3fd979ab77722b4 Mon Sep 17 00:00:00 2001
|
||||
From 08f507c2c558f3ae9fcd7a31c7ce33b0776bfe8a Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Tue, 3 May 2022 22:50:24 -0400
|
||||
Subject: [PATCH 20/31] Add lerp and sgn
|
||||
Subject: [PATCH 16/27] Add lerp and sgn
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/MathExtras.h | 20 ++++++++++++++++++++
|
||||
@@ -1,10 +1,10 @@
|
||||
From b013523b36cba3c8fc0ced2ca013a8763573d5a0 Mon Sep 17 00:00:00 2001
|
||||
From 8e868fdb545f3facb646418b5e127e360fe88a99 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:38:11 -0400
|
||||
Subject: [PATCH 21/31] Fixup includes
|
||||
Subject: [PATCH 17/27] Fixup includes
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/StringMap.h | 5 ++++-
|
||||
llvm/include/llvm/ADT/StringMap.h | 4 ++++
|
||||
llvm/include/llvm/ADT/StringMapEntry.h | 4 ++++
|
||||
llvm/include/llvm/Support/PointerLikeTypeTraits.h | 1 +
|
||||
llvm/lib/Support/ConvertUTFWrapper.cpp | 1 +
|
||||
@@ -13,17 +13,16 @@ Subject: [PATCH 21/31] Fixup includes
|
||||
llvm/unittests/ADT/SmallPtrSetTest.cpp | 2 ++
|
||||
llvm/unittests/ADT/StringMapTest.cpp | 1 +
|
||||
llvm/unittests/Support/ConvertUTFTest.cpp | 2 ++
|
||||
9 files changed, 24 insertions(+), 11 deletions(-)
|
||||
9 files changed, 24 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h
|
||||
index af4be84e469d..c41057cb6792 100644
|
||||
index ac0d4b363145..f7bf5ad9c063 100644
|
||||
--- a/llvm/include/llvm/ADT/StringMap.h
|
||||
+++ b/llvm/include/llvm/ADT/StringMap.h
|
||||
@@ -14,7 +14,10 @@
|
||||
#define LLVM_ADT_STRINGMAP_H
|
||||
@@ -15,6 +15,10 @@
|
||||
|
||||
#include "llvm/ADT/StringMapEntry.h"
|
||||
-#include "llvm/Support/AllocatorBase.h"
|
||||
#include "llvm/Support/AllocatorBase.h"
|
||||
+#include "llvm/Support/MemAlloc.h"
|
||||
+#include "llvm/Support/SmallVector.h"
|
||||
+#include "llvm/Support/iterator.h"
|
||||
@@ -32,7 +31,7 @@ index af4be84e469d..c41057cb6792 100644
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
diff --git a/llvm/include/llvm/ADT/StringMapEntry.h b/llvm/include/llvm/ADT/StringMapEntry.h
|
||||
index 66a30698d787..1201bb8e69d4 100644
|
||||
index 93e13b5bb16c..cdf11d627200 100644
|
||||
--- a/llvm/include/llvm/ADT/StringMapEntry.h
|
||||
+++ b/llvm/include/llvm/ADT/StringMapEntry.h
|
||||
@@ -15,6 +15,10 @@
|
||||
@@ -143,7 +142,7 @@ index 531f81ab5b3f..3db8b6e37d31 100644
|
||||
|
||||
TEST(SmallPtrSetTest, Assignment) {
|
||||
diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
index 28d710fe69e9..60571cff6927 100644
|
||||
index 081b699adee3..64bb8f85c4b9 100644
|
||||
--- a/llvm/unittests/ADT/StringMapTest.cpp
|
||||
+++ b/llvm/unittests/ADT/StringMapTest.cpp
|
||||
@@ -9,6 +9,7 @@
|
||||
@@ -1,7 +1,7 @@
|
||||
From 6df7cc04af50a1afad6f8baf8ea0520576944bed Mon Sep 17 00:00:00 2001
|
||||
From 024847ab39cbe06024da3f5c63d9a667aff4e500 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:42:09 -0400
|
||||
Subject: [PATCH 22/31] use std is_trivially_copy_constructible
|
||||
Subject: [PATCH 18/27] use std is_trivially_copy_constructible
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/PointerIntPair.h | 12 ----
|
||||
@@ -1,7 +1,7 @@
|
||||
From 403d6612f25ae09b3bbeffe3ed75e8c498f80da5 Mon Sep 17 00:00:00 2001
|
||||
From 45d53c5dc0cc2924569a96c1ac1e4efcaaa60044 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Tue, 3 May 2022 20:22:38 -0400
|
||||
Subject: [PATCH 23/31] Windows Support
|
||||
Subject: [PATCH 19/27] Windows Support
|
||||
|
||||
---
|
||||
.../llvm/Support/Windows/WindowsSupport.h | 45 +++++----
|
||||
@@ -1,7 +1,7 @@
|
||||
From c67b1c2baf278050fb43bee7a7241392d64fbb0d Mon Sep 17 00:00:00 2001
|
||||
From 2a480ee8e89b322b91f596a5a9d63aa6b9a76af0 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:46:20 -0400
|
||||
Subject: [PATCH 24/31] Prefer fmtlib
|
||||
Subject: [PATCH 20/27] Prefer fmtlib
|
||||
|
||||
---
|
||||
llvm/lib/Support/ErrorHandling.cpp | 20 ++++++--------------
|
||||
@@ -1,7 +1,7 @@
|
||||
From 07ffe44dd483a6fd847030ca9b76a225d5b7b2de Mon Sep 17 00:00:00 2001
|
||||
From c7a7fd016ae0636dcadc65705a9260f02c509495 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:49:36 -0400
|
||||
Subject: [PATCH 25/31] prefer wpi's fs.h
|
||||
Subject: [PATCH 21/27] prefer wpi's fs.h
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/raw_ostream.h | 7 ++-----
|
||||
@@ -1,15 +1,30 @@
|
||||
From 7bac24e5310d67d6828b687aec2043966a955093 Mon Sep 17 00:00:00 2001
|
||||
From 8536e1f23d515eac3cbc0680f27aa6ab740b4796 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 19:16:51 -0400
|
||||
Subject: [PATCH 26/31] Remove unused functions
|
||||
Subject: [PATCH 22/27] Remove unused functions
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/DJB.h | 3 -
|
||||
llvm/include/llvm/Support/raw_ostream.h | 3 +-
|
||||
llvm/lib/Support/ErrorHandling.cpp | 16 -----
|
||||
llvm/lib/Support/raw_ostream.cpp | 48 +++++++--------
|
||||
llvm/unittests/ADT/SmallStringTest.cpp | 81 -------------------------
|
||||
4 files changed, 22 insertions(+), 126 deletions(-)
|
||||
5 files changed, 22 insertions(+), 129 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/DJB.h b/llvm/include/llvm/Support/DJB.h
|
||||
index 8737cd144c37..67b0ae91b4b1 100644
|
||||
--- a/llvm/include/llvm/Support/DJB.h
|
||||
+++ b/llvm/include/llvm/Support/DJB.h
|
||||
@@ -24,9 +24,6 @@ inline uint32_t djbHash(std::string_view Buffer, uint32_t H = 5381) {
|
||||
return H;
|
||||
}
|
||||
|
||||
-/// Computes the Bernstein hash after folding the input according to the Dwarf 5
|
||||
-/// standard case folding rules.
|
||||
-uint32_t caseFoldingDjbHash(StringRef Buffer, uint32_t H = 5381);
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_SUPPORT_DJB_H
|
||||
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
|
||||
index 27fb5c03e474..d228b05f4f9b 100644
|
||||
--- a/llvm/include/llvm/Support/raw_ostream.h
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0e20a9a457bbcef8bd07a0c06fceb9641fba0ad2 Mon Sep 17 00:00:00 2001
|
||||
From 333f987aa17d7138af8bf6e41d5749041793a721 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Mon, 9 May 2022 00:18:29 -0400
|
||||
Subject: [PATCH 27/31] Add convienence feature to SmallString
|
||||
Subject: [PATCH 23/27] Add convienence feature to SmallString
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallString.h | 8 +++++---
|
||||
@@ -1,7 +1,7 @@
|
||||
From 96ace137b394c0af8b3f1d9f3862cdf171adcfa4 Mon Sep 17 00:00:00 2001
|
||||
From 9d6e5efbd4b77747387b35a45d0c591126f7c08c Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 19:30:43 -0400
|
||||
Subject: [PATCH 28/31] OS specific changes
|
||||
Subject: [PATCH 24/27] OS specific changes
|
||||
|
||||
---
|
||||
llvm/lib/Support/ErrorHandling.cpp | 13 +++++++------
|
||||
@@ -1,7 +1,7 @@
|
||||
From 6ec969e4a7a0bcbb3b54a48dc2bff84e1b431632 Mon Sep 17 00:00:00 2001
|
||||
From fa16120af5f965c13bd7b75a2e591cd250fad5fa Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Mon, 9 May 2022 00:04:30 -0400
|
||||
Subject: [PATCH 29/31] Use smallvector for UTF conversion
|
||||
Subject: [PATCH 25/27] Use smallvector for UTF conversion
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/ConvertUTF.h | 6 +++---
|
||||
@@ -1,7 +1,7 @@
|
||||
From 6f0f7e6e4256d642673e3441468f44f6bd94fe12 Mon Sep 17 00:00:00 2001
|
||||
From 7bdbcabd3271aebb692ef06a950d1ec59341ddf9 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 19 May 2022 00:58:36 -0400
|
||||
Subject: [PATCH 30/31] Prefer to use static pointers in raw_ostream
|
||||
Subject: [PATCH 26/27] Prefer to use static pointers in raw_ostream
|
||||
|
||||
See #1401
|
||||
---
|
||||
@@ -1,7 +1,7 @@
|
||||
From 63e46567fe7f9d3e48beaca7827125bfe06e1004 Mon Sep 17 00:00:00 2001
|
||||
From 34652f999acd319bb507ca4d504050ec90981e18 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 19 May 2022 01:12:41 -0400
|
||||
Subject: [PATCH 31/31] constexpr endian byte swap
|
||||
Subject: [PATCH 27/27] constexpr endian byte swap
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/Endian.h | 4 +++-
|
||||
@@ -54,8 +54,6 @@ def run_global_replacements(wpiutil_llvm_files):
|
||||
# Replace wpi/FileSystem.h with wpi/fs.h
|
||||
content = content.replace("include \"wpi/FileSystem.h\"",
|
||||
"include \"wpi/fs.h\"")
|
||||
content = content.replace("#include \"wpi/ReverseIteration.h\"",
|
||||
"#include \"wpi/PointerLikeTypeTraits.h\"")
|
||||
|
||||
# Replace llvm_unreachable() with wpi_unreachable()
|
||||
content = content.replace("llvm_unreachable", "wpi_unreachable")
|
||||
@@ -163,32 +161,28 @@ def main():
|
||||
os.path.join(patch_root, "0003-Wrap-std-min-max-calls-in-parens-for-windows-warning.patch"),
|
||||
os.path.join(patch_root, "0004-Change-uniqe_function-storage-size.patch"),
|
||||
os.path.join(patch_root, "0005-Threading-updates.patch"),
|
||||
os.path.join(patch_root, "0006-Remove-DJB-hash-dependency.patch"),
|
||||
os.path.join(patch_root, "0007-ifdef-guard-safety.patch"),
|
||||
os.path.join(patch_root, "0008-Explicitly-use-std.patch"),
|
||||
os.path.join(patch_root, "0009-Remove-format_provider.patch"),
|
||||
os.path.join(patch_root, "0010-Remove-reverse-iterator.patch"),
|
||||
os.path.join(patch_root, "0011-Remove-allocator-from-collections.patch"),
|
||||
os.path.join(patch_root, "0012-Remove-EpochTracker.patch"),
|
||||
os.path.join(patch_root, "0013-Add-compiler-warning-pragrams.patch"),
|
||||
os.path.join(patch_root, "0014-Remove-unused-functions.patch"),
|
||||
os.path.join(patch_root, "0015-Detemplatize-small-vector-base.patch"),
|
||||
os.path.join(patch_root, "0016-Add-vectors-to-raw_ostream.patch"),
|
||||
os.path.join(patch_root, "0017-Extra-collections-features.patch"),
|
||||
os.path.join(patch_root, "0018-EpochTracker-abi-macro.patch"),
|
||||
os.path.join(patch_root, "0019-Delete-numbers-from-mathextras.patch"),
|
||||
os.path.join(patch_root, "0020-Add-lerp-and-sgn.patch"),
|
||||
os.path.join(patch_root, "0021-Fixup-includes.patch"),
|
||||
os.path.join(patch_root, "0022-use-std-is_trivially_copy_constructible.patch"),
|
||||
os.path.join(patch_root, "0023-Windows-Support.patch"),
|
||||
os.path.join(patch_root, "0024-Prefer-fmtlib.patch"),
|
||||
os.path.join(patch_root, "0025-prefer-wpi-s-fs.h.patch"),
|
||||
os.path.join(patch_root, "0026-Remove-unused-functions.patch"),
|
||||
os.path.join(patch_root, "0027-Add-convienence-feature-to-SmallString.patch"),
|
||||
os.path.join(patch_root, "0028-OS-specific-changes.patch"),
|
||||
os.path.join(patch_root, "0029-Use-smallvector-for-UTF-conversion.patch"),
|
||||
os.path.join(patch_root, "0030-Prefer-to-use-static-pointers-in-raw_ostream.patch"),
|
||||
os.path.join(patch_root, "0031-constexpr-endian-byte-swap.patch"),
|
||||
os.path.join(patch_root, "0006-ifdef-guard-safety.patch"),
|
||||
os.path.join(patch_root, "0007-Explicitly-use-std.patch"),
|
||||
os.path.join(patch_root, "0008-Remove-format_provider.patch"),
|
||||
os.path.join(patch_root, "0009-Add-compiler-warning-pragrams.patch"),
|
||||
os.path.join(patch_root, "0010-Remove-unused-functions.patch"),
|
||||
os.path.join(patch_root, "0011-Detemplatize-small-vector-base.patch"),
|
||||
os.path.join(patch_root, "0012-Add-vectors-to-raw_ostream.patch"),
|
||||
os.path.join(patch_root, "0013-Extra-collections-features.patch"),
|
||||
os.path.join(patch_root, "0014-EpochTracker-abi-macro.patch"),
|
||||
os.path.join(patch_root, "0015-Delete-numbers-from-mathextras.patch"),
|
||||
os.path.join(patch_root, "0016-Add-lerp-and-sgn.patch"),
|
||||
os.path.join(patch_root, "0017-Fixup-includes.patch"),
|
||||
os.path.join(patch_root, "0018-use-std-is_trivially_copy_constructible.patch"),
|
||||
os.path.join(patch_root, "0019-Windows-Support.patch"),
|
||||
os.path.join(patch_root, "0020-Prefer-fmtlib.patch"),
|
||||
os.path.join(patch_root, "0021-prefer-wpi-s-fs.h.patch"),
|
||||
os.path.join(patch_root, "0022-Remove-unused-functions.patch"),
|
||||
os.path.join(patch_root, "0023-Add-convienence-feature-to-SmallString.patch"),
|
||||
os.path.join(patch_root, "0024-OS-specific-changes.patch"),
|
||||
os.path.join(patch_root, "0025-Use-smallvector-for-UTF-conversion.patch"),
|
||||
os.path.join(patch_root, "0026-Prefer-to-use-static-pointers-in-raw_ostream.patch"),
|
||||
os.path.join(patch_root, "0027-constexpr-endian-byte-swap.patch"),
|
||||
|
||||
]
|
||||
# yapf: enable
|
||||
|
||||
@@ -13,6 +13,7 @@ cppSrcFileInclude {
|
||||
generatedFileExclude {
|
||||
src/main/native/cpp/llvm/
|
||||
src/main/native/include/llvm/
|
||||
src/main/native/include/wpi/AllocatorBase\.h$
|
||||
src/main/native/include/wpi/AlignOf\.h$
|
||||
src/main/native/include/wpi/ArrayRef\.h$
|
||||
src/main/native/include/wpi/Chrono\.h$
|
||||
@@ -20,6 +21,7 @@ generatedFileExclude {
|
||||
src/main/native/include/wpi/ConvertUTF\.h$
|
||||
src/main/native/include/wpi/DenseMap\.h$
|
||||
src/main/native/include/wpi/DenseMapInfo\.h$
|
||||
src/main/native/include/wpi/DJB\.h$
|
||||
src/main/native/include/wpi/EpochTracker\.h$
|
||||
src/main/native/include/wpi/Endian\.h$
|
||||
src/main/native/include/wpi/Errc\.h$
|
||||
@@ -41,6 +43,7 @@ generatedFileExclude {
|
||||
src/main/native/include/wpi/PointerIntPair\.h$
|
||||
src/main/native/include/wpi/PointerLikeTypeTraits\.h$
|
||||
src/main/native/include/wpi/PointerUnion\.h$
|
||||
src/main/native/include/wpi/ReverseIteration\.h$
|
||||
src/main/native/include/wpi/STLExtras\.h$
|
||||
src/main/native/include/wpi/Signal\.h$
|
||||
src/main/native/include/wpi/SmallPtrSet\.h$
|
||||
|
||||
@@ -59,6 +59,7 @@ SmallPtrSetImplBase::insert_imp_big(const void *Ptr) {
|
||||
else
|
||||
++NumNonEmpty; // Track density.
|
||||
*Bucket = Ptr;
|
||||
incrementEpoch();
|
||||
return std::make_pair(Bucket, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,26 +12,11 @@
|
||||
|
||||
#include "wpi/StringMap.h"
|
||||
#include "wpi/StringExtras.h"
|
||||
#include "wpi/Compiler.h"
|
||||
#include "wpi/DJB.h"
|
||||
#include "wpi/MathExtras.h"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
/// HashString - Hash function for strings.
|
||||
///
|
||||
/// This is the Bernstein hash function.
|
||||
//
|
||||
// FIXME: Investigate whether a modified bernstein hash function performs
|
||||
// better: http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
|
||||
// X*33+c -> X*33^c
|
||||
static inline unsigned HashString(std::string_view str,
|
||||
unsigned result = 0) noexcept {
|
||||
for (std::string_view::size_type i = 0, e = str.size(); i != e; ++i) {
|
||||
result = result * 33 + static_cast<unsigned char>(str[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns the number of buckets to allocate to ensure that the DenseMap can
|
||||
/// accommodate \p NumEntries without need to grow().
|
||||
static unsigned getMinBucketToReserveForEntries(unsigned NumEntries) {
|
||||
@@ -92,7 +77,7 @@ unsigned StringMapImpl::LookupBucketFor(std::string_view Name) {
|
||||
init(16);
|
||||
HTSize = NumBuckets;
|
||||
}
|
||||
unsigned FullHashValue = HashString(Name);
|
||||
unsigned FullHashValue = djbHash(Name, 0);
|
||||
unsigned BucketNo = FullHashValue & (HTSize - 1);
|
||||
unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1);
|
||||
|
||||
@@ -148,7 +133,7 @@ int StringMapImpl::FindKey(std::string_view Key) const {
|
||||
unsigned HTSize = NumBuckets;
|
||||
if (HTSize == 0)
|
||||
return -1; // Really empty table?
|
||||
unsigned FullHashValue = HashString(Key);
|
||||
unsigned FullHashValue = djbHash(Key, 0);
|
||||
unsigned BucketNo = FullHashValue & (HTSize - 1);
|
||||
unsigned *HashTable = (unsigned *)(TheTable + NumBuckets + 1);
|
||||
|
||||
|
||||
103
wpiutil/src/main/native/include/wpi/AllocatorBase.h
Normal file
103
wpiutil/src/main/native/include/wpi/AllocatorBase.h
Normal file
@@ -0,0 +1,103 @@
|
||||
//===- AllocatorBase.h - Simple memory allocation abstraction ---*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// \file
|
||||
///
|
||||
/// This file defines MallocAllocator. MallocAllocator conforms to the LLVM
|
||||
/// "Allocator" concept which consists of an Allocate method accepting a size
|
||||
/// and alignment, and a Deallocate accepting a pointer and size. Further, the
|
||||
/// LLVM "Allocator" concept has overloads of Allocate and Deallocate for
|
||||
/// setting size and alignment based on the final type. These overloads are
|
||||
/// typically provided by a base class template \c AllocatorBase.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef WPIUTIL_WPI_ALLOCATORBASE_H
|
||||
#define WPIUTIL_WPI_ALLOCATORBASE_H
|
||||
|
||||
#include "wpi/Compiler.h"
|
||||
#include "wpi/MemAlloc.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
/// CRTP base class providing obvious overloads for the core \c
|
||||
/// Allocate() methods of LLVM-style allocators.
|
||||
///
|
||||
/// This base class both documents the full public interface exposed by all
|
||||
/// LLVM-style allocators, and redirects all of the overloads to a single core
|
||||
/// set of methods which the derived class must define.
|
||||
template <typename DerivedT> class AllocatorBase {
|
||||
public:
|
||||
/// Allocate \a Size bytes of \a Alignment aligned memory. This method
|
||||
/// must be implemented by \c DerivedT.
|
||||
void *Allocate(size_t Size, size_t Alignment) {
|
||||
#ifdef __clang__
|
||||
static_assert(static_cast<void *(AllocatorBase::*)(size_t, size_t)>(
|
||||
&AllocatorBase::Allocate) !=
|
||||
static_cast<void *(DerivedT::*)(size_t, size_t)>(
|
||||
&DerivedT::Allocate),
|
||||
"Class derives from AllocatorBase without implementing the "
|
||||
"core Allocate(size_t, size_t) overload!");
|
||||
#endif
|
||||
return static_cast<DerivedT *>(this)->Allocate(Size, Alignment);
|
||||
}
|
||||
|
||||
/// Deallocate \a Ptr to \a Size bytes of memory allocated by this
|
||||
/// allocator.
|
||||
void Deallocate(const void *Ptr, size_t Size, size_t Alignment) {
|
||||
#ifdef __clang__
|
||||
static_assert(
|
||||
static_cast<void (AllocatorBase::*)(const void *, size_t, size_t)>(
|
||||
&AllocatorBase::Deallocate) !=
|
||||
static_cast<void (DerivedT::*)(const void *, size_t, size_t)>(
|
||||
&DerivedT::Deallocate),
|
||||
"Class derives from AllocatorBase without implementing the "
|
||||
"core Deallocate(void *) overload!");
|
||||
#endif
|
||||
return static_cast<DerivedT *>(this)->Deallocate(Ptr, Size, Alignment);
|
||||
}
|
||||
|
||||
// The rest of these methods are helpers that redirect to one of the above
|
||||
// core methods.
|
||||
|
||||
/// Allocate space for a sequence of objects without constructing them.
|
||||
template <typename T> T *Allocate(size_t Num = 1) {
|
||||
return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T)));
|
||||
}
|
||||
|
||||
/// Deallocate space for a sequence of objects without constructing them.
|
||||
template <typename T>
|
||||
std::enable_if_t<!std::is_same<std::remove_cv_t<T>, void>::value, void>
|
||||
Deallocate(T *Ptr, size_t Num = 1) {
|
||||
Deallocate(static_cast<const void *>(Ptr), Num * sizeof(T), alignof(T));
|
||||
}
|
||||
};
|
||||
|
||||
class MallocAllocator : public AllocatorBase<MallocAllocator> {
|
||||
public:
|
||||
void Reset() {}
|
||||
|
||||
LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, size_t Alignment) {
|
||||
return allocate_buffer(Size, Alignment);
|
||||
}
|
||||
|
||||
// Pull in base class overloads.
|
||||
using AllocatorBase<MallocAllocator>::Allocate;
|
||||
|
||||
void Deallocate(const void *Ptr, size_t Size, size_t Alignment) {
|
||||
deallocate_buffer(const_cast<void *>(Ptr), Size, Alignment);
|
||||
}
|
||||
|
||||
// Pull in base class overloads.
|
||||
using AllocatorBase<MallocAllocator>::Deallocate;
|
||||
|
||||
void PrintStats() const {}
|
||||
};
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
#endif // WPIUTIL_WPI_ALLOCATORBASE_H
|
||||
29
wpiutil/src/main/native/include/wpi/DJB.h
Normal file
29
wpiutil/src/main/native/include/wpi/DJB.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//===-- llvm/Support/DJB.h ---DJB Hash --------------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contains support for the DJ Bernstein hash function.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef WPIUTIL_WPI_DJB_H
|
||||
#define WPIUTIL_WPI_DJB_H
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace wpi {
|
||||
|
||||
/// The Bernstein hash function used by the DWARF accelerator tables.
|
||||
inline uint32_t djbHash(std::string_view Buffer, uint32_t H = 5381) {
|
||||
for (unsigned char C : Buffer)
|
||||
H = (H << 5) + H + C;
|
||||
return H;
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
#endif // WPIUTIL_WPI_DJB_H
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "wpi/Compiler.h"
|
||||
#include "wpi/MathExtras.h"
|
||||
#include "wpi/MemAlloc.h"
|
||||
#include "wpi/PointerLikeTypeTraits.h"
|
||||
#include "wpi/ReverseIteration.h"
|
||||
#include "wpi/type_traits.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
@@ -76,6 +76,8 @@ public:
|
||||
// empty buckets.
|
||||
if (empty())
|
||||
return end();
|
||||
if (shouldReverseIterate<KeyT>())
|
||||
return makeIterator(getBucketsEnd() - 1, getBuckets(), *this);
|
||||
return makeIterator(getBuckets(), getBucketsEnd(), *this);
|
||||
}
|
||||
inline iterator end() {
|
||||
@@ -84,6 +86,8 @@ public:
|
||||
inline const_iterator begin() const {
|
||||
if (empty())
|
||||
return end();
|
||||
if (shouldReverseIterate<KeyT>())
|
||||
return makeConstIterator(getBucketsEnd() - 1, getBuckets(), *this);
|
||||
return makeConstIterator(getBuckets(), getBucketsEnd(), *this);
|
||||
}
|
||||
inline const_iterator end() const {
|
||||
@@ -146,14 +150,18 @@ public:
|
||||
iterator find(const_arg_type_t<KeyT> Val) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
return makeIterator(TheBucket, getBucketsEnd(),
|
||||
return makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
const_iterator find(const_arg_type_t<KeyT> Val) const {
|
||||
const BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
return makeConstIterator(TheBucket, getBucketsEnd(),
|
||||
return makeConstIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
@@ -167,7 +175,9 @@ public:
|
||||
iterator find_as(const LookupKeyT &Val) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
return makeIterator(TheBucket, getBucketsEnd(),
|
||||
return makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
@@ -175,7 +185,9 @@ public:
|
||||
const_iterator find_as(const LookupKeyT &Val) const {
|
||||
const BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
return makeConstIterator(TheBucket, getBucketsEnd(),
|
||||
return makeConstIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>() ? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true);
|
||||
return end();
|
||||
}
|
||||
@@ -210,14 +222,20 @@ public:
|
||||
std::pair<iterator, bool> try_emplace(KeyT &&Key, Ts &&... Args) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Key, TheBucket))
|
||||
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
return std::make_pair(makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>()
|
||||
? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true),
|
||||
false); // Already in map.
|
||||
|
||||
// Otherwise, insert the new element.
|
||||
TheBucket =
|
||||
InsertIntoBucket(TheBucket, std::move(Key), std::forward<Ts>(Args)...);
|
||||
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
return std::make_pair(makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>()
|
||||
? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true),
|
||||
true);
|
||||
}
|
||||
@@ -229,13 +247,19 @@ public:
|
||||
std::pair<iterator, bool> try_emplace(const KeyT &Key, Ts &&... Args) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Key, TheBucket))
|
||||
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
return std::make_pair(makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>()
|
||||
? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true),
|
||||
false); // Already in map.
|
||||
|
||||
// Otherwise, insert the new element.
|
||||
TheBucket = InsertIntoBucket(TheBucket, Key, std::forward<Ts>(Args)...);
|
||||
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
return std::make_pair(makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>()
|
||||
? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true),
|
||||
true);
|
||||
}
|
||||
@@ -250,14 +274,20 @@ public:
|
||||
const LookupKeyT &Val) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
return std::make_pair(makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>()
|
||||
? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true),
|
||||
false); // Already in map.
|
||||
|
||||
// Otherwise, insert the new element.
|
||||
TheBucket = InsertIntoBucketWithLookup(TheBucket, std::move(KV.first),
|
||||
std::move(KV.second), Val);
|
||||
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(),
|
||||
return std::make_pair(makeIterator(TheBucket,
|
||||
shouldReverseIterate<KeyT>()
|
||||
? getBuckets()
|
||||
: getBucketsEnd(),
|
||||
*this, true),
|
||||
true);
|
||||
}
|
||||
@@ -434,12 +464,20 @@ private:
|
||||
iterator makeIterator(BucketT *P, BucketT *E,
|
||||
DebugEpochBase &Epoch,
|
||||
bool NoAdvance=false) {
|
||||
if (shouldReverseIterate<KeyT>()) {
|
||||
BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
|
||||
return iterator(B, E, Epoch, NoAdvance);
|
||||
}
|
||||
return iterator(P, E, Epoch, NoAdvance);
|
||||
}
|
||||
|
||||
const_iterator makeConstIterator(const BucketT *P, const BucketT *E,
|
||||
const DebugEpochBase &Epoch,
|
||||
const bool NoAdvance=false) const {
|
||||
if (shouldReverseIterate<KeyT>()) {
|
||||
const BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
|
||||
return const_iterator(B, E, Epoch, NoAdvance);
|
||||
}
|
||||
return const_iterator(P, E, Epoch, NoAdvance);
|
||||
}
|
||||
|
||||
@@ -1176,6 +1214,10 @@ public:
|
||||
assert(isHandleInSync() && "invalid construction!");
|
||||
|
||||
if (NoAdvance) return;
|
||||
if (shouldReverseIterate<KeyT>()) {
|
||||
RetreatPastEmptyBuckets();
|
||||
return;
|
||||
}
|
||||
AdvancePastEmptyBuckets();
|
||||
}
|
||||
|
||||
@@ -1190,10 +1232,16 @@ public:
|
||||
|
||||
reference operator*() const {
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
assert(Ptr != End && "dereferencing end() iterator");
|
||||
if (shouldReverseIterate<KeyT>())
|
||||
return Ptr[-1];
|
||||
return *Ptr;
|
||||
}
|
||||
pointer operator->() const {
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
assert(Ptr != End && "dereferencing end() iterator");
|
||||
if (shouldReverseIterate<KeyT>())
|
||||
return &(Ptr[-1]);
|
||||
return Ptr;
|
||||
}
|
||||
|
||||
@@ -1213,6 +1261,12 @@ public:
|
||||
|
||||
inline DenseMapIterator& operator++() { // Preincrement
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
assert(Ptr != End && "incrementing end() iterator");
|
||||
if (shouldReverseIterate<KeyT>()) {
|
||||
--Ptr;
|
||||
RetreatPastEmptyBuckets();
|
||||
return *this;
|
||||
}
|
||||
++Ptr;
|
||||
AdvancePastEmptyBuckets();
|
||||
return *this;
|
||||
|
||||
15
wpiutil/src/main/native/include/wpi/ReverseIteration.h
Normal file
15
wpiutil/src/main/native/include/wpi/ReverseIteration.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef WPI_REVERSEITERATION_H
|
||||
#define WPI_REVERSEITERATION_H
|
||||
|
||||
#include "wpi/PointerLikeTypeTraits.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
template<class T = void *>
|
||||
constexpr bool shouldReverseIterate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -14,8 +14,9 @@
|
||||
#ifndef WPIUTIL_WPI_SMALLPTRSET_H
|
||||
#define WPIUTIL_WPI_SMALLPTRSET_H
|
||||
|
||||
#include "wpi/EpochTracker.h"
|
||||
#include "wpi/Compiler.h"
|
||||
#include "wpi/PointerLikeTypeTraits.h"
|
||||
#include "wpi/ReverseIteration.h"
|
||||
#include "wpi/type_traits.h"
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
@@ -45,7 +46,7 @@ namespace wpi {
|
||||
/// (-2), to allow deletion. The hash table is resized when the table is 3/4 or
|
||||
/// more. When this happens, the table is doubled in size.
|
||||
///
|
||||
class SmallPtrSetImplBase {
|
||||
class SmallPtrSetImplBase : public DebugEpochBase {
|
||||
friend class SmallPtrSetIteratorImpl;
|
||||
|
||||
protected:
|
||||
@@ -91,6 +92,7 @@ public:
|
||||
size_type size() const { return NumNonEmpty - NumTombstones; }
|
||||
|
||||
void clear() {
|
||||
incrementEpoch();
|
||||
// If the capacity of the array is huge, and the # elements used is small,
|
||||
// shrink the array.
|
||||
if (!isSmall()) {
|
||||
@@ -137,12 +139,14 @@ protected:
|
||||
if (LastTombstone != nullptr) {
|
||||
*LastTombstone = Ptr;
|
||||
--NumTombstones;
|
||||
incrementEpoch();
|
||||
return std::make_pair(LastTombstone, true);
|
||||
}
|
||||
|
||||
// Nope, there isn't. If we stay small, just 'pushback' now.
|
||||
if (NumNonEmpty < CurArraySize) {
|
||||
SmallArray[NumNonEmpty++] = Ptr;
|
||||
incrementEpoch();
|
||||
return std::make_pair(SmallArray + (NumNonEmpty - 1), true);
|
||||
}
|
||||
// Otherwise, hit the big set case, which will call grow.
|
||||
@@ -222,6 +226,10 @@ protected:
|
||||
public:
|
||||
explicit SmallPtrSetIteratorImpl(const void *const *BP, const void*const *E)
|
||||
: Bucket(BP), End(E) {
|
||||
if (shouldReverseIterate()) {
|
||||
RetreatIfNotValid();
|
||||
return;
|
||||
}
|
||||
AdvanceIfNotValid();
|
||||
}
|
||||
|
||||
@@ -255,7 +263,8 @@ protected:
|
||||
|
||||
/// SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
|
||||
template <typename PtrTy>
|
||||
class SmallPtrSetIterator : public SmallPtrSetIteratorImpl {
|
||||
class SmallPtrSetIterator : public SmallPtrSetIteratorImpl,
|
||||
DebugEpochBase::HandleBase {
|
||||
using PtrTraits = PointerLikeTypeTraits<PtrTy>;
|
||||
|
||||
public:
|
||||
@@ -265,17 +274,29 @@ public:
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
explicit SmallPtrSetIterator(const void *const *BP, const void *const *E)
|
||||
: SmallPtrSetIteratorImpl(BP, E) {}
|
||||
explicit SmallPtrSetIterator(const void *const *BP, const void *const *E,
|
||||
const DebugEpochBase &Epoch)
|
||||
: SmallPtrSetIteratorImpl(BP, E), DebugEpochBase::HandleBase(&Epoch) {}
|
||||
|
||||
// Most methods are provided by the base class.
|
||||
|
||||
const PtrTy operator*() const {
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
if (shouldReverseIterate()) {
|
||||
assert(Bucket > End);
|
||||
return PtrTraits::getFromVoidPointer(const_cast<void *>(Bucket[-1]));
|
||||
}
|
||||
assert(Bucket < End);
|
||||
return PtrTraits::getFromVoidPointer(const_cast<void*>(*Bucket));
|
||||
}
|
||||
|
||||
inline SmallPtrSetIterator& operator++() { // Preincrement
|
||||
assert(isHandleInSync() && "invalid iterator access!");
|
||||
if (shouldReverseIterate()) {
|
||||
--Bucket;
|
||||
RetreatIfNotValid();
|
||||
return *this;
|
||||
}
|
||||
++Bucket;
|
||||
AdvanceIfNotValid();
|
||||
return *this;
|
||||
@@ -379,6 +400,8 @@ public:
|
||||
}
|
||||
|
||||
iterator begin() const {
|
||||
if (shouldReverseIterate())
|
||||
return makeIterator(EndPointer() - 1);
|
||||
return makeIterator(CurArray);
|
||||
}
|
||||
iterator end() const { return makeIterator(EndPointer()); }
|
||||
@@ -386,7 +409,9 @@ public:
|
||||
private:
|
||||
/// Create an iterator that dereferences to same place as the given pointer.
|
||||
iterator makeIterator(const void *const *P) const {
|
||||
return iterator(P, EndPointer());
|
||||
if (shouldReverseIterate())
|
||||
return iterator(P == EndPointer() ? CurArray : P + 1, CurArray, *this);
|
||||
return iterator(P, EndPointer(), *this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define WPIUTIL_WPI_STRINGMAP_H
|
||||
|
||||
#include "wpi/StringMapEntry.h"
|
||||
#include "wpi/AllocatorBase.h"
|
||||
#include "wpi/MemAlloc.h"
|
||||
#include "wpi/SmallVector.h"
|
||||
#include "wpi/iterator.h"
|
||||
@@ -107,8 +108,10 @@ public:
|
||||
/// keys that are "strings", which are basically ranges of bytes. This does some
|
||||
/// funky memory allocation and hashing things to make it extremely efficient,
|
||||
/// storing the string data *after* the value in the map.
|
||||
template<typename ValueTy>
|
||||
template <typename ValueTy, typename AllocatorTy = MallocAllocator>
|
||||
class StringMap : public StringMapImpl {
|
||||
AllocatorTy Allocator;
|
||||
|
||||
public:
|
||||
using MapEntryTy = StringMapEntry<ValueTy>;
|
||||
|
||||
@@ -117,6 +120,14 @@ public:
|
||||
explicit StringMap(unsigned InitialSize)
|
||||
: StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {}
|
||||
|
||||
explicit StringMap(AllocatorTy A)
|
||||
: StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))), Allocator(A) {
|
||||
}
|
||||
|
||||
StringMap(unsigned InitialSize, AllocatorTy A)
|
||||
: StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))),
|
||||
Allocator(A) {}
|
||||
|
||||
StringMap(std::initializer_list<std::pair<std::string_view, ValueTy>> List)
|
||||
: StringMapImpl(List.size(), static_cast<unsigned>(sizeof(MapEntryTy))) {
|
||||
for (const auto &P : List) {
|
||||
@@ -125,10 +136,11 @@ public:
|
||||
}
|
||||
|
||||
StringMap(StringMap &&RHS)
|
||||
: StringMapImpl(std::move(RHS)) {}
|
||||
: StringMapImpl(std::move(RHS)), Allocator(std::move(RHS.Allocator)) {}
|
||||
|
||||
StringMap(const StringMap &RHS) :
|
||||
StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {
|
||||
StringMap(const StringMap &RHS)
|
||||
: StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))),
|
||||
Allocator(RHS.Allocator) {
|
||||
if (RHS.empty())
|
||||
return;
|
||||
|
||||
@@ -148,7 +160,7 @@ public:
|
||||
}
|
||||
|
||||
TheTable[I] = MapEntryTy::Create(
|
||||
static_cast<MapEntryTy *>(Bucket)->getKey(),
|
||||
static_cast<MapEntryTy *>(Bucket)->getKey(), Allocator,
|
||||
static_cast<MapEntryTy *>(Bucket)->getValue());
|
||||
HashTable[I] = RHSHashTable[I];
|
||||
}
|
||||
@@ -163,6 +175,7 @@ public:
|
||||
|
||||
StringMap &operator=(StringMap RHS) {
|
||||
StringMapImpl::swap(RHS);
|
||||
std::swap(Allocator, RHS.Allocator);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -174,13 +187,16 @@ public:
|
||||
for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
|
||||
StringMapEntryBase *Bucket = TheTable[I];
|
||||
if (Bucket && Bucket != getTombstoneVal()) {
|
||||
static_cast<MapEntryTy *>(Bucket)->Destroy();
|
||||
static_cast<MapEntryTy *>(Bucket)->Destroy(Allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(TheTable);
|
||||
}
|
||||
|
||||
AllocatorTy &getAllocator() { return Allocator; }
|
||||
const AllocatorTy &getAllocator() const { return Allocator; }
|
||||
|
||||
using key_type = const char *;
|
||||
using mapped_type = ValueTy;
|
||||
using value_type = StringMapEntry<ValueTy>;
|
||||
@@ -309,7 +325,7 @@ public:
|
||||
|
||||
if (Bucket == getTombstoneVal())
|
||||
--NumTombstones;
|
||||
Bucket = MapEntryTy::Create(Key, std::forward<ArgsTy>(Args)...);
|
||||
Bucket = MapEntryTy::Create(Key, Allocator, std::forward<ArgsTy>(Args)...);
|
||||
++NumItems;
|
||||
assert(NumItems + NumTombstones <= NumBuckets);
|
||||
|
||||
@@ -327,7 +343,7 @@ public:
|
||||
for (unsigned I = 0, E = NumBuckets; I != E; ++I) {
|
||||
StringMapEntryBase *&Bucket = TheTable[I];
|
||||
if (Bucket && Bucket != getTombstoneVal()) {
|
||||
static_cast<MapEntryTy *>(Bucket)->Destroy();
|
||||
static_cast<MapEntryTy *>(Bucket)->Destroy(Allocator);
|
||||
}
|
||||
Bucket = nullptr;
|
||||
}
|
||||
@@ -343,7 +359,7 @@ public:
|
||||
void erase(iterator I) {
|
||||
MapEntryTy &V = *I;
|
||||
remove(&V);
|
||||
V.Destroy();
|
||||
V.Destroy(Allocator);
|
||||
}
|
||||
|
||||
bool erase(std::string_view Key) {
|
||||
|
||||
@@ -37,14 +37,22 @@ protected:
|
||||
/// Helper to tail-allocate \p Key. It'd be nice to generalize this so it
|
||||
/// could be reused elsewhere, maybe even taking an wpi::function_ref to
|
||||
/// type-erase the allocator and put it in a source file.
|
||||
template <typename AllocatorTy>
|
||||
static void *allocateWithKey(size_t EntrySize, size_t EntryAlign,
|
||||
std::string_view Key) {
|
||||
std::string_view Key, AllocatorTy &Allocator);
|
||||
};
|
||||
|
||||
// Define out-of-line to dissuade inlining.
|
||||
template <typename AllocatorTy>
|
||||
void *StringMapEntryBase::allocateWithKey(size_t EntrySize, size_t EntryAlign,
|
||||
std::string_view Key,
|
||||
AllocatorTy &Allocator) {
|
||||
size_t KeyLength = Key.size();
|
||||
|
||||
// Allocate a new item with space for the string at the end and a null
|
||||
// terminator.
|
||||
size_t AllocSize = EntrySize + KeyLength + 1;
|
||||
void *Allocation = safe_malloc(AllocSize);
|
||||
void *Allocation = Allocator.Allocate(AllocSize, EntryAlign);
|
||||
assert(Allocation && "Unhandled out-of-memory");
|
||||
|
||||
// Copy the string information.
|
||||
@@ -54,7 +62,6 @@ protected:
|
||||
Buffer[KeyLength] = 0; // Null terminate for convenience of clients.
|
||||
return Allocation;
|
||||
}
|
||||
};
|
||||
|
||||
/// StringMapEntryStorage - Holds the value in a StringMapEntry.
|
||||
///
|
||||
@@ -114,11 +121,11 @@ public:
|
||||
|
||||
/// Create a StringMapEntry for the specified key construct the value using
|
||||
/// \p InitiVals.
|
||||
template <typename... InitTy>
|
||||
static StringMapEntry *Create(std::string_view key,
|
||||
template <typename AllocatorTy, typename... InitTy>
|
||||
static StringMapEntry *Create(std::string_view key, AllocatorTy &allocator,
|
||||
InitTy &&... initVals) {
|
||||
return new (StringMapEntryBase::allocateWithKey(
|
||||
sizeof(StringMapEntry), alignof(StringMapEntry), key))
|
||||
sizeof(StringMapEntry), alignof(StringMapEntry), key, allocator))
|
||||
StringMapEntry(key.size(), std::forward<InitTy>(initVals)...);
|
||||
}
|
||||
|
||||
@@ -131,10 +138,12 @@ public:
|
||||
|
||||
/// Destroy - Destroy this StringMapEntry, releasing memory back to the
|
||||
/// specified allocator.
|
||||
void Destroy() {
|
||||
template <typename AllocatorTy> void Destroy(AllocatorTy &allocator) {
|
||||
// Free memory referenced by the item.
|
||||
size_t AllocSize = sizeof(StringMapEntry) + this->getKeyLength() + 1;
|
||||
this->~StringMapEntry();
|
||||
std::free(static_cast<void *>(this));
|
||||
allocator.Deallocate(static_cast<void *>(this), AllocSize,
|
||||
alignof(StringMapEntry));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -223,12 +223,13 @@ TEST_F(StringMapTest, IterationTest) {
|
||||
|
||||
// Test StringMapEntry::Create() method.
|
||||
TEST_F(StringMapTest, StringMapEntryTest) {
|
||||
MallocAllocator Allocator;
|
||||
StringMap<uint32_t>::value_type *entry =
|
||||
StringMap<uint32_t>::value_type::Create(
|
||||
std::string_view(testKeyFirst, testKeyLength), 1u);
|
||||
std::string_view(testKeyFirst, testKeyLength), Allocator, 1u);
|
||||
EXPECT_STREQ(testKey, entry->first().data());
|
||||
EXPECT_EQ(1u, entry->second);
|
||||
entry->Destroy();
|
||||
entry->Destroy(Allocator);
|
||||
}
|
||||
|
||||
// Test insert() method.
|
||||
@@ -237,7 +238,7 @@ TEST_F(StringMapTest, InsertTest) {
|
||||
testMap.insert(
|
||||
StringMap<uint32_t>::value_type::Create(
|
||||
std::string_view(testKeyFirst, testKeyLength),
|
||||
1u));
|
||||
testMap.getAllocator(), 1u));
|
||||
assertSingleItemMap();
|
||||
}
|
||||
|
||||
@@ -352,14 +353,15 @@ TEST_F(StringMapTest, MoveOnly) {
|
||||
StringMap<MoveOnly> t;
|
||||
t.insert(std::make_pair("Test", MoveOnly(42)));
|
||||
std::string_view Key = "Test";
|
||||
StringMapEntry<MoveOnly>::Create(Key, MoveOnly(42))
|
||||
->Destroy();
|
||||
StringMapEntry<MoveOnly>::Create(Key, t.getAllocator(), MoveOnly(42))
|
||||
->Destroy(t.getAllocator());
|
||||
}
|
||||
|
||||
TEST_F(StringMapTest, CtorArg) {
|
||||
std::string_view Key = "Test";
|
||||
StringMapEntry<MoveOnly>::Create(Key, Immovable())
|
||||
->Destroy();
|
||||
MallocAllocator Allocator;
|
||||
StringMapEntry<MoveOnly>::Create(Key, Allocator, Immovable())
|
||||
->Destroy(Allocator);
|
||||
}
|
||||
|
||||
TEST_F(StringMapTest, MoveConstruct) {
|
||||
|
||||
Reference in New Issue
Block a user