14#ifndef LLVM_ADT_DENSEMAP_H
15#define LLVM_ADT_DENSEMAP_H
32#include <initializer_list>
44template <
typename KeyT,
typename ValueT>
49 const KeyT &
getFirst()
const {
return std::pair<KeyT, ValueT>::first; }
57 typename KeyInfoT = DenseMapInfo<KeyT>,
60class DenseMapIterator;
62template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
83 if (shouldReverseIterate<KeyT>())
84 return makeIterator(getBucketsEnd() - 1, getBuckets(), *
this);
85 return makeIterator(getBuckets(), getBucketsEnd(), *
this);
88 return makeIterator(getBucketsEnd(), getBucketsEnd(), *
this,
true);
93 if (shouldReverseIterate<KeyT>())
94 return makeConstIterator(getBucketsEnd() - 1, getBuckets(), *
this);
95 return makeConstIterator(getBuckets(), getBucketsEnd(), *
this);
98 return makeConstIterator(getBucketsEnd(), getBucketsEnd(), *
this,
true);
103 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
108 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
112 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
116 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
119 [[nodiscard]]
bool empty()
const {
return getNumEntries() == 0; }
120 unsigned size()
const {
return getNumEntries(); }
127 if (NumBuckets > getNumBuckets())
133 if (getNumEntries() == 0 && getNumTombstones() == 0)
138 if (getNumEntries() * 4 < getNumBuckets() && getNumBuckets() > 64) {
144 if constexpr (std::is_trivially_destructible_v<ValueT>) {
146 for (BucketT &
B : buckets())
147 B.getFirst() = EmptyKey;
150 unsigned NumEntries = getNumEntries();
151 for (BucketT &
B : buckets()) {
152 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey)) {
153 if (!KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
154 B.getSecond().~ValueT();
157 B.getFirst() = EmptyKey;
160 assert(NumEntries == 0 &&
"Node count imbalance!");
169 return doFind(Val) !=
nullptr;
186 if (BucketT *Bucket = doFind(Val))
188 Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
192 template <
class LookupKeyT>
194 if (
const BucketT *Bucket = doFind(Val))
195 return makeConstIterator(
196 Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
204 if (
const BucketT *Bucket = doFind(Val))
205 return Bucket->getSecond();
212 template <
typename U = std::remove_cv_t<ValueT>>
214 if (
const BucketT *Bucket = doFind(Val))
215 return Bucket->getSecond();
221 const ValueT &
at(const_arg_type_t<KeyT> Val)
const {
222 auto Iter = this->
find(std::move(Val));
223 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
230 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
231 return try_emplace_impl(KV.first, KV.second);
237 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
238 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
244 template <
typename... Ts>
246 return try_emplace_impl(std::move(Key), std::forward<Ts>(Args)...);
252 template <
typename... Ts>
254 return try_emplace_impl(Key, std::forward<Ts>(Args)...);
262 template <
typename LookupKeyT>
263 std::pair<iterator, bool>
insert_as(std::pair<KeyT, ValueT> &&KV,
264 const LookupKeyT &Val) {
266 if (LookupBucketFor(Val, TheBucket))
267 return {makeInsertIterator(TheBucket),
false};
270 TheBucket = findBucketForInsertion(Val, TheBucket);
271 TheBucket->getFirst() = std::move(KV.first);
272 ::new (&TheBucket->getSecond())
ValueT(std::move(KV.second));
273 return {makeInsertIterator(TheBucket),
true};
277 template <
typename InputIt>
void insert(InputIt
I, InputIt
E) {
287 template <
typename V>
291 Ret.first->second = std::forward<V>(Val);
295 template <
typename V>
297 auto Ret =
try_emplace(std::move(Key), std::forward<V>(Val));
299 Ret.first->second = std::forward<V>(Val);
303 template <
typename... Ts>
305 auto Ret =
try_emplace(Key, std::forward<Ts>(Args)...);
307 Ret.first->second =
ValueT(std::forward<Ts>(Args)...);
311 template <
typename... Ts>
313 auto Ret =
try_emplace(std::move(Key), std::forward<Ts>(Args)...);
315 Ret.first->second =
ValueT(std::forward<Ts>(Args)...);
320 BucketT *TheBucket = doFind(Val);
324 TheBucket->getSecond().~ValueT();
326 decrementNumEntries();
327 incrementNumTombstones();
331 BucketT *TheBucket = &*
I;
332 TheBucket->getSecond().~ValueT();
334 decrementNumEntries();
335 incrementNumTombstones();
339 return lookupOrInsertIntoBucket(Key).first->second;
343 return lookupOrInsertIntoBucket(std::move(Key)).first->second;
350 return Ptr >= getBuckets() &&
Ptr < getBucketsEnd();
362 if (getNumBuckets() == 0)
366 for (BucketT &
B : buckets()) {
367 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
368 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey))
369 B.getSecond().~ValueT();
370 B.getFirst().~KeyT();
378 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
379 "# initial buckets must be a power of two!");
381 for (BucketT &
B : buckets())
382 ::new (&
B.getFirst())
KeyT(EmptyKey);
402 for (BucketT &
B : OldBuckets) {
403 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
404 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
407 bool FoundVal = LookupBucketFor(
B.getFirst(), DestBucket);
409 assert(!FoundVal &&
"Key already in new map?");
410 DestBucket->getFirst() = std::move(
B.getFirst());
411 ::new (&DestBucket->getSecond())
ValueT(std::move(
B.getSecond()));
412 incrementNumEntries();
415 B.getSecond().~ValueT();
417 B.getFirst().~KeyT();
421 template <
typename OtherBaseT>
425 assert(getNumBuckets() == other.getNumBuckets());
427 setNumEntries(other.getNumEntries());
428 setNumTombstones(other.getNumTombstones());
430 BucketT *Buckets = getBuckets();
431 const BucketT *OtherBuckets = other.getBuckets();
432 const size_t NumBuckets = getNumBuckets();
433 if constexpr (std::is_trivially_copyable_v<KeyT> &&
434 std::is_trivially_copyable_v<ValueT>) {
435 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
436 NumBuckets *
sizeof(BucketT));
440 for (
size_t I = 0;
I < NumBuckets; ++
I) {
441 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
442 if (!KeyInfoT::isEqual(Buckets[
I].getFirst(), EmptyKey) &&
443 !KeyInfoT::isEqual(Buckets[
I].getFirst(), TombstoneKey))
444 ::new (&Buckets[
I].getSecond())
ValueT(OtherBuckets[
I].getSecond());
450 return KeyInfoT::getHashValue(Val);
453 template <
typename LookupKeyT>
455 return KeyInfoT::getHashValue(Val);
459 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
460 "Must pass the derived type to this template!");
461 return KeyInfoT::getEmptyKey();
467 template <
typename KeyArgT,
typename... Ts>
468 std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&Key,
470 BucketT *TheBucket =
nullptr;
471 if (LookupBucketFor(Key, TheBucket))
472 return {TheBucket,
false};
475 TheBucket = findBucketForInsertion(Key, TheBucket);
476 TheBucket->getFirst() = std::forward<KeyArgT>(Key);
477 ::new (&TheBucket->getSecond())
ValueT(
std::forward<Ts>(Args)...);
478 return {TheBucket,
true};
481 template <
typename KeyArgT,
typename... Ts>
482 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&Key, Ts &&...Args) {
483 auto [Bucket,
Inserted] = lookupOrInsertIntoBucket(
484 std::forward<KeyArgT>(Key), std::forward<Ts>(Args)...);
485 return {makeInsertIterator(Bucket),
Inserted};
488 iterator makeIterator(BucketT *
P, BucketT *
E, DebugEpochBase &Epoch,
489 bool NoAdvance =
false) {
490 if (shouldReverseIterate<KeyT>()) {
491 BucketT *
B =
P == getBucketsEnd() ? getBuckets() :
P + 1;
498 const DebugEpochBase &Epoch,
499 const bool NoAdvance =
false)
const {
500 if (shouldReverseIterate<KeyT>()) {
501 const BucketT *
B =
P == getBucketsEnd() ? getBuckets() :
P + 1;
507 iterator makeInsertIterator(BucketT *TheBucket) {
508 return makeIterator(TheBucket,
509 shouldReverseIterate<KeyT>() ? getBuckets()
514 unsigned getNumEntries()
const {
515 return static_cast<const DerivedT *
>(
this)->getNumEntries();
518 void setNumEntries(
unsigned Num) {
519 static_cast<DerivedT *
>(
this)->setNumEntries(Num);
522 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
524 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
526 unsigned getNumTombstones()
const {
527 return static_cast<const DerivedT *
>(
this)->getNumTombstones();
530 void setNumTombstones(
unsigned Num) {
531 static_cast<DerivedT *
>(
this)->setNumTombstones(Num);
534 void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
536 void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
538 const BucketT *getBuckets()
const {
539 return static_cast<const DerivedT *
>(
this)->getBuckets();
542 BucketT *getBuckets() {
return static_cast<DerivedT *
>(
this)->getBuckets(); }
544 unsigned getNumBuckets()
const {
545 return static_cast<const DerivedT *
>(
this)->getNumBuckets();
548 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
550 const BucketT *getBucketsEnd()
const {
551 return getBuckets() + getNumBuckets();
554 iterator_range<BucketT *> buckets() {
558 void grow(
unsigned AtLeast) {
static_cast<DerivedT *
>(
this)->grow(AtLeast); }
560 void shrink_and_clear() {
static_cast<DerivedT *
>(
this)->shrink_and_clear(); }
562 template <
typename LookupKeyT>
563 BucketT *findBucketForInsertion(
const LookupKeyT &
Lookup,
564 BucketT *TheBucket) {
576 unsigned NewNumEntries = getNumEntries() + 1;
577 unsigned NumBuckets = getNumBuckets();
579 this->grow(NumBuckets * 2);
580 LookupBucketFor(
Lookup, TheBucket);
582 (NewNumEntries + getNumTombstones()) <=
584 this->grow(NumBuckets);
585 LookupBucketFor(
Lookup, TheBucket);
591 incrementNumEntries();
595 if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
596 decrementNumTombstones();
601 template <
typename LookupKeyT>
602 const BucketT *doFind(
const LookupKeyT &Val)
const {
603 const BucketT *BucketsPtr = getBuckets();
604 const unsigned NumBuckets = getNumBuckets();
609 unsigned BucketNo =
getHashValue(Val) & (NumBuckets - 1);
610 unsigned ProbeAmt = 1;
612 const BucketT *Bucket = BucketsPtr + BucketNo;
613 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
615 if (
LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
620 BucketNo += ProbeAmt++;
621 BucketNo &= NumBuckets - 1;
625 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
626 return const_cast<BucketT *
>(
634 template <
typename LookupKeyT>
635 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
636 BucketT *BucketsPtr = getBuckets();
637 const unsigned NumBuckets = getNumBuckets();
639 if (NumBuckets == 0) {
640 FoundBucket =
nullptr;
645 BucketT *FoundTombstone =
nullptr;
648 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
649 !KeyInfoT::isEqual(Val, TombstoneKey) &&
650 "Empty/Tombstone value shouldn't be inserted into map!");
652 unsigned BucketNo =
getHashValue(Val) & (NumBuckets - 1);
653 unsigned ProbeAmt = 1;
655 BucketT *ThisBucket = BucketsPtr + BucketNo;
657 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
658 FoundBucket = ThisBucket;
664 if (
LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
667 FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
673 if (KeyInfoT::isEqual(ThisBucket->getFirst(), TombstoneKey) &&
675 FoundTombstone = ThisBucket;
679 BucketNo += ProbeAmt++;
680 BucketNo &= (NumBuckets - 1);
698template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
703 if (
LHS.size() !=
RHS.size())
706 for (
auto &KV :
LHS) {
707 auto I =
RHS.find(KV.first);
708 if (
I ==
RHS.end() ||
I->second != KV.second)
718template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
727 typename KeyInfoT = DenseMapInfo<KeyT>,
730 KeyT, ValueT, KeyInfoT, BucketT> {
739 unsigned NumTombstones;
745 explicit DenseMap(
unsigned InitialReserve = 0) { init(InitialReserve); }
757 template <
typename InputIt>
DenseMap(
const InputIt &
I,
const InputIt &
E) {
758 init(std::distance(
I,
E));
762 template <
typename RangeT>
766 DenseMap(std::initializer_list<typename BaseT::value_type> Vals)
800 if (allocateBuckets(other.NumBuckets)) {
809 unsigned OldNumBuckets = NumBuckets;
810 BucketT *OldBuckets = Buckets;
812 allocateBuckets(std::max<unsigned>(
829 unsigned OldNumBuckets = NumBuckets;
830 unsigned OldNumEntries = NumEntries;
834 unsigned NewNumBuckets = 0;
836 NewNumBuckets = std::max(64, 1 << (
Log2_32_Ceil(OldNumEntries) + 1));
837 if (NewNumBuckets == NumBuckets) {
848 unsigned getNumEntries()
const {
return NumEntries; }
850 void setNumEntries(
unsigned Num) { NumEntries = Num; }
852 unsigned getNumTombstones()
const {
return NumTombstones; }
854 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
856 BucketT *getBuckets()
const {
return Buckets; }
858 unsigned getNumBuckets()
const {
return NumBuckets; }
860 bool allocateBuckets(
unsigned Num) {
862 if (NumBuckets == 0) {
867 Buckets =
static_cast<BucketT *
>(
872 void init(
unsigned InitNumEntries) {
874 if (allocateBuckets(InitBuckets)) {
883template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
884 typename KeyInfoT = DenseMapInfo<KeyT>,
888 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
889 ValueT, KeyInfoT, BucketT> {
897 "InlineBuckets must be a power of 2.");
900 unsigned NumEntries : 31;
901 unsigned NumTombstones;
913 AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
917 if (NumInitBuckets > InlineBuckets)
919 init(NumInitBuckets);
932 template <
typename InputIt>
938 template <
typename RangeT>
951 unsigned TmpNumEntries =
RHS.NumEntries;
952 RHS.NumEntries = NumEntries;
953 NumEntries = TmpNumEntries;
958 if (Small &&
RHS.Small) {
963 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
964 BucketT *LHSB = &getInlineBuckets()[i],
965 *RHSB = &
RHS.getInlineBuckets()[i];
966 bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey) &&
967 !KeyInfoT::isEqual(LHSB->getFirst(), TombstoneKey));
968 bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey) &&
969 !KeyInfoT::isEqual(RHSB->getFirst(), TombstoneKey));
970 if (hasLHSValue && hasRHSValue) {
976 std::swap(LHSB->getFirst(), RHSB->getFirst());
978 ::new (&RHSB->getSecond())
ValueT(std::move(LHSB->getSecond()));
979 LHSB->getSecond().~ValueT();
980 }
else if (hasRHSValue) {
981 ::new (&LHSB->getSecond())
ValueT(std::move(RHSB->getSecond()));
982 RHSB->getSecond().~ValueT();
987 if (!Small && !
RHS.Small) {
996 LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
997 LargeSide.getLargeRep()->~LargeRep();
998 LargeSide.Small =
true;
1003 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
1004 BucketT *NewB = &LargeSide.getInlineBuckets()[i],
1005 *OldB = &SmallSide.getInlineBuckets()[i];
1006 ::new (&NewB->getFirst())
KeyT(std::move(OldB->getFirst()));
1007 OldB->getFirst().~KeyT();
1008 if (!KeyInfoT::isEqual(NewB->getFirst(), EmptyKey) &&
1009 !KeyInfoT::isEqual(NewB->getFirst(), TombstoneKey)) {
1010 ::new (&NewB->getSecond())
ValueT(std::move(OldB->getSecond()));
1011 OldB->getSecond().~ValueT();
1017 SmallSide.Small =
false;
1018 new (SmallSide.getLargeRep()) LargeRep(std::move(TmpRep));
1029 deallocateBuckets();
1037 deallocateBuckets();
1039 if (other.getNumBuckets() > InlineBuckets) {
1041 new (getLargeRep()) LargeRep(allocateBuckets(other.getNumBuckets()));
1048 if (InitBuckets > InlineBuckets) {
1050 new (getLargeRep()) LargeRep(allocateBuckets(InitBuckets));
1056 if (AtLeast > InlineBuckets)
1057 AtLeast = std::max<unsigned>(64,
NextPowerOf2(AtLeast - 1));
1062 BucketT *TmpBegin =
reinterpret_cast<BucketT *
>(&TmpStorage);
1063 BucketT *TmpEnd = TmpBegin;
1069 for (BucketT &
B : inlineBuckets()) {
1070 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
1071 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
1072 assert(
size_t(TmpEnd - TmpBegin) < InlineBuckets &&
1073 "Too many inline buckets!");
1074 ::new (&TmpEnd->getFirst())
KeyT(std::move(
B.getFirst()));
1075 ::new (&TmpEnd->getSecond())
ValueT(std::move(
B.getSecond()));
1077 B.getSecond().~ValueT();
1079 B.getFirst().~KeyT();
1085 if (AtLeast > InlineBuckets) {
1087 new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
1093 LargeRep OldRep = std::move(*getLargeRep());
1094 getLargeRep()->~LargeRep();
1095 if (AtLeast <= InlineBuckets) {
1098 new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
1109 unsigned OldSize = this->
size();
1113 unsigned NewNumBuckets = 0;
1116 if (NewNumBuckets > InlineBuckets && NewNumBuckets < 64u)
1119 if ((Small && NewNumBuckets <= InlineBuckets) ||
1120 (!Small && NewNumBuckets == getLargeRep()->NumBuckets)) {
1125 deallocateBuckets();
1126 init(NewNumBuckets);
1130 unsigned getNumEntries()
const {
return NumEntries; }
1132 void setNumEntries(
unsigned Num) {
1134 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1138 unsigned getNumTombstones()
const {
return NumTombstones; }
1140 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
1142 const BucketT *getInlineBuckets()
const {
1147 return reinterpret_cast<const BucketT *
>(&storage);
1150 BucketT *getInlineBuckets() {
1151 return const_cast<BucketT *
>(
1152 const_cast<const SmallDenseMap *
>(
this)->getInlineBuckets());
1155 const LargeRep *getLargeRep()
const {
1158 return reinterpret_cast<const LargeRep *
>(&storage);
1161 LargeRep *getLargeRep() {
1162 return const_cast<LargeRep *
>(
1163 const_cast<const SmallDenseMap *
>(
this)->getLargeRep());
1166 const BucketT *getBuckets()
const {
1167 return Small ? getInlineBuckets() : getLargeRep()->Buckets;
1170 BucketT *getBuckets() {
1171 return const_cast<BucketT *
>(
1172 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1175 unsigned getNumBuckets()
const {
1176 return Small ? InlineBuckets : getLargeRep()->NumBuckets;
1179 iterator_range<BucketT *> inlineBuckets() {
1180 BucketT *Begin = getInlineBuckets();
1184 void deallocateBuckets() {
1189 sizeof(BucketT) * getLargeRep()->NumBuckets,
1191 getLargeRep()->~LargeRep();
1194 LargeRep allocateBuckets(
unsigned Num) {
1195 assert(Num > InlineBuckets &&
"Must allocate more buckets than are inline");
1197 sizeof(BucketT) * Num,
alignof(BucketT))),
1203template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1211 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1224 bool NoAdvance =
false)
1230 if (shouldReverseIterate<KeyT>()) {
1231 RetreatPastEmptyBuckets();
1234 AdvancePastEmptyBuckets();
1240 template <
bool IsConstSrc,
1241 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1249 if (shouldReverseIterate<KeyT>())
1256 if (shouldReverseIterate<KeyT>())
1263 assert((!
LHS.Ptr ||
LHS.isHandleInSync()) &&
"handle not in sync!");
1264 assert((!
RHS.Ptr ||
RHS.isHandleInSync()) &&
"handle not in sync!");
1265 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1266 "comparing incomparable iterators!");
1267 return LHS.Ptr ==
RHS.Ptr;
1278 if (shouldReverseIterate<KeyT>()) {
1280 RetreatPastEmptyBuckets();
1284 AdvancePastEmptyBuckets();
1295 void AdvancePastEmptyBuckets() {
1297 const KeyT Empty = KeyInfoT::getEmptyKey();
1298 const KeyT Tombstone = KeyInfoT::getTombstoneKey();
1300 while (
Ptr !=
End && (KeyInfoT::isEqual(
Ptr->getFirst(), Empty) ||
1301 KeyInfoT::isEqual(
Ptr->getFirst(), Tombstone)))
1305 void RetreatPastEmptyBuckets() {
1307 const KeyT Empty = KeyInfoT::getEmptyKey();
1308 const KeyT Tombstone = KeyInfoT::getTombstoneKey();
1310 while (
Ptr !=
End && (KeyInfoT::isEqual(
Ptr[-1].getFirst(), Empty) ||
1311 KeyInfoT::isEqual(
Ptr[-1].getFirst(), Tombstone)))
1316template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1318 return X.getMemorySize();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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'.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file contains library features backported from future STL versions.
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
bool isHandleInSync() const
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(iterator_range< BucketT * > OldBuckets)
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
std::pair< iterator, bool > emplace_or_assign(const KeyT &Key, Ts &&...Args)
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
std::pair< iterator, bool > emplace_or_assign(KeyT &&Key, Ts &&...Args)
void insert_range(Range &&R)
Inserts range of 'std::pair<KeyT, ValueT>' values into the map.
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
std::pair< iterator, bool > insert_or_assign(KeyT &&Key, V &&Val)
ValueT lookup_or(const_arg_type_t< KeyT > Val, U &&Default) const
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)
DenseMap(llvm::from_range_t, const RangeT &Range)
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)
SmallDenseMap(llvm::from_range_t, const RangeT &Range)
A range adaptor for a pair of iterators.
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.
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
BitVector::size_type capacity_in_bytes(const BitVector &X)
bool operator!=(uint64_t V1, const APInt &V2)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
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)
auto map_range(ContainerTy &&C, FuncTy F)
LLVM_ABI 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.
LLVM_ABI void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment)
Deallocate a buffer of memory with the given size and alignment.
@ Default
The result values are uniform if and only if all operands are uniform.
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