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();
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 (derived().allocateBuckets(NewNumBuckets)) {
386 if constexpr (std::is_trivially_destructible_v<KeyT> &&
387 std::is_trivially_destructible_v<ValueT>)
390 if (getNumBuckets() == 0)
393 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
394 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
395 for (BucketT &
B : buckets()) {
396 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
397 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey))
398 B.getSecond().~ValueT();
399 B.getFirst().~KeyT();
404 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
405 "Must pass the derived type to this template!");
409 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
410 "# initial buckets must be a power of two!");
411 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
412 for (BucketT &
B : buckets())
413 ::new (&
B.getFirst())
KeyT(EmptyKey);
431 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
432 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
433 for (BucketT &
B :
Other.buckets()) {
434 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
435 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
438 bool FoundVal = LookupBucketFor(
B.getFirst(), DestBucket);
440 assert(!FoundVal &&
"Key already in new map?");
441 DestBucket->getFirst() = std::move(
B.getFirst());
442 ::new (&DestBucket->getSecond()) ValueT(std::move(
B.getSecond()));
443 incrementNumEntries();
446 B.getSecond().~ValueT();
448 B.getFirst().~KeyT();
450 Other.derived().kill();
455 derived().deallocateBuckets();
458 if (!derived().allocateBuckets(other.getNumBuckets())) {
464 assert(getNumBuckets() == other.getNumBuckets());
466 setNumEntries(other.getNumEntries());
467 setNumTombstones(other.getNumTombstones());
469 BucketT *Buckets = getBuckets();
470 const BucketT *OtherBuckets = other.getBuckets();
471 const size_t NumBuckets = getNumBuckets();
472 if constexpr (std::is_trivially_copyable_v<KeyT> &&
473 std::is_trivially_copyable_v<ValueT>) {
474 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
475 NumBuckets *
sizeof(BucketT));
477 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
478 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
479 for (
size_t I = 0;
I < NumBuckets; ++
I) {
480 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
481 if (!KeyInfoT::isEqual(Buckets[
I].getFirst(), EmptyKey) &&
482 !KeyInfoT::isEqual(Buckets[
I].getFirst(), TombstoneKey))
483 ::new (&Buckets[
I].getSecond()) ValueT(OtherBuckets[
I].getSecond());
489 DerivedT &derived() {
return *
static_cast<DerivedT *
>(
this); }
490 const DerivedT &derived()
const {
491 return *
static_cast<const DerivedT *
>(
this);
494 template <
typename KeyArgT,
typename... Ts>
495 std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&
Key,
497 BucketT *TheBucket =
nullptr;
498 if (LookupBucketFor(
Key, TheBucket))
499 return {TheBucket,
false};
502 TheBucket = findBucketForInsertion(
Key, TheBucket);
503 TheBucket->getFirst() = std::forward<KeyArgT>(
Key);
504 ::new (&TheBucket->getSecond()) ValueT(std::forward<Ts>(Args)...);
505 return {TheBucket,
true};
508 template <
typename KeyArgT,
typename... Ts>
509 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
510 auto [Bucket,
Inserted] = lookupOrInsertIntoBucket(
511 std::forward<KeyArgT>(
Key), std::forward<Ts>(Args)...);
512 return {makeIterator(Bucket),
Inserted};
515 iterator makeIterator(BucketT *TheBucket) {
519 const_iterator makeConstIterator(
const BucketT *TheBucket)
const {
523 unsigned getNumEntries()
const {
return derived().getNumEntries(); }
525 void setNumEntries(
unsigned Num) { derived().setNumEntries(Num); }
527 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
529 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
531 unsigned getNumTombstones()
const {
return derived().getNumTombstones(); }
533 void setNumTombstones(
unsigned Num) { derived().setNumTombstones(Num); }
535 void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
537 void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
539 const BucketT *getBuckets()
const {
return derived().getBuckets(); }
541 BucketT *getBuckets() {
return derived().getBuckets(); }
543 unsigned getNumBuckets()
const {
return derived().getNumBuckets(); }
545 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
547 const BucketT *getBucketsEnd()
const {
548 return getBuckets() + getNumBuckets();
559 void grow(
unsigned MinNumBuckets) {
560 unsigned NumBuckets = DerivedT::roundUpNumBuckets(MinNumBuckets);
562 Tmp.moveFrom(derived());
563 if (derived().maybeMoveFast(std::move(Tmp)))
569 template <
typename LookupKeyT>
570 BucketT *findBucketForInsertion(
const LookupKeyT &
Lookup,
571 BucketT *TheBucket) {
583 unsigned NewNumEntries = getNumEntries() + 1;
584 unsigned NumBuckets = getNumBuckets();
586 this->grow(NumBuckets * 2);
587 LookupBucketFor(
Lookup, TheBucket);
589 (NewNumEntries + getNumTombstones()) <=
591 this->grow(NumBuckets);
592 LookupBucketFor(
Lookup, TheBucket);
598 incrementNumEntries();
601 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
602 if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
603 decrementNumTombstones();
608 template <
typename LookupKeyT>
609 const BucketT *doFind(
const LookupKeyT &Val)
const {
610 const BucketT *BucketsPtr = getBuckets();
611 const unsigned NumBuckets = getNumBuckets();
615 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
616 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
617 unsigned ProbeAmt = 1;
619 const BucketT *Bucket = BucketsPtr + BucketNo;
620 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
622 if (
LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
627 BucketNo += ProbeAmt++;
628 BucketNo &= NumBuckets - 1;
632 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
633 return const_cast<BucketT *
>(
641 template <
typename LookupKeyT>
642 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
643 BucketT *BucketsPtr = getBuckets();
644 const unsigned NumBuckets = getNumBuckets();
646 if (NumBuckets == 0) {
647 FoundBucket =
nullptr;
652 BucketT *FoundTombstone =
nullptr;
653 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
654 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
655 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
656 !KeyInfoT::isEqual(Val, TombstoneKey) &&
657 "Empty/Tombstone value shouldn't be inserted into map!");
659 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
660 unsigned ProbeAmt = 1;
662 BucketT *ThisBucket = BucketsPtr + BucketNo;
664 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
665 FoundBucket = ThisBucket;
671 if (
LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
674 FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
680 if (KeyInfoT::isEqual(ThisBucket->getFirst(), TombstoneKey) &&
682 FoundTombstone = ThisBucket;
686 BucketNo += ProbeAmt++;
687 BucketNo &= (NumBuckets - 1);
697 return getNumBuckets() *
sizeof(BucketT);
707template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
712 if (
LHS.size() !=
RHS.size())
715 for (
auto &KV :
LHS) {
716 auto I =
RHS.find(KV.first);
717 if (
I ==
RHS.end() ||
I->second != KV.second)
727template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
735template <
typename KeyT,
typename ValueT,
736 typename KeyInfoT = DenseMapInfo<KeyT>,
738class DenseMap :
public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
739 KeyT, ValueT, KeyInfoT, BucketT> {
748 unsigned NumTombstones;
751 explicit DenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
758 explicit DenseMap(
unsigned NumElementsToReserve = 0)
766 template <
typename InputIt>
771 template <
typename RangeT>
775 DenseMap(std::initializer_list<typename BaseT::value_type> Vals)
776 : DenseMap(Vals.
begin(), Vals.
end()) {}
805 unsigned getNumEntries()
const {
return NumEntries; }
807 void setNumEntries(
unsigned Num) { NumEntries = Num; }
809 unsigned getNumTombstones()
const {
return NumTombstones; }
811 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
813 BucketT *getBuckets()
const {
return Buckets; }
815 unsigned getNumBuckets()
const {
return NumBuckets; }
817 void deallocateBuckets() {
821 bool allocateBuckets(
unsigned Num) {
823 if (NumBuckets == 0) {
828 Buckets =
static_cast<BucketT *
>(
840 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
842 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
845 bool maybeMoveFast(DenseMap &&
Other) {
853 std::pair<bool, unsigned> planShrinkAndClear()
const {
854 unsigned NewNumBuckets = 0;
856 NewNumBuckets = std::max(64u, 1u << (
Log2_32_Ceil(NumEntries) + 1));
857 if (NewNumBuckets == NumBuckets)
859 return {
true, NewNumBuckets};
863template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
864 typename KeyInfoT = DenseMapInfo<KeyT>,
868 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
869 ValueT, KeyInfoT, BucketT> {
877 "InlineBuckets must be a power of 2.");
880 unsigned NumEntries : 31;
881 unsigned NumTombstones;
893 AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
895 SmallDenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
911 template <
typename InputIt>
913 : SmallDenseMap(
std::distance(
I,
E)) {
917 template <
typename RangeT>
922 : SmallDenseMap(Vals.
begin(), Vals.
end()) {}
945 unsigned TmpNumEntries =
RHS.NumEntries;
946 RHS.NumEntries = NumEntries;
947 NumEntries = TmpNumEntries;
950 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
951 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
952 if (Small &&
RHS.Small) {
957 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
958 BucketT *LHSB = &getInlineBuckets()[i],
959 *RHSB = &
RHS.getInlineBuckets()[i];
960 bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey) &&
961 !KeyInfoT::isEqual(LHSB->getFirst(), TombstoneKey));
962 bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey) &&
963 !KeyInfoT::isEqual(RHSB->getFirst(), TombstoneKey));
964 if (hasLHSValue && hasRHSValue) {
970 std::swap(LHSB->getFirst(), RHSB->getFirst());
972 ::new (&RHSB->getSecond()) ValueT(
std::
move(LHSB->getSecond()));
973 LHSB->getSecond().~ValueT();
975 ::new (&LHSB->getSecond()) ValueT(
std::
move(RHSB->getSecond()));
976 RHSB->getSecond().~ValueT();
981 if (!Small && !
RHS.Small) {
986 SmallDenseMap &SmallSide = Small ? *this :
RHS;
987 SmallDenseMap &LargeSide = Small ?
RHS : *
this;
990 LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
991 LargeSide.getLargeRep()->~LargeRep();
992 LargeSide.Small =
true;
997 for (
unsigned i = 0, e = InlineBuckets; i !=
e; ++i) {
998 BucketT *NewB = &LargeSide.getInlineBuckets()[i],
999 *OldB = &SmallSide.getInlineBuckets()[i];
1000 ::new (&NewB->getFirst()) KeyT(std::
move(OldB->getFirst()));
1001 OldB->getFirst().~KeyT();
1002 if (!KeyInfoT::
isEqual(NewB->getFirst(), EmptyKey) &&
1003 !KeyInfoT::
isEqual(NewB->getFirst(), TombstoneKey)) {
1004 ::new (&NewB->getSecond()) ValueT(std::
move(OldB->getSecond()));
1005 OldB->getSecond().~ValueT();
1011 SmallSide.Small = false;
1012 new (SmallSide.getLargeRep()) LargeRep(std::
move(TmpRep));
1015 unsigned getNumEntries()
const {
return NumEntries; }
1017 void setNumEntries(
unsigned Num) {
1019 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1023 unsigned getNumTombstones()
const {
return NumTombstones; }
1025 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
1027 const BucketT *getInlineBuckets()
const {
1032 return reinterpret_cast<const BucketT *
>(&storage);
1035 BucketT *getInlineBuckets() {
1036 return const_cast<BucketT *
>(
1037 const_cast<const SmallDenseMap *
>(
this)->getInlineBuckets());
1040 const LargeRep *getLargeRep()
const {
1043 return reinterpret_cast<const LargeRep *
>(&storage);
1046 LargeRep *getLargeRep() {
1047 return const_cast<LargeRep *
>(
1048 const_cast<const SmallDenseMap *
>(
this)->getLargeRep());
1051 const BucketT *getBuckets()
const {
1052 return Small ? getInlineBuckets() : getLargeRep()->Buckets;
1055 BucketT *getBuckets() {
1056 return const_cast<BucketT *
>(
1057 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1060 unsigned getNumBuckets()
const {
1061 return Small ? InlineBuckets : getLargeRep()->NumBuckets;
1065 BucketT *Begin = getInlineBuckets();
1069 void deallocateBuckets() {
1073 if (Small || getLargeRep()->NumBuckets == 0)
1077 sizeof(BucketT) * getLargeRep()->NumBuckets,
1079 getLargeRep()->~LargeRep();
1082 bool allocateBuckets(
unsigned Num) {
1083 if (Num <= InlineBuckets) {
1087 BucketT *NewBuckets =
static_cast<BucketT *
>(
1089 new (getLargeRep()) LargeRep{NewBuckets, Num};
1096 deallocateBuckets();
1098 new (getLargeRep()) LargeRep{
nullptr, 0};
1101 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
1102 if (MinNumBuckets <= InlineBuckets)
1103 return MinNumBuckets;
1104 return std::max(64u,
1105 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
1108 bool maybeMoveFast(SmallDenseMap &&
Other) {
1113 NumEntries =
Other.NumEntries;
1114 NumTombstones =
Other.NumTombstones;
1115 *getLargeRep() = std::move(*
Other.getLargeRep());
1116 Other.getLargeRep()->NumBuckets = 0;
1123 std::pair<bool, unsigned> planShrinkAndClear()
const {
1124 unsigned NewNumBuckets = 0;
1125 if (!this->
empty()) {
1127 if (NewNumBuckets > InlineBuckets)
1128 NewNumBuckets = std::max(64u, NewNumBuckets);
1130 bool Reuse = Small ? NewNumBuckets <= InlineBuckets
1131 : NewNumBuckets == getLargeRep()->NumBuckets;
1134 return {
true, NewNumBuckets};
1138template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1141 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
true>;
1142 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
false>;
1146 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1153 std::conditional_t<shouldReverseIterate<KeyT>(),
1154 std::reverse_iterator<pointer>,
pointer>;
1156 BucketItTy Ptr = {};
1157 BucketItTy End = {};
1159 DenseMapIterator(BucketItTy Pos, BucketItTy
E,
const DebugEpochBase &Epoch)
1160 : DebugEpochBase::HandleBase(&Epoch),
Ptr(Pos), End(
E) {
1161 assert(isHandleInSync() &&
"invalid construction!");
1172 return makeEnd(Buckets, Epoch);
1173 auto R = maybeReverse(Buckets);
1174 DenseMapIterator Iter(R.begin(), R.end(), Epoch);
1175 Iter.AdvancePastEmptyBuckets();
1181 auto R = maybeReverse(Buckets);
1182 return DenseMapIterator(R.end(), R.end(), Epoch);
1188 auto R = maybeReverse(Buckets);
1190 return DenseMapIterator(BucketItTy(
P +
Offset), R.end(), Epoch);
1196 template <
bool IsConstSrc,
1197 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1199 const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &
I)
1204 assert(Ptr != End &&
"dereferencing end() iterator");
1210 const DenseMapIterator &
RHS) {
1211 assert((!
LHS.getEpochAddress() ||
LHS.isHandleInSync()) &&
1212 "handle not in sync!");
1213 assert((!
RHS.getEpochAddress() ||
RHS.isHandleInSync()) &&
1214 "handle not in sync!");
1215 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1216 "comparing incomparable iterators!");
1217 return LHS.Ptr ==
RHS.Ptr;
1221 const DenseMapIterator &
RHS) {
1227 assert(Ptr != End &&
"incrementing end() iterator");
1229 AdvancePastEmptyBuckets();
1234 DenseMapIterator tmp = *
this;
1240 void AdvancePastEmptyBuckets() {
1242 const KeyT Empty = KeyInfoT::getEmptyKey();
1245 while (
Ptr != End && (KeyInfoT::isEqual(
Ptr->getFirst(),
Empty) ||
1250 static auto maybeReverse(iterator_range<pointer>
Range) {
1251 if constexpr (shouldReverseIterate<KeyT>())
1252 return reverse(
Range);
1258template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1259[[nodiscard]]
inline size_t
1261 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 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)
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)
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)
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