mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Update to latest LLVM code (#88)
* Update to latest LLVM code. * Add LLVM's raw_ostream. * MathExtras.h: Include cmath for log2.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "llvm/AlignOf.h"
|
||||
#include "llvm/Compiler.h"
|
||||
#include "llvm/MathExtras.h"
|
||||
#include "llvm/PointerLikeTypeTraits.h"
|
||||
#include "llvm/type_traits.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
@@ -41,7 +42,7 @@ struct DenseMapPair : public std::pair<KeyT, ValueT> {
|
||||
ValueT &getSecond() { return std::pair<KeyT, ValueT>::second; }
|
||||
const ValueT &getSecond() const { return std::pair<KeyT, ValueT>::second; }
|
||||
};
|
||||
} // namespace detail
|
||||
}
|
||||
|
||||
template <
|
||||
typename KeyT, typename ValueT, typename KeyInfoT = DenseMapInfo<KeyT>,
|
||||
@@ -80,11 +81,13 @@ public:
|
||||
}
|
||||
unsigned size() const { return getNumEntries(); }
|
||||
|
||||
/// Grow the densemap so that it has at least Size buckets. Does not shrink
|
||||
void resize(size_type Size) {
|
||||
/// Grow the densemap so that it can contain at least \p NumEntries items
|
||||
/// before resizing again.
|
||||
void reserve(size_type NumEntries) {
|
||||
auto NumBuckets = getMinBucketToReserveForEntries(NumEntries);
|
||||
incrementEpoch();
|
||||
if (Size > getNumBuckets())
|
||||
grow(Size);
|
||||
if (NumBuckets > getNumBuckets())
|
||||
grow(NumBuckets);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
@@ -194,6 +197,26 @@ public:
|
||||
true);
|
||||
}
|
||||
|
||||
/// Alternate version of insert() which allows a different, and possibly
|
||||
/// less expensive, key type.
|
||||
/// The DenseMapInfo is responsible for supplying methods
|
||||
/// getHashValue(LookupKeyT) and isEqual(LookupKeyT, KeyT) for each key
|
||||
/// type used.
|
||||
template <typename LookupKeyT>
|
||||
std::pair<iterator, bool> insert_as(std::pair<KeyT, ValueT> &&KV,
|
||||
const LookupKeyT &Val) {
|
||||
BucketT *TheBucket;
|
||||
if (LookupBucketFor(Val, TheBucket))
|
||||
return std::make_pair(iterator(TheBucket, getBucketsEnd(), *this, true),
|
||||
false); // Already in map.
|
||||
|
||||
// Otherwise, insert the new element.
|
||||
TheBucket = InsertIntoBucket(std::move(KV.first), std::move(KV.second), Val,
|
||||
TheBucket);
|
||||
return std::make_pair(iterator(TheBucket, getBucketsEnd(), *this, true),
|
||||
true);
|
||||
}
|
||||
|
||||
/// insert - Range insertion of pairs.
|
||||
template<typename InputIt>
|
||||
void insert(InputIt I, InputIt E) {
|
||||
@@ -281,7 +304,18 @@ protected:
|
||||
"# initial buckets must be a power of two!");
|
||||
const KeyT EmptyKey = getEmptyKey();
|
||||
for (BucketT *B = getBuckets(), *E = getBucketsEnd(); B != E; ++B)
|
||||
new (&B->getFirst()) KeyT(EmptyKey);
|
||||
::new (&B->getFirst()) KeyT(EmptyKey);
|
||||
}
|
||||
|
||||
/// Returns the number of buckets to allocate to ensure that the DenseMap can
|
||||
/// accommodate \p NumEntries without need to grow().
|
||||
unsigned getMinBucketToReserveForEntries(unsigned NumEntries) {
|
||||
// Ensure that "NumEntries * 4 < NumBuckets * 3"
|
||||
if (NumEntries == 0)
|
||||
return 0;
|
||||
// +1 is required because of the strict equality.
|
||||
// For example if NumEntries is 48, we need to return 401.
|
||||
return NextPowerOf2(NumEntries * 4 / 3 + 1);
|
||||
}
|
||||
|
||||
void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) {
|
||||
@@ -299,7 +333,7 @@ protected:
|
||||
(void)FoundVal; // silence warning.
|
||||
assert(!FoundVal && "Key already in new map?");
|
||||
DestBucket->getFirst() = std::move(B->getFirst());
|
||||
new (&DestBucket->getSecond()) ValueT(std::move(B->getSecond()));
|
||||
::new (&DestBucket->getSecond()) ValueT(std::move(B->getSecond()));
|
||||
incrementNumEntries();
|
||||
|
||||
// Free the value.
|
||||
@@ -323,11 +357,11 @@ protected:
|
||||
getNumBuckets() * sizeof(BucketT));
|
||||
else
|
||||
for (size_t i = 0; i < getNumBuckets(); ++i) {
|
||||
new (&getBuckets()[i].getFirst())
|
||||
::new (&getBuckets()[i].getFirst())
|
||||
KeyT(other.getBuckets()[i].getFirst());
|
||||
if (!KeyInfoT::isEqual(getBuckets()[i].getFirst(), getEmptyKey()) &&
|
||||
!KeyInfoT::isEqual(getBuckets()[i].getFirst(), getTombstoneKey()))
|
||||
new (&getBuckets()[i].getSecond())
|
||||
::new (&getBuckets()[i].getSecond())
|
||||
ValueT(other.getBuckets()[i].getSecond());
|
||||
}
|
||||
}
|
||||
@@ -398,31 +432,43 @@ private:
|
||||
|
||||
BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value,
|
||||
BucketT *TheBucket) {
|
||||
TheBucket = InsertIntoBucketImpl(Key, TheBucket);
|
||||
TheBucket = InsertIntoBucketImpl(Key, Key, TheBucket);
|
||||
|
||||
TheBucket->getFirst() = Key;
|
||||
new (&TheBucket->getSecond()) ValueT(Value);
|
||||
::new (&TheBucket->getSecond()) ValueT(Value);
|
||||
return TheBucket;
|
||||
}
|
||||
|
||||
BucketT *InsertIntoBucket(const KeyT &Key, ValueT &&Value,
|
||||
BucketT *TheBucket) {
|
||||
TheBucket = InsertIntoBucketImpl(Key, TheBucket);
|
||||
TheBucket = InsertIntoBucketImpl(Key, Key, TheBucket);
|
||||
|
||||
TheBucket->getFirst() = Key;
|
||||
new (&TheBucket->getSecond()) ValueT(std::move(Value));
|
||||
::new (&TheBucket->getSecond()) ValueT(std::move(Value));
|
||||
return TheBucket;
|
||||
}
|
||||
|
||||
BucketT *InsertIntoBucket(KeyT &&Key, ValueT &&Value, BucketT *TheBucket) {
|
||||
TheBucket = InsertIntoBucketImpl(Key, TheBucket);
|
||||
TheBucket = InsertIntoBucketImpl(Key, Key, TheBucket);
|
||||
|
||||
TheBucket->getFirst() = std::move(Key);
|
||||
new (&TheBucket->getSecond()) ValueT(std::move(Value));
|
||||
::new (&TheBucket->getSecond()) ValueT(std::move(Value));
|
||||
return TheBucket;
|
||||
}
|
||||
|
||||
BucketT *InsertIntoBucketImpl(const KeyT &Key, BucketT *TheBucket) {
|
||||
template <typename LookupKeyT>
|
||||
BucketT *InsertIntoBucket(KeyT &&Key, ValueT &&Value, LookupKeyT &Lookup,
|
||||
BucketT *TheBucket) {
|
||||
TheBucket = InsertIntoBucketImpl(Key, Lookup, TheBucket);
|
||||
|
||||
TheBucket->getFirst() = std::move(Key);
|
||||
::new (&TheBucket->getSecond()) ValueT(std::move(Value));
|
||||
return TheBucket;
|
||||
}
|
||||
|
||||
template <typename LookupKeyT>
|
||||
BucketT *InsertIntoBucketImpl(const KeyT &Key, const LookupKeyT &Lookup,
|
||||
BucketT *TheBucket) {
|
||||
incrementEpoch();
|
||||
|
||||
// If the load of the hash table is more than 3/4, or if fewer than 1/8 of
|
||||
@@ -438,12 +484,12 @@ private:
|
||||
unsigned NumBuckets = getNumBuckets();
|
||||
if (LLVM_UNLIKELY(NewNumEntries * 4 >= NumBuckets * 3)) {
|
||||
this->grow(NumBuckets * 2);
|
||||
LookupBucketFor(Key, TheBucket);
|
||||
LookupBucketFor(Lookup, TheBucket);
|
||||
NumBuckets = getNumBuckets();
|
||||
} else if (LLVM_UNLIKELY(NumBuckets-(NewNumEntries+getNumTombstones()) <=
|
||||
NumBuckets/8)) {
|
||||
this->grow(NumBuckets);
|
||||
LookupBucketFor(Key, TheBucket);
|
||||
LookupBucketFor(Lookup, TheBucket);
|
||||
}
|
||||
assert(TheBucket);
|
||||
|
||||
@@ -549,9 +595,9 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
|
||||
unsigned NumBuckets;
|
||||
|
||||
public:
|
||||
explicit DenseMap(unsigned NumInitBuckets = 0) {
|
||||
init(NumInitBuckets);
|
||||
}
|
||||
/// Create a DenseMap wth an optional \p InitialReserve that guarantee that
|
||||
/// this number of elements can be inserted in the map without grow()
|
||||
explicit DenseMap(unsigned InitialReserve = 0) { init(InitialReserve); }
|
||||
|
||||
DenseMap(const DenseMap &other) : BaseT() {
|
||||
init(0);
|
||||
@@ -565,7 +611,7 @@ public:
|
||||
|
||||
template<typename InputIt>
|
||||
DenseMap(const InputIt &I, const InputIt &E) {
|
||||
init(NextPowerOf2(std::distance(I, E)));
|
||||
init(std::distance(I, E));
|
||||
this->insert(I, E);
|
||||
}
|
||||
|
||||
@@ -608,7 +654,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void init(unsigned InitBuckets) {
|
||||
void init(unsigned InitNumEntries) {
|
||||
auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
|
||||
if (allocateBuckets(InitBuckets)) {
|
||||
this->BaseT::initEmpty();
|
||||
} else {
|
||||
@@ -765,10 +812,10 @@ public:
|
||||
// Swap separately and handle any assymetry.
|
||||
std::swap(LHSB->getFirst(), RHSB->getFirst());
|
||||
if (hasLHSValue) {
|
||||
new (&RHSB->getSecond()) ValueT(std::move(LHSB->getSecond()));
|
||||
::new (&RHSB->getSecond()) ValueT(std::move(LHSB->getSecond()));
|
||||
LHSB->getSecond().~ValueT();
|
||||
} else if (hasRHSValue) {
|
||||
new (&LHSB->getSecond()) ValueT(std::move(RHSB->getSecond()));
|
||||
::new (&LHSB->getSecond()) ValueT(std::move(RHSB->getSecond()));
|
||||
RHSB->getSecond().~ValueT();
|
||||
}
|
||||
}
|
||||
@@ -794,11 +841,11 @@ public:
|
||||
for (unsigned i = 0, e = InlineBuckets; i != e; ++i) {
|
||||
BucketT *NewB = &LargeSide.getInlineBuckets()[i],
|
||||
*OldB = &SmallSide.getInlineBuckets()[i];
|
||||
new (&NewB->getFirst()) KeyT(std::move(OldB->getFirst()));
|
||||
::new (&NewB->getFirst()) KeyT(std::move(OldB->getFirst()));
|
||||
OldB->getFirst().~KeyT();
|
||||
if (!KeyInfoT::isEqual(NewB->getFirst(), EmptyKey) &&
|
||||
!KeyInfoT::isEqual(NewB->getFirst(), TombstoneKey)) {
|
||||
new (&NewB->getSecond()) ValueT(std::move(OldB->getSecond()));
|
||||
::new (&NewB->getSecond()) ValueT(std::move(OldB->getSecond()));
|
||||
OldB->getSecond().~ValueT();
|
||||
}
|
||||
}
|
||||
@@ -865,8 +912,8 @@ public:
|
||||
!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
|
||||
assert(size_t(TmpEnd - TmpBegin) < InlineBuckets &&
|
||||
"Too many inline buckets!");
|
||||
new (&TmpEnd->getFirst()) KeyT(std::move(P->getFirst()));
|
||||
new (&TmpEnd->getSecond()) ValueT(std::move(P->getSecond()));
|
||||
::new (&TmpEnd->getFirst()) KeyT(std::move(P->getFirst()));
|
||||
::new (&TmpEnd->getSecond()) ValueT(std::move(P->getSecond()));
|
||||
++TmpEnd;
|
||||
P->getSecond().~ValueT();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user