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]] ValueT &
at(const_arg_type_t<KeyT> Val) {
225 auto Iter = this->
find(std::move(Val));
226 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
232 [[nodiscard]]
const ValueT &
at(const_arg_type_t<KeyT> Val)
const {
233 auto Iter = this->
find(std::move(Val));
234 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
241 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
242 return try_emplace_impl(KV.first, KV.second);
248 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
249 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
255 template <
typename... Ts>
257 return try_emplace_impl(std::move(
Key), std::forward<Ts>(Args)...);
263 template <
typename... Ts>
265 return try_emplace_impl(
Key, std::forward<Ts>(Args)...);
273 template <
typename LookupKeyT>
274 std::pair<iterator, bool>
insert_as(std::pair<KeyT, ValueT> &&KV,
275 const LookupKeyT &Val) {
277 if (LookupBucketFor(Val, TheBucket))
278 return {makeIterator(TheBucket),
false};
281 TheBucket = findBucketForInsertion(Val, TheBucket);
282 TheBucket->getFirst() = std::move(KV.first);
283 ::new (&TheBucket->getSecond()) ValueT(std::move(KV.second));
284 return {makeIterator(TheBucket),
true};
288 template <
typename InputIt>
void insert(InputIt
I, InputIt
E) {
298 template <
typename V>
302 Ret.first->second = std::forward<V>(Val);
306 template <
typename V>
310 Ret.first->second = std::forward<V>(Val);
314 template <
typename... Ts>
318 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
322 template <
typename... Ts>
324 auto Ret =
try_emplace(std::move(
Key), std::forward<Ts>(Args)...);
326 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
331 BucketT *TheBucket = doFind(Val);
335 TheBucket->getSecond().~ValueT();
336 TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
337 decrementNumEntries();
338 incrementNumTombstones();
342 BucketT *TheBucket = &*
I;
343 TheBucket->getSecond().~ValueT();
344 TheBucket->getFirst() = KeyInfoT::getTombstoneKey();
345 decrementNumEntries();
346 incrementNumTombstones();
350 return lookupOrInsertIntoBucket(
Key).first->second;
354 return lookupOrInsertIntoBucket(std::move(
Key)).first->second;
361 return Ptr >= getBuckets() && Ptr < getBucketsEnd();
373 RHS.incrementEpoch();
374 derived().swapImpl(
RHS);
383 if (derived().allocateBuckets(NewNumBuckets)) {
394 if constexpr (std::is_trivially_destructible_v<KeyT> &&
395 std::is_trivially_destructible_v<ValueT>)
398 if (getNumBuckets() == 0)
401 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
402 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
403 for (BucketT &
B : buckets()) {
404 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
405 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey))
406 B.getSecond().~ValueT();
407 B.getFirst().~KeyT();
412 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
413 "Must pass the derived type to this template!");
417 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
418 "# initial buckets must be a power of two!");
419 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
420 for (BucketT &
B : buckets())
421 ::new (&
B.getFirst())
KeyT(EmptyKey);
439 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
440 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
441 for (BucketT &
B :
Other.buckets()) {
442 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey) &&
443 !KeyInfoT::isEqual(
B.getFirst(), TombstoneKey)) {
446 bool FoundVal = LookupBucketFor(
B.getFirst(), DestBucket);
448 assert(!FoundVal &&
"Key already in new map?");
449 DestBucket->getFirst() = std::move(
B.getFirst());
450 ::new (&DestBucket->getSecond()) ValueT(std::move(
B.getSecond()));
451 incrementNumEntries();
454 B.getSecond().~ValueT();
456 B.getFirst().~KeyT();
458 Other.derived().kill();
463 derived().deallocateBuckets();
466 if (!derived().allocateBuckets(other.getNumBuckets())) {
472 assert(getNumBuckets() == other.getNumBuckets());
474 setNumEntries(other.getNumEntries());
475 setNumTombstones(other.getNumTombstones());
477 BucketT *Buckets = getBuckets();
478 const BucketT *OtherBuckets = other.getBuckets();
479 const size_t NumBuckets = getNumBuckets();
480 if constexpr (std::is_trivially_copyable_v<KeyT> &&
481 std::is_trivially_copyable_v<ValueT>) {
482 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
483 NumBuckets *
sizeof(BucketT));
485 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
486 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
487 for (
size_t I = 0;
I < NumBuckets; ++
I) {
488 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
489 if (!KeyInfoT::isEqual(Buckets[
I].getFirst(), EmptyKey) &&
490 !KeyInfoT::isEqual(Buckets[
I].getFirst(), TombstoneKey))
491 ::new (&Buckets[
I].getSecond()) ValueT(OtherBuckets[
I].getSecond());
497 DerivedT &derived() {
return *
static_cast<DerivedT *
>(
this); }
498 const DerivedT &derived()
const {
499 return *
static_cast<const DerivedT *
>(
this);
502 template <
typename KeyArgT,
typename... Ts>
503 std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&
Key,
505 BucketT *TheBucket =
nullptr;
506 if (LookupBucketFor(
Key, TheBucket))
507 return {TheBucket,
false};
510 TheBucket = findBucketForInsertion(
Key, TheBucket);
511 TheBucket->getFirst() = std::forward<KeyArgT>(
Key);
512 ::new (&TheBucket->getSecond()) ValueT(std::forward<Ts>(Args)...);
513 return {TheBucket,
true};
516 template <
typename KeyArgT,
typename... Ts>
517 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
518 auto [Bucket,
Inserted] = lookupOrInsertIntoBucket(
519 std::forward<KeyArgT>(
Key), std::forward<Ts>(Args)...);
520 return {makeIterator(Bucket),
Inserted};
523 iterator makeIterator(BucketT *TheBucket) {
527 const_iterator makeConstIterator(
const BucketT *TheBucket)
const {
531 unsigned getNumEntries()
const {
return derived().getNumEntries(); }
533 void setNumEntries(
unsigned Num) { derived().setNumEntries(Num); }
535 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
537 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
539 unsigned getNumTombstones()
const {
return derived().getNumTombstones(); }
541 void setNumTombstones(
unsigned Num) { derived().setNumTombstones(Num); }
543 void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
545 void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
547 const BucketT *getBuckets()
const {
return derived().getBuckets(); }
549 BucketT *getBuckets() {
return derived().getBuckets(); }
551 unsigned getNumBuckets()
const {
return derived().getNumBuckets(); }
553 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
555 const BucketT *getBucketsEnd()
const {
556 return getBuckets() + getNumBuckets();
567 void grow(
unsigned MinNumBuckets) {
568 unsigned NumBuckets = DerivedT::roundUpNumBuckets(MinNumBuckets);
570 Tmp.moveFrom(derived());
571 if (derived().maybeMoveFast(std::move(Tmp)))
577 template <
typename LookupKeyT>
578 BucketT *findBucketForInsertion(
const LookupKeyT &
Lookup,
579 BucketT *TheBucket) {
591 unsigned NewNumEntries = getNumEntries() + 1;
592 unsigned NumBuckets = getNumBuckets();
594 this->grow(NumBuckets * 2);
595 LookupBucketFor(
Lookup, TheBucket);
597 (NewNumEntries + getNumTombstones()) <=
599 this->grow(NumBuckets);
600 LookupBucketFor(
Lookup, TheBucket);
606 incrementNumEntries();
609 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
610 if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
611 decrementNumTombstones();
616 template <
typename LookupKeyT>
617 const BucketT *doFind(
const LookupKeyT &Val)
const {
618 const BucketT *BucketsPtr = getBuckets();
619 const unsigned NumBuckets = getNumBuckets();
623 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
624 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
625 unsigned ProbeAmt = 1;
627 const BucketT *Bucket = BucketsPtr + BucketNo;
628 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
630 if (
LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
635 BucketNo += ProbeAmt++;
636 BucketNo &= NumBuckets - 1;
640 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
641 return const_cast<BucketT *
>(
649 template <
typename LookupKeyT>
650 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
651 BucketT *BucketsPtr = getBuckets();
652 const unsigned NumBuckets = getNumBuckets();
654 if (NumBuckets == 0) {
655 FoundBucket =
nullptr;
660 BucketT *FoundTombstone =
nullptr;
661 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
662 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
663 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
664 !KeyInfoT::isEqual(Val, TombstoneKey) &&
665 "Empty/Tombstone value shouldn't be inserted into map!");
667 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
668 unsigned ProbeAmt = 1;
670 BucketT *ThisBucket = BucketsPtr + BucketNo;
672 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
673 FoundBucket = ThisBucket;
679 if (
LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
682 FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
688 if (KeyInfoT::isEqual(ThisBucket->getFirst(), TombstoneKey) &&
690 FoundTombstone = ThisBucket;
694 BucketNo += ProbeAmt++;
695 BucketNo &= (NumBuckets - 1);
705 return getNumBuckets() *
sizeof(BucketT);
715template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
720 if (
LHS.size() !=
RHS.size())
723 for (
auto &KV :
LHS) {
724 auto I =
RHS.find(KV.first);
725 if (
I ==
RHS.end() ||
I->second != KV.second)
735template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
743template <
typename KeyT,
typename ValueT,
744 typename KeyInfoT = DenseMapInfo<KeyT>,
746class DenseMap :
public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
747 KeyT, ValueT, KeyInfoT, BucketT> {
756 unsigned NumTombstones;
759 explicit DenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
766 explicit DenseMap(
unsigned NumElementsToReserve = 0)
774 template <
typename InputIt>
779 template <
typename RangeT>
783 DenseMap(std::initializer_list<typename BaseT::value_type> Vals)
784 : DenseMap(Vals.
begin(), Vals.
end()) {}
813 unsigned getNumEntries()
const {
return NumEntries; }
815 void setNumEntries(
unsigned Num) { NumEntries = Num; }
817 unsigned getNumTombstones()
const {
return NumTombstones; }
819 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
821 BucketT *getBuckets()
const {
return Buckets; }
823 unsigned getNumBuckets()
const {
return NumBuckets; }
825 void deallocateBuckets() {
829 bool allocateBuckets(
unsigned Num) {
831 if (NumBuckets == 0) {
836 Buckets =
static_cast<BucketT *
>(
848 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
850 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
853 bool maybeMoveFast(DenseMap &&
Other) {
861 std::pair<bool, unsigned> planShrinkAndClear()
const {
862 unsigned NewNumBuckets = 0;
864 NewNumBuckets = std::max(64u, 1u << (
Log2_32_Ceil(NumEntries) + 1));
865 if (NewNumBuckets == NumBuckets)
867 return {
true, NewNumBuckets};
871template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
872 typename KeyInfoT = DenseMapInfo<KeyT>,
876 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
877 ValueT, KeyInfoT, BucketT> {
885 "InlineBuckets must be a power of 2.");
888 unsigned NumEntries : 31;
889 unsigned NumTombstones;
901 AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
903 SmallDenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
919 template <
typename InputIt>
921 : SmallDenseMap(
std::distance(
I,
E)) {
925 template <
typename RangeT>
930 : SmallDenseMap(Vals.
begin(), Vals.
end()) {}
953 unsigned TmpNumEntries =
RHS.NumEntries;
954 RHS.NumEntries = NumEntries;
955 NumEntries = TmpNumEntries;
958 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
959 const KeyT TombstoneKey = KeyInfoT::getTombstoneKey();
960 if (Small &&
RHS.Small) {
965 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
966 BucketT *LHSB = &getInlineBuckets()[i],
967 *RHSB = &
RHS.getInlineBuckets()[i];
968 bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey) &&
969 !KeyInfoT::isEqual(LHSB->getFirst(), TombstoneKey));
970 bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey) &&
971 !KeyInfoT::isEqual(RHSB->getFirst(), TombstoneKey));
972 if (hasLHSValue && hasRHSValue) {
978 std::swap(LHSB->getFirst(), RHSB->getFirst());
980 ::new (&RHSB->getSecond()) ValueT(
std::
move(LHSB->getSecond()));
981 LHSB->getSecond().~ValueT();
983 ::new (&LHSB->getSecond()) ValueT(
std::
move(RHSB->getSecond()));
984 RHSB->getSecond().~ValueT();
989 if (!Small && !
RHS.Small) {
994 SmallDenseMap &SmallSide = Small ? *this :
RHS;
995 SmallDenseMap &LargeSide = Small ?
RHS : *
this;
998 LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
999 LargeSide.getLargeRep()->~LargeRep();
1000 LargeSide.Small =
true;
1005 for (
unsigned i = 0, e = InlineBuckets; i !=
e; ++i) {
1006 BucketT *NewB = &LargeSide.getInlineBuckets()[i],
1007 *OldB = &SmallSide.getInlineBuckets()[i];
1008 ::new (&NewB->getFirst()) KeyT(std::
move(OldB->getFirst()));
1009 OldB->getFirst().~KeyT();
1010 if (!KeyInfoT::
isEqual(NewB->getFirst(), EmptyKey) &&
1011 !KeyInfoT::
isEqual(NewB->getFirst(), TombstoneKey)) {
1012 ::new (&NewB->getSecond()) ValueT(std::
move(OldB->getSecond()));
1013 OldB->getSecond().~ValueT();
1019 SmallSide.Small = false;
1020 new (SmallSide.getLargeRep()) LargeRep(std::
move(TmpRep));
1023 unsigned getNumEntries()
const {
return NumEntries; }
1025 void setNumEntries(
unsigned Num) {
1027 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1031 unsigned getNumTombstones()
const {
return NumTombstones; }
1033 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
1035 const BucketT *getInlineBuckets()
const {
1040 return reinterpret_cast<const BucketT *
>(&storage);
1043 BucketT *getInlineBuckets() {
1044 return const_cast<BucketT *
>(
1045 const_cast<const SmallDenseMap *
>(
this)->getInlineBuckets());
1048 const LargeRep *getLargeRep()
const {
1051 return reinterpret_cast<const LargeRep *
>(&storage);
1054 LargeRep *getLargeRep() {
1055 return const_cast<LargeRep *
>(
1056 const_cast<const SmallDenseMap *
>(
this)->getLargeRep());
1059 const BucketT *getBuckets()
const {
1060 return Small ? getInlineBuckets() : getLargeRep()->Buckets;
1063 BucketT *getBuckets() {
1064 return const_cast<BucketT *
>(
1065 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1068 unsigned getNumBuckets()
const {
1069 return Small ? InlineBuckets : getLargeRep()->NumBuckets;
1073 BucketT *Begin = getInlineBuckets();
1077 void deallocateBuckets() {
1081 if (Small || getLargeRep()->NumBuckets == 0)
1085 sizeof(BucketT) * getLargeRep()->NumBuckets,
1087 getLargeRep()->~LargeRep();
1090 bool allocateBuckets(
unsigned Num) {
1091 if (Num <= InlineBuckets) {
1095 BucketT *NewBuckets =
static_cast<BucketT *
>(
1097 new (getLargeRep()) LargeRep{NewBuckets, Num};
1104 deallocateBuckets();
1106 new (getLargeRep()) LargeRep{
nullptr, 0};
1109 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
1110 if (MinNumBuckets <= InlineBuckets)
1111 return MinNumBuckets;
1112 return std::max(64u,
1113 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
1116 bool maybeMoveFast(SmallDenseMap &&
Other) {
1121 NumEntries =
Other.NumEntries;
1122 NumTombstones =
Other.NumTombstones;
1123 *getLargeRep() = std::move(*
Other.getLargeRep());
1124 Other.getLargeRep()->NumBuckets = 0;
1131 std::pair<bool, unsigned> planShrinkAndClear()
const {
1132 unsigned NewNumBuckets = 0;
1133 if (!this->
empty()) {
1135 if (NewNumBuckets > InlineBuckets)
1136 NewNumBuckets = std::max(64u, NewNumBuckets);
1138 bool Reuse = Small ? NewNumBuckets <= InlineBuckets
1139 : NewNumBuckets == getLargeRep()->NumBuckets;
1142 return {
true, NewNumBuckets};
1146template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1149 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
true>;
1150 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
false>;
1154 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1161 std::conditional_t<shouldReverseIterate<KeyT>(),
1162 std::reverse_iterator<pointer>,
pointer>;
1164 BucketItTy Ptr = {};
1165 BucketItTy End = {};
1167 DenseMapIterator(BucketItTy Pos, BucketItTy
E,
const DebugEpochBase &Epoch)
1168 : DebugEpochBase::HandleBase(&Epoch), Ptr(Pos), End(
E) {
1169 assert(isHandleInSync() &&
"invalid construction!");
1180 return makeEnd(Buckets, Epoch);
1181 auto R = maybeReverse(Buckets);
1182 DenseMapIterator Iter(R.begin(), R.end(), Epoch);
1183 Iter.AdvancePastEmptyBuckets();
1189 auto R = maybeReverse(Buckets);
1190 return DenseMapIterator(R.end(), R.end(), Epoch);
1196 auto R = maybeReverse(Buckets);
1198 return DenseMapIterator(BucketItTy(
P +
Offset), R.end(), Epoch);
1204 template <
bool IsConstSrc,
1205 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1207 const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &
I)
1212 assert(Ptr != End &&
"dereferencing end() iterator");
1218 const DenseMapIterator &
RHS) {
1219 assert((!
LHS.getEpochAddress() ||
LHS.isHandleInSync()) &&
1220 "handle not in sync!");
1221 assert((!
RHS.getEpochAddress() ||
RHS.isHandleInSync()) &&
1222 "handle not in sync!");
1223 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1224 "comparing incomparable iterators!");
1225 return LHS.Ptr ==
RHS.Ptr;
1229 const DenseMapIterator &
RHS) {
1235 assert(Ptr != End &&
"incrementing end() iterator");
1237 AdvancePastEmptyBuckets();
1242 DenseMapIterator tmp = *
this;
1248 void AdvancePastEmptyBuckets() {
1250 const KeyT Empty = KeyInfoT::getEmptyKey();
1253 while (Ptr != End && (KeyInfoT::isEqual(Ptr->getFirst(),
Empty) ||
1254 KeyInfoT::isEqual(Ptr->getFirst(),
Tombstone)))
1258 static auto maybeReverse(iterator_range<pointer>
Range) {
1259 if constexpr (shouldReverseIterate<KeyT>())
1260 return reverse(
Range);
1266template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1267[[nodiscard]]
inline size_t
1269 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 & at(const_arg_type_t< KeyT > Val)
at - Return the entry for the specified key, or abort if no such entry exists.
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