14#ifndef LLVM_ADT_DENSEMAP_H
15#define LLVM_ADT_DENSEMAP_H
29#include <initializer_list>
41template <
typename KeyT,
typename ValueT>
46 const KeyT &
getFirst()
const {
return std::pair<KeyT, ValueT>::first; }
54 typename KeyInfoT = DenseMapInfo<KeyT>,
57class DenseMapIterator;
59template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
80 if (shouldReverseIterate<KeyT>())
81 return makeIterator(getBucketsEnd() - 1, getBuckets(), *
this);
82 return makeIterator(getBuckets(), getBucketsEnd(), *
this);
85 return makeIterator(getBucketsEnd(), getBucketsEnd(), *
this,
true);
90 if (shouldReverseIterate<KeyT>())
91 return makeConstIterator(getBucketsEnd() - 1, getBuckets(), *
this);
92 return makeConstIterator(getBuckets(), getBucketsEnd(), *
this);
95 return makeConstIterator(getBucketsEnd(), getBucketsEnd(), *
this,
true);
98 [[nodiscard]]
bool empty()
const {
return getNumEntries() == 0; }
99 unsigned size()
const {
return getNumEntries(); }
106 if (NumBuckets > getNumBuckets())
112 if (getNumEntries() == 0 && getNumTombstones() == 0)
117 if (getNumEntries() * 4 < getNumBuckets() && getNumBuckets() > 64) {
123 if constexpr (std::is_trivially_destructible_v<ValueT>) {
125 for (BucketT *
P = getBuckets(), *
E = getBucketsEnd();
P !=
E; ++
P)
126 P->getFirst() = EmptyKey;
129 unsigned NumEntries = getNumEntries();
130 for (BucketT *
P = getBuckets(), *
E = getBucketsEnd();
P !=
E; ++
P) {
131 if (!KeyInfoT::isEqual(
P->getFirst(), EmptyKey)) {
132 if (!KeyInfoT::isEqual(
P->getFirst(), TombstoneKey)) {
133 P->getSecond().~ValueT();
136 P->getFirst() = EmptyKey;
139 assert(NumEntries == 0 &&
"Node count imbalance!");
148 return doFind(Val) !=
nullptr;
157 if (BucketT *Bucket = doFind(Val))
159 Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
164 if (
const BucketT *Bucket = doFind(Val))
165 return makeConstIterator(
166 Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
177 if (BucketT *Bucket = doFind(Val))
179 Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
183 template <
class LookupKeyT>
185 if (
const BucketT *Bucket = doFind(Val))
186 return makeConstIterator(
187 Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
195 if (
const BucketT *Bucket = doFind(Val))
196 return Bucket->getSecond();
202 const ValueT &
at(const_arg_type_t<KeyT> Val)
const {
203 auto Iter = this->
find(std::move(Val));
204 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
211 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
218 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
219 return try_emplace(std::move(KV.first), std::move(KV.second));
225 template <
typename... Ts>
228 if (LookupBucketFor(Key, TheBucket))
229 return std::make_pair(makeIterator(TheBucket,
230 shouldReverseIterate<KeyT>()
238 InsertIntoBucket(TheBucket, std::move(Key), std::forward<Ts>(Args)...);
239 return std::make_pair(makeIterator(TheBucket,
240 shouldReverseIterate<KeyT>()
250 template <
typename... Ts>
253 if (LookupBucketFor(Key, TheBucket))
254 return std::make_pair(makeIterator(TheBucket,
255 shouldReverseIterate<KeyT>()
262 TheBucket = InsertIntoBucket(TheBucket, Key, std::forward<Ts>(Args)...);
263 return std::make_pair(makeIterator(TheBucket,
264 shouldReverseIterate<KeyT>()
276 template <
typename LookupKeyT>
277 std::pair<iterator, bool>
insert_as(std::pair<KeyT, ValueT> &&KV,
278 const LookupKeyT &Val) {
280 if (LookupBucketFor(Val, TheBucket))
281 return std::make_pair(makeIterator(TheBucket,
282 shouldReverseIterate<KeyT>()
289 TheBucket = InsertIntoBucketWithLookup(TheBucket, std::move(KV.first),
290 std::move(KV.second), Val);
291 return std::make_pair(makeIterator(TheBucket,
292 shouldReverseIterate<KeyT>()
300 template <
typename InputIt>
void insert(InputIt
I, InputIt
E) {
305 template <
typename V>
309 Ret.first->second = std::forward<V>(Val);
313 template <
typename V>
315 auto Ret =
try_emplace(std::move(Key), std::forward<V>(Val));
317 Ret.first->second = std::forward<V>(Val);
322 BucketT *TheBucket = doFind(Val);
326 TheBucket->getSecond().~ValueT();
328 decrementNumEntries();
329 incrementNumTombstones();
333 BucketT *TheBucket = &*
I;
334 TheBucket->getSecond().~ValueT();
336 decrementNumEntries();
337 incrementNumTombstones();
342 if (LookupBucketFor(Key, TheBucket))
343 return TheBucket->second;
345 return InsertIntoBucket(TheBucket, Key)->second;
350 if (LookupBucketFor(Key, TheBucket))
351 return TheBucket->second;
353 return InsertIntoBucket(TheBucket, std::move(Key))->second;
360 return Ptr >= getBuckets() &&
Ptr < getBucketsEnd();
372 if (getNumBuckets() == 0)
376 for (BucketT *
P = getBuckets(), *
E = getBucketsEnd();
P !=
E; ++
P) {
377 if (!KeyInfoT::isEqual(
P->getFirst(), EmptyKey) &&
378 !KeyInfoT::isEqual(
P->getFirst(), TombstoneKey))
379 P->getSecond().~ValueT();
380 P->getFirst().~KeyT();
388 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
389 "# initial buckets must be a power of two!");
391 for (BucketT *
B = getBuckets(), *
E = getBucketsEnd();
B !=
E; ++
B)
392 ::new (&
B->getFirst())
KeyT(EmptyKey);
412 for (BucketT *
B = OldBucketsBegin, *
E = OldBucketsEnd;
B !=
E; ++
B) {
413 if (!KeyInfoT::isEqual(
B->getFirst(), EmptyKey) &&
414 !KeyInfoT::isEqual(
B->getFirst(), TombstoneKey)) {
417 bool FoundVal = LookupBucketFor(
B->getFirst(), DestBucket);
419 assert(!FoundVal &&
"Key already in new map?");
420 DestBucket->getFirst() = std::move(
B->getFirst());
421 ::new (&DestBucket->getSecond())
ValueT(std::move(
B->getSecond()));
422 incrementNumEntries();
425 B->getSecond().~ValueT();
427 B->getFirst().~KeyT();
431 template <
typename OtherBaseT>
435 assert(getNumBuckets() == other.getNumBuckets());
437 setNumEntries(other.getNumEntries());
438 setNumTombstones(other.getNumTombstones());
440 BucketT *Buckets = getBuckets();
441 const BucketT *OtherBuckets = other.getBuckets();
442 const size_t NumBuckets = getNumBuckets();
443 if constexpr (std::is_trivially_copyable_v<KeyT> &&
444 std::is_trivially_copyable_v<ValueT>) {
445 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
446 NumBuckets *
sizeof(BucketT));
450 for (
size_t I = 0;
I < NumBuckets; ++
I) {
451 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
452 if (!KeyInfoT::isEqual(Buckets[
I].getFirst(), EmptyKey) &&
453 !KeyInfoT::isEqual(Buckets[
I].getFirst(), TombstoneKey))
454 ::new (&Buckets[
I].getSecond())
ValueT(OtherBuckets[
I].getSecond());
460 return KeyInfoT::getHashValue(Val);
463 template <
typename LookupKeyT>
465 return KeyInfoT::getHashValue(Val);
469 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
470 "Must pass the derived type to this template!");
471 return KeyInfoT::getEmptyKey();
478 bool NoAdvance =
false) {
479 if (shouldReverseIterate<KeyT>()) {
480 BucketT *
B =
P == getBucketsEnd() ? getBuckets() :
P + 1;
487 const DebugEpochBase &Epoch,
488 const bool NoAdvance =
false)
const {
489 if (shouldReverseIterate<KeyT>()) {
490 const BucketT *
B =
P == getBucketsEnd() ? getBuckets() :
P + 1;
496 unsigned getNumEntries()
const {
497 return static_cast<const DerivedT *
>(
this)->getNumEntries();
500 void setNumEntries(
unsigned Num) {
501 static_cast<DerivedT *
>(
this)->setNumEntries(Num);
504 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
506 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
508 unsigned getNumTombstones()
const {
509 return static_cast<const DerivedT *
>(
this)->getNumTombstones();
512 void setNumTombstones(
unsigned Num) {
513 static_cast<DerivedT *
>(
this)->setNumTombstones(Num);
516 void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
518 void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
520 const BucketT *getBuckets()
const {
521 return static_cast<const DerivedT *
>(
this)->getBuckets();
524 BucketT *getBuckets() {
return static_cast<DerivedT *
>(
this)->getBuckets(); }
526 unsigned getNumBuckets()
const {
527 return static_cast<const DerivedT *
>(
this)->getNumBuckets();
530 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
532 const BucketT *getBucketsEnd()
const {
533 return getBuckets() + getNumBuckets();
536 void grow(
unsigned AtLeast) {
static_cast<DerivedT *
>(
this)->grow(AtLeast); }
538 void shrink_and_clear() {
static_cast<DerivedT *
>(
this)->shrink_and_clear(); }
540 template <
typename KeyArg,
typename... ValueArgs>
541 BucketT *InsertIntoBucket(BucketT *TheBucket, KeyArg &&Key,
542 ValueArgs &&...Values) {
543 TheBucket = InsertIntoBucketImpl(Key, TheBucket);
545 TheBucket->getFirst() = std::forward<KeyArg>(Key);
546 ::new (&TheBucket->getSecond())
ValueT(
std::forward<ValueArgs>(Values)...);
550 template <typename LookupKeyT>
551 BucketT *InsertIntoBucketWithLookup(BucketT *TheBucket,
KeyT &&Key,
553 TheBucket = InsertIntoBucketImpl(
Lookup, TheBucket);
555 TheBucket->getFirst() = std::move(Key);
560 template <typename LookupKeyT>
561 BucketT *InsertIntoBucketImpl(
const LookupKeyT &
Lookup, BucketT *TheBucket) {
573 unsigned NewNumEntries = getNumEntries() + 1;
574 unsigned NumBuckets = getNumBuckets();
576 this->grow(NumBuckets * 2);
577 LookupBucketFor(
Lookup, TheBucket);
578 NumBuckets = getNumBuckets();
580 (NewNumEntries + getNumTombstones()) <=
582 this->grow(NumBuckets);
583 LookupBucketFor(
Lookup, TheBucket);
589 incrementNumEntries();
593 if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
594 decrementNumTombstones();
599 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
600 BucketT *BucketsPtr = getBuckets();
601 const unsigned NumBuckets = getNumBuckets();
606 unsigned BucketNo =
getHashValue(Val) & (NumBuckets - 1);
607 unsigned ProbeAmt = 1;
609 BucketT *Bucket = BucketsPtr + BucketNo;
610 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
612 if (
LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
617 BucketNo += ProbeAmt++;
618 BucketNo &= NumBuckets - 1;
622 template <
typename LookupKeyT>
623 const BucketT *doFind(
const LookupKeyT &Val)
const {
631 template <
typename LookupKeyT>
632 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
633 BucketT *BucketsPtr = getBuckets();
634 const unsigned NumBuckets = getNumBuckets();
636 if (NumBuckets == 0) {
637 FoundBucket =
nullptr;
642 BucketT *FoundTombstone =
nullptr;
645 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
646 !KeyInfoT::isEqual(Val, TombstoneKey) &&
647 "Empty/Tombstone value shouldn't be inserted into map!");
649 unsigned BucketNo =
getHashValue(Val) & (NumBuckets - 1);
650 unsigned ProbeAmt = 1;
652 BucketT *ThisBucket = BucketsPtr + BucketNo;
654 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
655 FoundBucket = ThisBucket;
661 if (
LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
664 FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
670 if (KeyInfoT::isEqual(ThisBucket->getFirst(), TombstoneKey) &&
672 FoundTombstone = ThisBucket;
676 BucketNo += ProbeAmt++;
677 BucketNo &= (NumBuckets - 1);
695template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
700 if (
LHS.size() !=
RHS.size())
703 for (
auto &KV :
LHS) {
704 auto I =
RHS.find(KV.first);
705 if (
I ==
RHS.end() ||
I->second != KV.second)
715template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
724 typename KeyInfoT = DenseMapInfo<KeyT>,
727 KeyT, ValueT, KeyInfoT, BucketT> {
736 unsigned NumTombstones;
742 explicit DenseMap(
unsigned InitialReserve = 0) { init(InitialReserve); }
754 template <
typename InputIt>
DenseMap(
const InputIt &
I,
const InputIt &
E) {
755 init(std::distance(
I,
E));
759 DenseMap(std::initializer_list<typename BaseT::value_type> Vals) {
761 this->insert(Vals.begin(), Vals.end());
770 this->incrementEpoch();
771 RHS.incrementEpoch();
795 if (allocateBuckets(other.NumBuckets)) {
796 this->BaseT::copyFrom(other);
803 void init(
unsigned InitNumEntries) {
804 auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
805 if (allocateBuckets(InitBuckets)) {
806 this->BaseT::initEmpty();
814 unsigned OldNumBuckets = NumBuckets;
815 BucketT *OldBuckets = Buckets;
817 allocateBuckets(std::max<unsigned>(
821 this->BaseT::initEmpty();
825 this->moveFromOldBuckets(OldBuckets, OldBuckets + OldNumBuckets);
833 unsigned OldNumBuckets = NumBuckets;
834 unsigned OldNumEntries = NumEntries;
838 unsigned NewNumBuckets = 0;
840 NewNumBuckets = std::max(64, 1 << (
Log2_32_Ceil(OldNumEntries) + 1));
841 if (NewNumBuckets == NumBuckets) {
842 this->BaseT::initEmpty();
852 unsigned getNumEntries()
const {
return NumEntries; }
854 void setNumEntries(
unsigned Num) { NumEntries = Num; }
856 unsigned getNumTombstones()
const {
return NumTombstones; }
858 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
860 BucketT *getBuckets()
const {
return Buckets; }
862 unsigned getNumBuckets()
const {
return NumBuckets; }
864 bool allocateBuckets(
unsigned Num) {
866 if (NumBuckets == 0) {
871 Buckets =
static_cast<BucketT *
>(
877template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
878 typename KeyInfoT = DenseMapInfo<KeyT>,
882 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
883 ValueT, KeyInfoT, BucketT> {
891 "InlineBuckets must be a power of 2.");
894 unsigned NumEntries : 31;
895 unsigned NumTombstones;
908 if (NumInitBuckets > InlineBuckets)
910 init(NumInitBuckets);
923 template <
typename InputIt>
938 unsigned TmpNumEntries =
RHS.NumEntries;
939 RHS.NumEntries = NumEntries;
940 NumEntries = TmpNumEntries;
943 const KeyT EmptyKey = this->getEmptyKey();
944 const KeyT TombstoneKey = this->getTombstoneKey();
945 if (Small &&
RHS.Small) {
950 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
951 BucketT *LHSB = &getInlineBuckets()[i],
952 *RHSB = &
RHS.getInlineBuckets()[i];
953 bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey) &&
954 !KeyInfoT::isEqual(LHSB->getFirst(), TombstoneKey));
955 bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey) &&
956 !KeyInfoT::isEqual(RHSB->getFirst(), TombstoneKey));
957 if (hasLHSValue && hasRHSValue) {
963 std::swap(LHSB->getFirst(), RHSB->getFirst());
965 ::new (&RHSB->getSecond())
ValueT(std::move(LHSB->getSecond()));
966 LHSB->getSecond().~ValueT();
967 }
else if (hasRHSValue) {
968 ::new (&LHSB->getSecond())
ValueT(std::move(RHSB->getSecond()));
969 RHSB->getSecond().~ValueT();
974 if (!Small && !
RHS.Small) {
975 std::swap(getLargeRep()->Buckets,
RHS.getLargeRep()->Buckets);
976 std::swap(getLargeRep()->NumBuckets,
RHS.getLargeRep()->NumBuckets);
984 LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
985 LargeSide.getLargeRep()->~LargeRep();
986 LargeSide.Small =
true;
991 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
992 BucketT *NewB = &LargeSide.getInlineBuckets()[i],
993 *OldB = &SmallSide.getInlineBuckets()[i];
994 ::new (&NewB->getFirst())
KeyT(std::move(OldB->getFirst()));
995 OldB->getFirst().~KeyT();
996 if (!KeyInfoT::isEqual(NewB->getFirst(), EmptyKey) &&
997 !KeyInfoT::isEqual(NewB->getFirst(), TombstoneKey)) {
998 ::new (&NewB->getSecond())
ValueT(std::move(OldB->getSecond()));
999 OldB->getSecond().~ValueT();
1005 SmallSide.Small =
false;
1006 new (SmallSide.getLargeRep()) LargeRep(std::move(TmpRep));
1017 deallocateBuckets();
1025 deallocateBuckets();
1027 if (other.getNumBuckets() > InlineBuckets) {
1029 new (getLargeRep()) LargeRep(allocateBuckets(other.getNumBuckets()));
1031 this->BaseT::copyFrom(other);
1036 if (InitBuckets > InlineBuckets) {
1038 new (getLargeRep()) LargeRep(allocateBuckets(InitBuckets));
1040 this->BaseT::initEmpty();
1044 if (AtLeast > InlineBuckets)
1045 AtLeast = std::max<unsigned>(64,
NextPowerOf2(AtLeast - 1));
1050 BucketT *TmpBegin =
reinterpret_cast<BucketT *
>(&TmpStorage);
1051 BucketT *TmpEnd = TmpBegin;
1055 const KeyT EmptyKey = this->getEmptyKey();
1056 const KeyT TombstoneKey = this->getTombstoneKey();
1057 for (BucketT *
P = getBuckets(), *
E =
P + InlineBuckets;
P !=
E; ++
P) {
1058 if (!KeyInfoT::isEqual(
P->getFirst(), EmptyKey) &&
1059 !KeyInfoT::isEqual(
P->getFirst(), TombstoneKey)) {
1060 assert(
size_t(TmpEnd - TmpBegin) < InlineBuckets &&
1061 "Too many inline buckets!");
1062 ::new (&TmpEnd->getFirst())
KeyT(std::move(
P->getFirst()));
1063 ::new (&TmpEnd->getSecond())
ValueT(std::move(
P->getSecond()));
1065 P->getSecond().~ValueT();
1067 P->getFirst().~KeyT();
1073 if (AtLeast > InlineBuckets) {
1075 new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
1077 this->moveFromOldBuckets(TmpBegin, TmpEnd);
1081 LargeRep OldRep = std::move(*getLargeRep());
1082 getLargeRep()->~LargeRep();
1083 if (AtLeast <= InlineBuckets) {
1086 new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
1089 this->moveFromOldBuckets(OldRep.Buckets,
1090 OldRep.Buckets + OldRep.NumBuckets);
1098 unsigned OldSize = this->
size();
1102 unsigned NewNumBuckets = 0;
1105 if (NewNumBuckets > InlineBuckets && NewNumBuckets < 64u)
1108 if ((Small && NewNumBuckets <= InlineBuckets) ||
1109 (!Small && NewNumBuckets == getLargeRep()->NumBuckets)) {
1110 this->BaseT::initEmpty();
1114 deallocateBuckets();
1115 init(NewNumBuckets);
1119 unsigned getNumEntries()
const {
return NumEntries; }
1121 void setNumEntries(
unsigned Num) {
1123 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1127 unsigned getNumTombstones()
const {
return NumTombstones; }
1129 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
1131 const BucketT *getInlineBuckets()
const {
1136 return reinterpret_cast<const BucketT *
>(&storage);
1139 BucketT *getInlineBuckets() {
1140 return const_cast<BucketT *
>(
1141 const_cast<const SmallDenseMap *
>(
this)->getInlineBuckets());
1144 const LargeRep *getLargeRep()
const {
1147 return reinterpret_cast<const LargeRep *
>(&storage);
1150 LargeRep *getLargeRep() {
1151 return const_cast<LargeRep *
>(
1152 const_cast<const SmallDenseMap *
>(
this)->getLargeRep());
1155 const BucketT *getBuckets()
const {
1156 return Small ? getInlineBuckets() : getLargeRep()->Buckets;
1159 BucketT *getBuckets() {
1160 return const_cast<BucketT *
>(
1161 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1164 unsigned getNumBuckets()
const {
1165 return Small ? InlineBuckets : getLargeRep()->NumBuckets;
1168 void deallocateBuckets() {
1173 sizeof(BucketT) * getLargeRep()->NumBuckets,
1175 getLargeRep()->~LargeRep();
1178 LargeRep allocateBuckets(
unsigned Num) {
1179 assert(Num > InlineBuckets &&
"Must allocate more buckets than are inline");
1181 sizeof(BucketT) * Num,
alignof(BucketT))),
1187template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1195 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1208 bool NoAdvance =
false)
1210 assert(isHandleInSync() &&
"invalid construction!");
1214 if (shouldReverseIterate<KeyT>()) {
1215 RetreatPastEmptyBuckets();
1218 AdvancePastEmptyBuckets();
1224 template <
bool IsConstSrc,
1225 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1231 assert(isHandleInSync() &&
"invalid iterator access!");
1233 if (shouldReverseIterate<KeyT>())
1238 assert(isHandleInSync() &&
"invalid iterator access!");
1240 if (shouldReverseIterate<KeyT>())
1247 assert((!
LHS.Ptr ||
LHS.isHandleInSync()) &&
"handle not in sync!");
1248 assert((!
RHS.Ptr ||
RHS.isHandleInSync()) &&
"handle not in sync!");
1249 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1250 "comparing incomparable iterators!");
1251 return LHS.Ptr ==
RHS.Ptr;
1260 assert(isHandleInSync() &&
"invalid iterator access!");
1262 if (shouldReverseIterate<KeyT>()) {
1264 RetreatPastEmptyBuckets();
1268 AdvancePastEmptyBuckets();
1272 assert(isHandleInSync() &&
"invalid iterator access!");
1279 void AdvancePastEmptyBuckets() {
1281 const KeyT Empty = KeyInfoT::getEmptyKey();
1282 const KeyT Tombstone = KeyInfoT::getTombstoneKey();
1284 while (
Ptr !=
End && (KeyInfoT::isEqual(
Ptr->getFirst(), Empty) ||
1285 KeyInfoT::isEqual(
Ptr->getFirst(), Tombstone)))
1289 void RetreatPastEmptyBuckets() {
1291 const KeyT Empty = KeyInfoT::getEmptyKey();
1292 const KeyT Tombstone = KeyInfoT::getTombstoneKey();
1294 while (
Ptr !=
End && (KeyInfoT::isEqual(
Ptr[-1].getFirst(), Empty) ||
1295 KeyInfoT::isEqual(
Ptr[-1].getFirst(), Tombstone)))
1300template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1302 return X.getMemorySize();
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
#define LLVM_LIKELY(EXPR)
This file defines DenseMapInfo traits for DenseMap.
This file defines the DebugEpochBase and DebugEpochBase::HandleBase classes.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
static unsigned getHashValue(const KeyT &Val)
static const KeyT getEmptyKey()
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
bool erase(const KeyT &Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
std::pair< iterator, bool > insert_as(std::pair< KeyT, ValueT > &&KV, const LookupKeyT &Val)
Alternate version of insert() which allows a different, and possibly less expensive,...
const_iterator find_as(const LookupKeyT &Val) const
const_iterator end() const
void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd)
iterator find_as(const LookupKeyT &Val)
Alternate version of find() which allows a different, and possibly less expensive,...
const_iterator find(const_arg_type_t< KeyT > Val) const
void insert(InputIt I, InputIt E)
insert - Range insertion of pairs.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
static const KeyT getTombstoneKey()
const ValueT & at(const_arg_type_t< KeyT > Val) const
at - Return the entry for the specified key, or abort if no such entry exists.
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
void copyFrom(const DenseMapBase< OtherBaseT, KeyT, ValueT, KeyInfoT, BucketT > &other)
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
const_iterator begin() const
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
std::pair< iterator, bool > insert_or_assign(KeyT &&Key, V &&Val)
unsigned getMinBucketToReserveForEntries(unsigned NumEntries)
Returns the number of buckets to allocate to ensure that the DenseMap can accommodate NumEntries with...
static unsigned getHashValue(const LookupKeyT &Val)
ValueT & operator[](const KeyT &Key)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
std::pair< iterator, bool > insert_or_assign(const KeyT &Key, V &&Val)
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
ValueT & operator[](KeyT &&Key)
size_t getMemorySize() const
Return the approximate size (in bytes) of the actual map.
std::conditional_t< IsConst, const Bucket, Bucket > value_type
friend bool operator!=(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
DenseMapIterator & operator++()
pointer operator->() const
reference operator*() const
DenseMapIterator(pointer Pos, pointer E, const DebugEpochBase &Epoch, bool NoAdvance=false)
DenseMapIterator()=default
DenseMapIterator operator++(int)
DenseMapIterator(const DenseMapIterator< KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc > &I)
friend bool operator==(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
std::forward_iterator_tag iterator_category
DenseMap(std::initializer_list< typename BaseT::value_type > Vals)
void copyFrom(const DenseMap &other)
DenseMap & operator=(DenseMap &&other)
DenseMap(unsigned InitialReserve=0)
Create a DenseMap with an optional InitialReserve that guarantee that this number of elements can be ...
void grow(unsigned AtLeast)
void init(unsigned InitNumEntries)
DenseMap(const DenseMap &other)
DenseMap(const InputIt &I, const InputIt &E)
DenseMap(DenseMap &&other)
DenseMap & operator=(const DenseMap &other)
void grow(unsigned AtLeast)
SmallDenseMap(const InputIt &I, const InputIt &E)
void swap(SmallDenseMap &RHS)
void init(unsigned InitBuckets)
SmallDenseMap & operator=(SmallDenseMap &&other)
SmallDenseMap & operator=(const SmallDenseMap &other)
SmallDenseMap(unsigned NumInitBuckets=0)
SmallDenseMap(std::initializer_list< typename BaseT::value_type > Vals)
SmallDenseMap(SmallDenseMap &&other)
SmallDenseMap(const SmallDenseMap &other)
void copyFrom(const SmallDenseMap &other)
constexpr char IsConst[]
Key for Kernel::Arg::Metadata::mIsConst.
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
BitVector::size_type capacity_in_bytes(const BitVector &X)
bool operator!=(uint64_t V1, const APInt &V2)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * allocate_buffer(size_t Size, size_t Alignment)
Allocate a buffer of memory with the given size and alignment.
void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment)
Deallocate a buffer of memory with the given size and alignment.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A suitably aligned and sized character array member which can hold elements of any type.
const ValueT & getSecond() const
const KeyT & getFirst() const