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();
165 derived().init(NewNumBuckets);
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();
224 [[nodiscard]]
const ValueT &
at(const_arg_type_t<KeyT> Val)
const {
225 auto Iter = this->
find(std::move(Val));
226 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
233 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
234 return try_emplace_impl(KV.first, KV.second);
240 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
241 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
247 template <
typename... Ts>
249 return try_emplace_impl(std::move(
Key), std::forward<Ts>(Args)...);
255 template <
typename... Ts>
257 return try_emplace_impl(
Key, std::forward<Ts>(Args)...);
265 template <
typename LookupKeyT>
266 std::pair<iterator, bool>
insert_as(std::pair<KeyT, ValueT> &&KV,
267 const LookupKeyT &Val) {
269 if (LookupBucketFor(Val, TheBucket))
270 return {makeIterator(TheBucket),
false};
273 TheBucket = findBucketForInsertion(Val, TheBucket);
274 TheBucket->getFirst() = std::move(KV.first);
275 ::new (&TheBucket->getSecond()) ValueT(std::move(KV.second));
276 return {makeIterator(TheBucket),
true};
280 template <
typename InputIt>
void insert(InputIt
I, InputIt
E) {
290 template <
typename V>
294 Ret.first->second = std::forward<V>(Val);
298 template <
typename V>
302 Ret.first->second = std::forward<V>(Val);
306 template <
typename... Ts>
310 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
314 template <
typename... Ts>
316 auto Ret =
try_emplace(std::move(
Key), std::forward<Ts>(Args)...);
318 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
323 BucketT *TheBucket = doFind(Val);
327 TheBucket->getSecond().~ValueT();
328 TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
329 decrementNumEntries();
330 incrementNumTombstones();
334 BucketT *TheBucket = &*
I;
335 TheBucket->getSecond().~ValueT();
336 TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
337 decrementNumEntries();
338 incrementNumTombstones();
342 return lookupOrInsertIntoBucket(
Key).first->second;
346 return lookupOrInsertIntoBucket(std::move(
Key)).first->second;
353 return Ptr >= getBuckets() &&
Ptr < getBucketsEnd();
365 RHS.incrementEpoch();
366 derived().swapImpl(
RHS);
375 if constexpr (std::is_trivially_destructible_v<KeyT> &&
376 std::is_trivially_destructible_v<ValueT>)
379 if (getNumBuckets() == 0)
382 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
383 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
384 for (BucketT &
B : buckets()) {
385 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
386 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey))
387 B.getSecond().~ValueT();
388 B.getFirst().~KeyT();
393 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
394 "Must pass the derived type to this template!");
398 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
399 "# initial buckets must be a power of two!");
400 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
401 for (BucketT &
B : buckets())
402 ::new (&
B.getFirst())
KeyT(EmptyKey);
418 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
419 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
420 for (BucketT &
B : OldBuckets) {
421 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
422 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
425 bool FoundVal = LookupBucketFor(
B.getFirst(), DestBucket);
427 assert(!FoundVal &&
"Key already in new map?");
428 DestBucket->getFirst() = std::move(
B.getFirst());
429 ::new (&DestBucket->getSecond()) ValueT(std::move(
B.getSecond()));
430 incrementNumEntries();
433 B.getSecond().~ValueT();
435 B.getFirst().~KeyT();
449 derived().deallocateBuckets();
452 if (!derived().allocateBuckets(other.getNumBuckets())) {
458 assert(getNumBuckets() == other.getNumBuckets());
460 setNumEntries(other.getNumEntries());
461 setNumTombstones(other.getNumTombstones());
463 BucketT *Buckets = getBuckets();
464 const BucketT *OtherBuckets = other.getBuckets();
465 const size_t NumBuckets = getNumBuckets();
466 if constexpr (std::is_trivially_copyable_v<KeyT> &&
467 std::is_trivially_copyable_v<ValueT>) {
468 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
469 NumBuckets *
sizeof(BucketT));
471 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
472 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
473 for (
size_t I = 0;
I < NumBuckets; ++
I) {
474 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
475 if (!KeyInfoT::isEqual(Buckets[
I].getFirst(), EmptyKey) &&
476 !KeyInfoT::isEqual(Buckets[
I].getFirst(), TombstoneKey))
477 ::new (&Buckets[
I].getSecond()) ValueT(OtherBuckets[
I].getSecond());
483 DerivedT &derived() {
return *
static_cast<DerivedT *
>(
this); }
484 const DerivedT &derived()
const {
485 return *
static_cast<const DerivedT *
>(
this);
488 template <
typename KeyArgT,
typename... Ts>
489 std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&
Key,
491 BucketT *TheBucket =
nullptr;
492 if (LookupBucketFor(
Key, TheBucket))
493 return {TheBucket,
false};
496 TheBucket = findBucketForInsertion(
Key, TheBucket);
497 TheBucket->getFirst() = std::forward<KeyArgT>(
Key);
498 ::new (&TheBucket->getSecond()) ValueT(std::forward<Ts>(Args)...);
499 return {TheBucket,
true};
502 template <
typename KeyArgT,
typename... Ts>
503 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
504 auto [Bucket,
Inserted] = lookupOrInsertIntoBucket(
505 std::forward<KeyArgT>(
Key), std::forward<Ts>(Args)...);
506 return {makeIterator(Bucket),
Inserted};
509 iterator makeIterator(BucketT *TheBucket) {
513 const_iterator makeConstIterator(
const BucketT *TheBucket)
const {
517 unsigned getNumEntries()
const {
return derived().getNumEntries(); }
519 void setNumEntries(
unsigned Num) { derived().setNumEntries(Num); }
521 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
523 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
525 unsigned getNumTombstones()
const {
return derived().getNumTombstones(); }
527 void setNumTombstones(
unsigned Num) { derived().setNumTombstones(Num); }
529 void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
531 void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
533 const BucketT *getBuckets()
const {
return derived().getBuckets(); }
535 BucketT *getBuckets() {
return derived().getBuckets(); }
537 unsigned getNumBuckets()
const {
return derived().getNumBuckets(); }
539 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
541 const BucketT *getBucketsEnd()
const {
542 return getBuckets() + getNumBuckets();
553 void grow(
unsigned AtLeast) { derived().grow(AtLeast); }
555 template <
typename LookupKeyT>
556 BucketT *findBucketForInsertion(
const LookupKeyT &
Lookup,
557 BucketT *TheBucket) {
569 unsigned NewNumEntries = getNumEntries() + 1;
570 unsigned NumBuckets = getNumBuckets();
572 this->grow(NumBuckets * 2);
573 LookupBucketFor(
Lookup, TheBucket);
575 (NewNumEntries + getNumTombstones()) <=
577 this->grow(NumBuckets);
578 LookupBucketFor(
Lookup, TheBucket);
584 incrementNumEntries();
587 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
588 if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
589 decrementNumTombstones();
594 template <
typename LookupKeyT>
595 const BucketT *doFind(
const LookupKeyT &Val)
const {
596 const BucketT *BucketsPtr = getBuckets();
597 const unsigned NumBuckets = getNumBuckets();
601 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
602 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
603 unsigned ProbeAmt = 1;
605 const BucketT *Bucket = BucketsPtr + BucketNo;
606 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
608 if (
LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
613 BucketNo += ProbeAmt++;
614 BucketNo &= NumBuckets - 1;
618 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
619 return const_cast<BucketT *
>(
627 template <
typename LookupKeyT>
628 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
629 BucketT *BucketsPtr = getBuckets();
630 const unsigned NumBuckets = getNumBuckets();
632 if (NumBuckets == 0) {
633 FoundBucket =
nullptr;
638 BucketT *FoundTombstone =
nullptr;
639 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
640 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
641 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
642 !KeyInfoT::isEqual(Val, TombstoneKey) &&
643 "Empty/Tombstone value shouldn't be inserted into map!");
645 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
646 unsigned ProbeAmt = 1;
648 BucketT *ThisBucket = BucketsPtr + BucketNo;
650 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
651 FoundBucket = ThisBucket;
657 if (
LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
660 FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
666 if (KeyInfoT::isEqual(ThisBucket->getFirst(), TombstoneKey) &&
668 FoundTombstone = ThisBucket;
672 BucketNo += ProbeAmt++;
673 BucketNo &= (NumBuckets - 1);
683 return getNumBuckets() *
sizeof(BucketT);
693template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
698 if (
LHS.size() !=
RHS.size())
701 for (
auto &KV :
LHS) {
702 auto I =
RHS.find(KV.first);
703 if (
I ==
RHS.end() ||
I->second != KV.second)
713template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
721template <
typename KeyT,
typename ValueT,
722 typename KeyInfoT = DenseMapInfo<KeyT>,
725 KeyT, ValueT, KeyInfoT, BucketT> {
734 unsigned NumTombstones;
740 explicit DenseMap(
unsigned NumElementsToReserve = 0) {
741 init(NumElementsToReserve);
754 template <
typename InputIt>
DenseMap(
const InputIt &
I,
const InputIt &
E) {
755 init(std::distance(
I,
E));
759 template <
typename RangeT>
763 DenseMap(std::initializer_list<typename BaseT::value_type> Vals)
795 unsigned getNumEntries()
const {
return NumEntries; }
797 void setNumEntries(
unsigned Num) { NumEntries = Num; }
799 unsigned getNumTombstones()
const {
return NumTombstones; }
801 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
803 BucketT *getBuckets()
const {
return Buckets; }
805 unsigned getNumBuckets()
const {
return NumBuckets; }
807 void deallocateBuckets() {
811 bool allocateBuckets(
unsigned Num) {
813 if (NumBuckets == 0) {
818 Buckets =
static_cast<BucketT *
>(
823 void init(
unsigned InitNumEntries) {
825 if (allocateBuckets(InitBuckets)) {
833 void grow(
unsigned AtLeast) {
834 unsigned OldNumBuckets = NumBuckets;
835 BucketT *OldBuckets = Buckets;
837 allocateBuckets(std::max<unsigned>(
856 std::pair<bool, unsigned> planShrinkAndClear()
const {
857 unsigned NewNumBuckets = 0;
859 NewNumBuckets = std::max(64u, 1u << (
Log2_32_Ceil(NumEntries) + 1));
860 if (NewNumBuckets == NumBuckets)
862 return {
true, NewNumBuckets};
866template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
867 typename KeyInfoT = DenseMapInfo<KeyT>,
871 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
872 ValueT, KeyInfoT, BucketT> {
880 "InlineBuckets must be a power of 2.");
883 unsigned NumEntries : 31;
884 unsigned NumTombstones;
896 AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
898 struct ExactBucketCount {};
899 SmallDenseMap(
unsigned NumBuckets, ExactBucketCount) {
900 allocateBuckets(NumBuckets);
906 init(NumElementsToReserve);
919 template <
typename InputIt>
921 init(std::distance(
I,
E));
925 template <
typename RangeT>
930 : SmallDenseMap(Vals.
begin(), Vals.
end()) {}
939 unsigned TmpNumEntries =
RHS.NumEntries;
940 RHS.NumEntries = NumEntries;
941 NumEntries = TmpNumEntries;
944 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
945 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
946 if (Small &&
RHS.Small) {
951 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
952 BucketT *LHSB = &getInlineBuckets()[i],
953 *RHSB = &
RHS.getInlineBuckets()[i];
954 bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey) &&
955 !KeyInfoT::isEqual(LHSB->getFirst(), TombstoneKey));
956 bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey) &&
957 !KeyInfoT::isEqual(RHSB->getFirst(), TombstoneKey));
958 if (hasLHSValue && hasRHSValue) {
964 std::swap(LHSB->getFirst(), RHSB->getFirst());
966 ::new (&RHSB->getSecond()) ValueT(
std::
move(LHSB->getSecond()));
967 LHSB->getSecond().~ValueT();
969 ::new (&LHSB->getSecond()) ValueT(
std::
move(RHSB->getSecond()));
970 RHSB->getSecond().~ValueT();
975 if (!Small && !
RHS.Small) {
980 SmallDenseMap &SmallSide = Small ? *this :
RHS;
981 SmallDenseMap &LargeSide = Small ?
RHS : *
this;
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));
1010 SmallDenseMap &operator=(
const SmallDenseMap &other) {
1018 deallocateBuckets();
1025 unsigned getNumEntries()
const {
return NumEntries; }
1027 void setNumEntries(
unsigned Num) {
1029 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1033 unsigned getNumTombstones()
const {
return NumTombstones; }
1035 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
1037 const BucketT *getInlineBuckets()
const {
1042 return reinterpret_cast<const BucketT *
>(&storage);
1045 BucketT *getInlineBuckets() {
1046 return const_cast<BucketT *
>(
1047 const_cast<const SmallDenseMap *
>(
this)->getInlineBuckets());
1050 const LargeRep *getLargeRep()
const {
1053 return reinterpret_cast<const LargeRep *
>(&storage);
1056 LargeRep *getLargeRep() {
1057 return const_cast<LargeRep *
>(
1058 const_cast<const SmallDenseMap *
>(
this)->getLargeRep());
1061 const BucketT *getBuckets()
const {
1062 return Small ? getInlineBuckets() : getLargeRep()->Buckets;
1065 BucketT *getBuckets() {
1066 return const_cast<BucketT *
>(
1067 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1070 unsigned getNumBuckets()
const {
1071 return Small ? InlineBuckets : getLargeRep()->NumBuckets;
1075 BucketT *Begin = getInlineBuckets();
1079 void deallocateBuckets() {
1083 if (Small || getLargeRep()->NumBuckets == 0)
1087 sizeof(BucketT) * getLargeRep()->NumBuckets,
1089 getLargeRep()->~LargeRep();
1092 bool allocateBuckets(
unsigned Num) {
1093 if (Num <= InlineBuckets) {
1097 BucketT *NewBuckets =
static_cast<BucketT *
>(
1099 new (getLargeRep()) LargeRep{NewBuckets, Num};
1104 void init(
unsigned InitNumEntries) {
1106 allocateBuckets(InitBuckets);
1110 void grow(
unsigned AtLeast) {
1111 if (AtLeast > InlineBuckets)
1112 AtLeast = std::max<unsigned>(64,
NextPowerOf2(AtLeast - 1));
1114 SmallDenseMap Tmp(AtLeast, ExactBucketCount{});
1115 Tmp.moveFrom(*
this);
1123 Tmp.getLargeRep()->NumBuckets = 0;
1125 deallocateBuckets();
1128 *getLargeRep() = std::move(*Tmp.getLargeRep());
1129 Tmp.getLargeRep()->NumBuckets = 0;
1136 std::pair<bool, unsigned> planShrinkAndClear()
const {
1137 unsigned NewNumBuckets = 0;
1138 if (!this->
empty()) {
1140 if (NewNumBuckets > InlineBuckets)
1141 NewNumBuckets = std::max(64u, NewNumBuckets);
1143 bool Reuse = Small ? NewNumBuckets <= InlineBuckets
1144 : NewNumBuckets == getLargeRep()->NumBuckets;
1147 return {
true, NewNumBuckets};
1151template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1154 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
true>;
1155 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
false>;
1159 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1166 std::conditional_t<shouldReverseIterate<KeyT>(),
1167 std::reverse_iterator<pointer>,
pointer>;
1169 BucketItTy Ptr = {};
1170 BucketItTy End = {};
1172 DenseMapIterator(BucketItTy Pos, BucketItTy
E,
const DebugEpochBase &Epoch)
1173 : DebugEpochBase::HandleBase(&Epoch),
Ptr(Pos), End(
E) {
1174 assert(isHandleInSync() &&
"invalid construction!");
1185 return makeEnd(Buckets, Epoch);
1186 auto R = maybeReverse(Buckets);
1187 DenseMapIterator Iter(R.begin(), R.end(), Epoch);
1188 Iter.AdvancePastEmptyBuckets();
1194 auto R = maybeReverse(Buckets);
1195 return DenseMapIterator(R.end(), R.end(), Epoch);
1201 auto R = maybeReverse(Buckets);
1203 return DenseMapIterator(BucketItTy(
P +
Offset), R.end(), Epoch);
1209 template <
bool IsConstSrc,
1210 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1212 const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &
I)
1217 assert(Ptr != End &&
"dereferencing end() iterator");
1223 const DenseMapIterator &
RHS) {
1224 assert((!
LHS.getEpochAddress() ||
LHS.isHandleInSync()) &&
1225 "handle not in sync!");
1226 assert((!
RHS.getEpochAddress() ||
RHS.isHandleInSync()) &&
1227 "handle not in sync!");
1228 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1229 "comparing incomparable iterators!");
1230 return LHS.Ptr ==
RHS.Ptr;
1234 const DenseMapIterator &
RHS) {
1240 assert(Ptr != End &&
"incrementing end() iterator");
1242 AdvancePastEmptyBuckets();
1247 DenseMapIterator tmp = *
this;
1253 void AdvancePastEmptyBuckets() {
1255 const KeyT Empty = KeyInfoT::getEmptyKey();
1258 while (
Ptr != End && (KeyInfoT::isEqual(
Ptr->getFirst(),
Empty) ||
1263 static auto maybeReverse(iterator_range<pointer>
Range) {
1264 if constexpr (shouldReverseIterate<KeyT>())
1265 return reverse(
Range);
1271template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1272[[nodiscard]]
inline size_t
1274 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.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
LocallyHashedType DenseMapInfo< LocallyHashedType >::Tombstone
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)
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 moveFromImpl(iterator_range< BucketT * > OldBuckets)
void moveFrom(DerivedT &Other)
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.
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
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...
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)
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(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)
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 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.
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