14#ifndef LLVM_ADT_DENSEMAP_H
15#define LLVM_ADT_DENSEMAP_H
32#include <initializer_list>
44template <
typename KeyT,
typename ValueT>
46 using std::pair<
KeyT, ValueT>::pair;
49 const KeyT &
getFirst()
const {
return std::pair<KeyT, ValueT>::first; }
50 ValueT &
getSecond() {
return std::pair<KeyT, ValueT>::second; }
51 const ValueT &
getSecond()
const {
return std::pair<KeyT, ValueT>::second; }
56template <
typename KeyT,
typename ValueT,
57 typename KeyInfoT = DenseMapInfo<KeyT>,
60class DenseMapIterator;
62template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
92 [[nodiscard]]
inline auto keys() {
93 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
98 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
101 [[nodiscard]]
inline auto keys()
const {
102 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
105 [[nodiscard]]
inline auto values()
const {
106 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
109 [[nodiscard]]
bool empty()
const {
return getNumEntries() == 0; }
110 [[nodiscard]]
unsigned size()
const {
return getNumEntries(); }
117 if (NumBuckets > getNumBuckets())
123 if (getNumEntries() == 0 && getNumTombstones() == 0)
128 if (getNumEntries() * 4 < getNumBuckets() && getNumBuckets() > 64) {
133 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
134 if constexpr (std::is_trivially_destructible_v<ValueT>) {
136 for (BucketT &
B : buckets())
137 B.getFirst() = EmptyKey;
139 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
140 unsigned NumEntries = getNumEntries();
141 for (BucketT &
B : buckets()) {
142 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey)) {
143 if (!KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
144 B.getSecond().~ValueT();
147 B.getFirst() = EmptyKey;
150 assert(NumEntries == 0 &&
"Node count imbalance!");
158 auto [Reallocate, NewNumBuckets] = derived().planShrinkAndClear();
164 derived().deallocateBuckets();
169 [[nodiscard]]
bool contains(const_arg_type_t<KeyT> Val)
const {
170 return doFind(Val) !=
nullptr;
190 template <
class LookupKeyT>
192 if (BucketT *Bucket = doFind(Val))
193 return makeIterator(Bucket);
196 template <
class LookupKeyT>
198 if (
const BucketT *Bucket = doFind(Val))
199 return makeConstIterator(Bucket);
205 [[nodiscard]] ValueT
lookup(const_arg_type_t<KeyT> Val)
const {
206 if (
const BucketT *Bucket = doFind(Val))
207 return Bucket->getSecond();
214 template <
typename U = std::remove_cv_t<ValueT>>
215 [[nodiscard]] ValueT
lookup_or(const_arg_type_t<KeyT> Val,
217 if (
const BucketT *Bucket = doFind(Val))
218 return Bucket->getSecond();
223 [[nodiscard]] ValueT &
at(const_arg_type_t<KeyT> Val) {
224 auto Iter = this->
find(std::move(Val));
225 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
230 [[nodiscard]]
const ValueT &
at(const_arg_type_t<KeyT> Val)
const {
231 auto Iter = this->
find(std::move(Val));
232 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
239 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
240 return try_emplace_impl(KV.first, KV.second);
246 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
247 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
253 template <
typename... Ts>
255 return try_emplace_impl(std::move(
Key), std::forward<Ts>(Args)...);
261 template <
typename... Ts>
263 return try_emplace_impl(
Key, std::forward<Ts>(Args)...);
271 template <
typename LookupKeyT>
272 std::pair<iterator, bool>
insert_as(std::pair<KeyT, ValueT> &&KV,
273 const LookupKeyT &Val) {
275 if (LookupBucketFor(Val, TheBucket))
276 return {makeIterator(TheBucket),
false};
279 TheBucket = findBucketForInsertion(Val, TheBucket);
280 TheBucket->getFirst() = std::move(KV.first);
281 ::new (&TheBucket->getSecond()) ValueT(std::move(KV.second));
282 return {makeIterator(TheBucket),
true};
286 template <
typename InputIt>
void insert(InputIt
I, InputIt
E) {
296 template <
typename V>
300 Ret.first->second = std::forward<V>(Val);
304 template <
typename V>
308 Ret.first->second = std::forward<V>(Val);
312 template <
typename... Ts>
316 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
320 template <
typename... Ts>
322 auto Ret =
try_emplace(std::move(
Key), std::forward<Ts>(Args)...);
324 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
329 BucketT *TheBucket = doFind(Val);
333 TheBucket->getSecond().~ValueT();
334 TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
335 decrementNumEntries();
336 incrementNumTombstones();
340 BucketT *TheBucket = &*
I;
341 TheBucket->getSecond().~ValueT();
342 TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
343 decrementNumEntries();
344 incrementNumTombstones();
354 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
355 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
356 bool Removed =
false;
357 for (BucketT &
B : buckets()) {
358 if (KeyInfoT::isEqual(
B.getFirst(), EmptyKey) ||
359 KeyInfoT::isEqual(
B.getFirst(), TombstoneKey))
362 B.getSecond().~ValueT();
363 B.getFirst() = TombstoneKey;
364 decrementNumEntries();
365 incrementNumTombstones();
375 return lookupOrInsertIntoBucket(
Key).first->second;
379 return lookupOrInsertIntoBucket(std::move(
Key)).first->second;
385 return Ptr >= getBuckets() && Ptr < getBucketsEnd();
397 RHS.incrementEpoch();
398 derived().swapImpl(
RHS);
407 if (derived().allocateBuckets(NewNumBuckets)) {
418 if constexpr (std::is_trivially_destructible_v<KeyT> &&
419 std::is_trivially_destructible_v<ValueT>)
422 if (getNumBuckets() == 0)
425 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
426 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
427 for (BucketT &
B : buckets()) {
428 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
429 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey))
430 B.getSecond().~ValueT();
431 B.getFirst().~KeyT();
436 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
437 "Must pass the derived type to this template!");
441 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
442 "# initial buckets must be a power of two!");
443 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
444 for (BucketT &
B : buckets())
445 ::new (&
B.getFirst())
KeyT(EmptyKey);
463 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
464 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
465 for (BucketT &
B :
Other.buckets()) {
466 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
467 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
470 bool FoundVal = LookupBucketFor(
B.getFirst(), DestBucket);
472 assert(!FoundVal &&
"Key already in new map?");
473 DestBucket->getFirst() = std::move(
B.getFirst());
474 ::new (&DestBucket->getSecond()) ValueT(std::move(
B.getSecond()));
475 incrementNumEntries();
478 B.getSecond().~ValueT();
480 B.getFirst().~KeyT();
482 Other.derived().kill();
487 derived().deallocateBuckets();
490 if (!derived().allocateBuckets(other.getNumBuckets())) {
496 assert(getNumBuckets() == other.getNumBuckets());
498 setNumEntries(other.getNumEntries());
499 setNumTombstones(other.getNumTombstones());
501 BucketT *Buckets = getBuckets();
502 const BucketT *OtherBuckets = other.getBuckets();
503 const size_t NumBuckets = getNumBuckets();
504 if constexpr (std::is_trivially_copyable_v<KeyT> &&
505 std::is_trivially_copyable_v<ValueT>) {
506 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
507 NumBuckets *
sizeof(BucketT));
509 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
510 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
511 for (
size_t I = 0;
I < NumBuckets; ++
I) {
512 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
513 if (!KeyInfoT::isEqual(Buckets[
I].getFirst(), EmptyKey) &&
514 !KeyInfoT::isEqual(Buckets[
I].getFirst(), TombstoneKey))
515 ::new (&Buckets[
I].getSecond()) ValueT(OtherBuckets[
I].getSecond());
521 DerivedT &derived() {
return *
static_cast<DerivedT *
>(
this); }
522 const DerivedT &derived()
const {
523 return *
static_cast<const DerivedT *
>(
this);
526 template <
typename KeyArgT,
typename... Ts>
527 std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&
Key,
529 BucketT *TheBucket =
nullptr;
530 if (LookupBucketFor(
Key, TheBucket))
531 return {TheBucket,
false};
534 TheBucket = findBucketForInsertion(
Key, TheBucket);
535 TheBucket->getFirst() = std::forward<KeyArgT>(
Key);
536 ::new (&TheBucket->getSecond()) ValueT(std::forward<Ts>(Args)...);
537 return {TheBucket,
true};
540 template <
typename KeyArgT,
typename... Ts>
541 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
542 auto [Bucket,
Inserted] = lookupOrInsertIntoBucket(
543 std::forward<KeyArgT>(
Key), std::forward<Ts>(Args)...);
544 return {makeIterator(Bucket),
Inserted};
547 iterator makeIterator(BucketT *TheBucket) {
551 const_iterator makeConstIterator(
const BucketT *TheBucket)
const {
555 unsigned getNumEntries()
const {
return derived().getNumEntries(); }
557 void setNumEntries(
unsigned Num) { derived().setNumEntries(Num); }
559 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
561 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
563 unsigned getNumTombstones()
const {
return derived().getNumTombstones(); }
565 void setNumTombstones(
unsigned Num) { derived().setNumTombstones(Num); }
567 void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
569 void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
571 const BucketT *getBuckets()
const {
return derived().getBuckets(); }
573 BucketT *getBuckets() {
return derived().getBuckets(); }
575 unsigned getNumBuckets()
const {
return derived().getNumBuckets(); }
577 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
579 const BucketT *getBucketsEnd()
const {
580 return getBuckets() + getNumBuckets();
591 void grow(
unsigned MinNumBuckets) {
592 unsigned NumBuckets = DerivedT::roundUpNumBuckets(MinNumBuckets);
594 Tmp.moveFrom(derived());
595 if (derived().maybeMoveFast(std::move(Tmp)))
601 template <
typename LookupKeyT>
602 BucketT *findBucketForInsertion(
const LookupKeyT &
Lookup,
603 BucketT *TheBucket) {
615 unsigned NewNumEntries = getNumEntries() + 1;
616 unsigned NumBuckets = getNumBuckets();
618 this->grow(NumBuckets * 2);
619 LookupBucketFor(
Lookup, TheBucket);
621 (NewNumEntries + getNumTombstones()) <=
623 this->grow(NumBuckets);
624 LookupBucketFor(
Lookup, TheBucket);
630 incrementNumEntries();
633 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
634 if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
635 decrementNumTombstones();
640 template <
typename LookupKeyT>
641 const BucketT *doFind(
const LookupKeyT &Val)
const {
642 const BucketT *BucketsPtr = getBuckets();
643 const unsigned NumBuckets = getNumBuckets();
647 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
648 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
649 unsigned ProbeAmt = 1;
651 const BucketT *Bucket = BucketsPtr + BucketNo;
652 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
654 if (
LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
659 BucketNo += ProbeAmt++;
660 BucketNo &= NumBuckets - 1;
664 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
665 return const_cast<BucketT *
>(
672 template <
typename LookupKeyT>
673 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
674 BucketT *BucketsPtr = getBuckets();
675 const unsigned NumBuckets = getNumBuckets();
677 if (NumBuckets == 0) {
678 FoundBucket =
nullptr;
683 BucketT *FoundTombstone =
nullptr;
684 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
685 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
686 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
687 !KeyInfoT::isEqual(Val, TombstoneKey) &&
688 "Empty/Tombstone value shouldn't be inserted into map!");
690 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
691 unsigned ProbeAmt = 1;
693 BucketT *ThisBucket = BucketsPtr + BucketNo;
695 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
696 FoundBucket = ThisBucket;
702 if (
LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
705 FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
711 if (KeyInfoT::isEqual(ThisBucket->getFirst(), TombstoneKey) &&
713 FoundTombstone = ThisBucket;
717 BucketNo += ProbeAmt++;
718 BucketNo &= (NumBuckets - 1);
728 return getNumBuckets() *
sizeof(BucketT);
738template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
743 if (
LHS.size() !=
RHS.size())
746 for (
auto &KV :
LHS) {
747 auto I =
RHS.find(KV.first);
748 if (
I ==
RHS.end() ||
I->second != KV.second)
758template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
766template <
typename KeyT,
typename ValueT,
767 typename KeyInfoT = DenseMapInfo<KeyT>,
769class DenseMap :
public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
770 KeyT, ValueT, KeyInfoT, BucketT> {
777 BucketT *Buckets =
nullptr;
778 unsigned NumEntries = 0;
779 unsigned NumTombstones = 0;
780 unsigned NumBuckets = 0;
782 explicit DenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
789 explicit DenseMap(
unsigned NumElementsToReserve = 0)
797 template <
typename InputIt>
802 template <
typename RangeT>
806 DenseMap(std::initializer_list<typename BaseT::value_type> Vals)
807 : DenseMap(Vals.
begin(), Vals.
end()) {}
836 unsigned getNumEntries()
const {
return NumEntries; }
838 void setNumEntries(
unsigned Num) { NumEntries = Num; }
840 unsigned getNumTombstones()
const {
return NumTombstones; }
842 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
844 BucketT *getBuckets()
const {
return Buckets; }
846 unsigned getNumBuckets()
const {
return NumBuckets; }
848 void deallocateBuckets() {
852 bool allocateBuckets(
unsigned Num) {
854 if (NumBuckets == 0) {
859 Buckets =
static_cast<BucketT *
>(
871 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
873 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
876 bool maybeMoveFast(DenseMap &&
Other) {
884 std::pair<bool, unsigned> planShrinkAndClear()
const {
885 unsigned NewNumBuckets = 0;
887 NewNumBuckets = std::max(64u, 1u << (
Log2_32_Ceil(NumEntries) + 1));
888 if (NewNumBuckets == NumBuckets)
890 return {
true, NewNumBuckets};
894template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
895 typename KeyInfoT = DenseMapInfo<KeyT>,
899 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
900 ValueT, KeyInfoT, BucketT> {
908 "InlineBuckets must be a power of 2.");
911 unsigned NumEntries : 31;
912 unsigned NumTombstones;
924 AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
926 SmallDenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
942 template <
typename InputIt>
944 : SmallDenseMap(
std::distance(
I,
E)) {
948 template <
typename RangeT>
953 : SmallDenseMap(Vals.
begin(), Vals.
end()) {}
976 unsigned TmpNumEntries =
RHS.NumEntries;
977 RHS.NumEntries = NumEntries;
978 NumEntries = TmpNumEntries;
981 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
982 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
983 if (Small &&
RHS.Small) {
988 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
989 BucketT *LHSB = &getInlineBuckets()[i],
990 *RHSB = &
RHS.getInlineBuckets()[i];
991 bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey) &&
992 !KeyInfoT::isEqual(LHSB->getFirst(), TombstoneKey));
993 bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey) &&
994 !KeyInfoT::isEqual(RHSB->getFirst(), TombstoneKey));
995 if (hasLHSValue && hasRHSValue) {
1001 std::swap(LHSB->getFirst(), RHSB->getFirst());
1003 ::new (&RHSB->getSecond()) ValueT(
std::
move(LHSB->getSecond()));
1004 LHSB->getSecond().~ValueT();
1005 }
else if (hasRHSValue) {
1006 ::new (&LHSB->getSecond()) ValueT(
std::
move(RHSB->getSecond()));
1007 RHSB->getSecond().~ValueT();
1012 if (!Small && !
RHS.Small) {
1017 SmallDenseMap &SmallSide = Small ? *this :
RHS;
1018 SmallDenseMap &LargeSide = Small ?
RHS : *
this;
1021 LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
1022 LargeSide.getLargeRep()->~LargeRep();
1023 LargeSide.Small =
true;
1028 for (
unsigned i = 0, e = InlineBuckets; i !=
e; ++i) {
1029 BucketT *NewB = &LargeSide.getInlineBuckets()[i],
1030 *OldB = &SmallSide.getInlineBuckets()[i];
1031 ::new (&NewB->getFirst()) KeyT(std::
move(OldB->getFirst()));
1032 OldB->getFirst().~KeyT();
1033 if (!KeyInfoT::
isEqual(NewB->getFirst(), EmptyKey) &&
1034 !KeyInfoT::
isEqual(NewB->getFirst(), TombstoneKey)) {
1035 ::new (&NewB->getSecond()) ValueT(std::
move(OldB->getSecond()));
1036 OldB->getSecond().~ValueT();
1042 SmallSide.Small = false;
1043 new (SmallSide.getLargeRep()) LargeRep(std::
move(TmpRep));
1046 unsigned getNumEntries()
const {
return NumEntries; }
1048 void setNumEntries(
unsigned Num) {
1050 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1054 unsigned getNumTombstones()
const {
return NumTombstones; }
1056 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
1058 const BucketT *getInlineBuckets()
const {
1063 return reinterpret_cast<const BucketT *
>(&storage);
1066 BucketT *getInlineBuckets() {
1067 return const_cast<BucketT *
>(
1068 const_cast<const SmallDenseMap *
>(
this)->getInlineBuckets());
1071 const LargeRep *getLargeRep()
const {
1074 return reinterpret_cast<const LargeRep *
>(&storage);
1077 LargeRep *getLargeRep() {
1078 return const_cast<LargeRep *
>(
1079 const_cast<const SmallDenseMap *
>(
this)->getLargeRep());
1082 const BucketT *getBuckets()
const {
1083 return Small ? getInlineBuckets() : getLargeRep()->Buckets;
1086 BucketT *getBuckets() {
1087 return const_cast<BucketT *
>(
1088 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1091 unsigned getNumBuckets()
const {
1092 return Small ? InlineBuckets : getLargeRep()->NumBuckets;
1096 BucketT *Begin = getInlineBuckets();
1100 void deallocateBuckets() {
1104 if (Small || getLargeRep()->NumBuckets == 0)
1108 sizeof(BucketT) * getLargeRep()->NumBuckets,
1110 getLargeRep()->~LargeRep();
1113 bool allocateBuckets(
unsigned Num) {
1114 if (Num <= InlineBuckets) {
1118 BucketT *NewBuckets =
static_cast<BucketT *
>(
1120 new (getLargeRep()) LargeRep{NewBuckets, Num};
1127 deallocateBuckets();
1129 new (getLargeRep()) LargeRep{
nullptr, 0};
1132 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
1133 if (MinNumBuckets <= InlineBuckets)
1134 return MinNumBuckets;
1135 return std::max(64u,
1136 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
1139 bool maybeMoveFast(SmallDenseMap &&
Other) {
1144 NumEntries =
Other.NumEntries;
1145 NumTombstones =
Other.NumTombstones;
1146 *getLargeRep() = std::move(*
Other.getLargeRep());
1147 Other.getLargeRep()->NumBuckets = 0;
1154 std::pair<bool, unsigned> planShrinkAndClear()
const {
1155 unsigned NewNumBuckets = 0;
1156 if (!this->
empty()) {
1158 if (NewNumBuckets > InlineBuckets)
1159 NewNumBuckets = std::max(64u, NewNumBuckets);
1161 bool Reuse = Small ? NewNumBuckets <= InlineBuckets
1162 : NewNumBuckets == getLargeRep()->NumBuckets;
1165 return {
true, NewNumBuckets};
1169template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1172 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
true>;
1173 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
false>;
1177 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1184 std::conditional_t<shouldReverseIterate<KeyT>(),
1185 std::reverse_iterator<pointer>,
pointer>;
1187 BucketItTy Ptr = {};
1188 BucketItTy End = {};
1190 DenseMapIterator(BucketItTy Pos, BucketItTy
E,
const DebugEpochBase &Epoch)
1191 : DebugEpochBase::HandleBase(&Epoch), Ptr(Pos), End(
E) {
1192 assert(isHandleInSync() &&
"invalid construction!");
1203 return makeEnd(Buckets, Epoch);
1204 auto R = maybeReverse(Buckets);
1205 DenseMapIterator Iter(R.begin(), R.end(), Epoch);
1206 Iter.AdvancePastEmptyBuckets();
1212 auto R = maybeReverse(Buckets);
1213 return DenseMapIterator(R.end(), R.end(), Epoch);
1219 auto R = maybeReverse(Buckets);
1221 return DenseMapIterator(BucketItTy(
P +
Offset), R.end(), Epoch);
1227 template <
bool IsConstSrc,
1228 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1230 const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &
I)
1235 assert(Ptr != End &&
"dereferencing end() iterator");
1241 const DenseMapIterator &
RHS) {
1242 assert((!
LHS.getEpochAddress() ||
LHS.isHandleInSync()) &&
1243 "handle not in sync!");
1244 assert((!
RHS.getEpochAddress() ||
RHS.isHandleInSync()) &&
1245 "handle not in sync!");
1246 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1247 "comparing incomparable iterators!");
1248 return LHS.Ptr ==
RHS.Ptr;
1252 const DenseMapIterator &
RHS) {
1258 assert(Ptr != End &&
"incrementing end() iterator");
1260 AdvancePastEmptyBuckets();
1265 DenseMapIterator tmp = *
this;
1271 void AdvancePastEmptyBuckets() {
1273 const KeyT Empty = KeyInfoT::getEmptyKey();
1276 while (Ptr != End && (KeyInfoT::isEqual(Ptr->getFirst(),
Empty) ||
1277 KeyInfoT::isEqual(Ptr->getFirst(),
Tombstone)))
1281 static auto maybeReverse(iterator_range<pointer>
Range) {
1282 if constexpr (shouldReverseIterate<KeyT>())
1283 return reverse(
Range);
1289template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1290[[nodiscard]]
inline size_t
1292 return X.getMemorySize();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-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.
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.
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
LocallyHashedType DenseMapInfo< LocallyHashedType >::Tombstone
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
bool isHandleInSync() const
ValueT & at(const_arg_type_t< KeyT > Val)
Return the entry for the specified key, or abort if no such entry exists.
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
iterator find(const_arg_type_t< KeyT > Val)
void copyFrom(const DerivedT &other)
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,...
void moveFrom(DerivedT &Other)
const_iterator find_as(const LookupKeyT &Val) const
const_iterator end() const
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)
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.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
bool remove_if(Predicate Pred)
Remove entries that match the given predicate.
const ValueT & at(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or abort if no such entry exists.
bool isPointerIntoBucketsArray(const void *Ptr) const
Return true if the specified pointer points somewhere into the DenseMap's array of buckets (i....
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...
ValueT & operator[](const KeyT &Key)
void initWithExactBucketCount(unsigned NewNumBuckets)
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 BucketT, BucketT > value_type
static DenseMapIterator makeIterator(pointer P, iterator_range< pointer > Buckets, const DebugEpochBase &Epoch)
friend bool operator!=(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
DenseMapIterator & operator++()
pointer operator->() const
reference operator*() const
DenseMapIterator()=default
static DenseMapIterator makeBegin(iterator_range< pointer > Buckets, bool IsEmpty, const DebugEpochBase &Epoch)
DenseMapIterator operator++(int)
DenseMapIterator(const DenseMapIterator< KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc > &I)
ptrdiff_t difference_type
friend bool operator==(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
static DenseMapIterator makeEnd(iterator_range< pointer > Buckets, const DebugEpochBase &Epoch)
std::forward_iterator_tag iterator_category
DenseMap(std::initializer_list< typename BaseT::value_type > Vals)
DenseMap(unsigned NumElementsToReserve=0)
Create a DenseMap with an optional NumElementsToReserve to guarantee that this number of elements can...
DenseMap & operator=(DenseMap &&other)
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)
SmallDenseMap(const InputIt &I, const InputIt &E)
SmallDenseMap & operator=(SmallDenseMap &&other)
SmallDenseMap & operator=(const SmallDenseMap &other)
SmallDenseMap(unsigned NumElementsToReserve=0)
SmallDenseMap(std::initializer_list< typename BaseT::value_type > Vals)
SmallDenseMap(SmallDenseMap &&other)
SmallDenseMap(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.
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
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.
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
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...
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
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.
constexpr bool shouldReverseIterate()
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
@ Default
The result value is 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.
std::conditional_t< std::is_pointer_v< T >, typename add_const_past_pointer< T >::type, const T & > type
const ValueT & getSecond() const
const KeyT & getFirst() const