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; }
60template <
typename KeyT,
typename ValueT,
61 typename KeyInfoT = DenseMapInfo<KeyT>,
64class DenseMapIterator;
66template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
96 [[nodiscard]]
inline auto keys() {
97 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
102 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
105 [[nodiscard]]
inline auto keys()
const {
106 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
109 [[nodiscard]]
inline auto values()
const {
110 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
113 [[nodiscard]]
bool empty()
const {
return getNumEntries() == 0; }
114 [[nodiscard]]
unsigned size()
const {
return getNumEntries(); }
121 if (NumBuckets > getNumBuckets())
127 if (getNumEntries() == 0)
132 if (getNumEntries() * 4 < getNumBuckets() && getNumBuckets() > 64) {
137 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
138 if constexpr (std::is_trivially_destructible_v<ValueT>) {
140 for (BucketT &
B : buckets())
141 B.getFirst() = EmptyKey;
143 unsigned NumEntries = getNumEntries();
144 for (BucketT &
B : buckets()) {
145 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey)) {
146 B.getSecond().~ValueT();
148 B.getFirst() = EmptyKey;
151 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)...);
333 BucketT *TheBucket = doFind(Val);
349 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
350 unsigned NumBuckets = getNumBuckets();
351 bool Removed =
false;
352 for (BucketT &
B : buckets()) {
353 if (KeyInfoT::isEqual(
B.getFirst(), EmptyKey))
356 B.getSecond().~ValueT();
357 B.getFirst() = EmptyKey;
358 decrementNumEntries();
364 this->grow(NumBuckets);
370 return lookupOrInsertIntoBucket(
Key).first->second;
374 return lookupOrInsertIntoBucket(std::move(
Key)).first->second;
380 return Ptr >= getBuckets() && Ptr < getBucketsEnd();
392 RHS.incrementEpoch();
393 derived().swapImpl(
RHS);
402 if (derived().allocateBuckets(NewNumBuckets))
411 if constexpr (std::is_trivially_destructible_v<KeyT> &&
412 std::is_trivially_destructible_v<ValueT>)
415 if (getNumBuckets() == 0)
418 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
419 for (BucketT &
B : buckets()) {
420 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey))
421 B.getSecond().~ValueT();
422 B.getFirst().~KeyT();
427 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
428 "Must pass the derived type to this template!");
431 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
432 "# initial buckets must be a power of two!");
433 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
434 for (BucketT &
B : buckets())
435 ::new (&
B.getFirst())
KeyT(EmptyKey);
453 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
454 for (BucketT &
B :
Other.buckets()) {
455 if (!KeyInfoT::isEqual(
B.getFirst(), EmptyKey)) {
458 bool FoundVal = LookupBucketFor(
B.getFirst(), DestBucket);
460 assert(!FoundVal &&
"Key already in new map?");
461 DestBucket->getFirst() = std::move(
B.getFirst());
462 ::new (&DestBucket->getSecond()) ValueT(std::move(
B.getSecond()));
463 incrementNumEntries();
466 B.getSecond().~ValueT();
468 B.getFirst().~KeyT();
470 Other.derived().kill();
475 derived().deallocateBuckets();
477 if (!derived().allocateBuckets(other.getNumBuckets())) {
483 assert(getNumBuckets() == other.getNumBuckets());
485 setNumEntries(other.getNumEntries());
487 BucketT *Buckets = getBuckets();
488 const BucketT *OtherBuckets = other.getBuckets();
489 const size_t NumBuckets = getNumBuckets();
490 if constexpr (std::is_trivially_copyable_v<KeyT> &&
491 std::is_trivially_copyable_v<ValueT>) {
492 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
493 NumBuckets *
sizeof(BucketT));
495 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
496 for (
size_t I = 0;
I < NumBuckets; ++
I) {
497 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
498 if (!KeyInfoT::isEqual(Buckets[
I].getFirst(), EmptyKey))
499 ::new (&Buckets[
I].getSecond()) ValueT(OtherBuckets[
I].getSecond());
513 template <
typename OnMovedT>
516 TheBucket->getSecond().~ValueT();
517 decrementNumEntries();
519 BucketT *BucketsPtr = getBuckets();
520 const unsigned NumBuckets = getNumBuckets();
521 const unsigned Mask = NumBuckets - 1;
522 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
523 unsigned I =
static_cast<unsigned>(TheBucket - BucketsPtr);
527 BucketT &BJ = BucketsPtr[J];
528 if (KeyInfoT::isEqual(BJ.getFirst(), EmptyKey))
530 auto Ideal = KeyInfoT::getHashValue(BJ.getFirst());
533 if (((
I - Ideal) & Mask) < ((J - Ideal) & Mask)) {
534 BucketT &BI = BucketsPtr[
I];
535 BI.getFirst() = std::move(BJ.getFirst());
536 ::new (&BI.getSecond()) ValueT(
std::
move(BJ.getSecond()));
537 BJ.getSecond().~ValueT();
542 BucketsPtr[
I].getFirst() = EmptyKey;
548 template <typename OnMovedT>
bool erase(
const KeyT &Val, OnMovedT &&OnMoved) {
549 BucketT *TheBucket = doFind(Val);
556 DerivedT &derived() {
return *
static_cast<DerivedT *
>(
this); }
557 const DerivedT &derived()
const {
558 return *
static_cast<const DerivedT *
>(
this);
561 template <
typename KeyArgT,
typename... Ts>
562 std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&
Key,
564 BucketT *TheBucket =
nullptr;
565 if (LookupBucketFor(
Key, TheBucket))
566 return {TheBucket,
false};
569 TheBucket = findBucketForInsertion(
Key, TheBucket);
570 TheBucket->getFirst() = std::forward<KeyArgT>(
Key);
571 ::new (&TheBucket->getSecond()) ValueT(std::forward<Ts>(Args)...);
572 return {TheBucket,
true};
575 template <
typename KeyArgT,
typename... Ts>
576 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
577 auto [Bucket,
Inserted] = lookupOrInsertIntoBucket(
578 std::forward<KeyArgT>(
Key), std::forward<Ts>(Args)...);
579 return {makeIterator(Bucket),
Inserted};
582 iterator makeIterator(BucketT *TheBucket) {
586 const_iterator makeConstIterator(
const BucketT *TheBucket)
const {
590 unsigned getNumEntries()
const {
return derived().getNumEntries(); }
592 void setNumEntries(
unsigned Num) { derived().setNumEntries(Num); }
594 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
596 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
598 const BucketT *getBuckets()
const {
return derived().getBuckets(); }
600 BucketT *getBuckets() {
return derived().getBuckets(); }
602 unsigned getNumBuckets()
const {
return derived().getNumBuckets(); }
604 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
606 const BucketT *getBucketsEnd()
const {
607 return getBuckets() + getNumBuckets();
618 void grow(
unsigned MinNumBuckets) {
619 unsigned NumBuckets = DerivedT::roundUpNumBuckets(MinNumBuckets);
621 Tmp.moveFrom(derived());
622 if (derived().maybeMoveFast(std::move(Tmp)))
628 template <
typename LookupKeyT>
629 BucketT *findBucketForInsertion(
const LookupKeyT &
Lookup,
630 BucketT *TheBucket) {
637 unsigned NewNumEntries = getNumEntries() + 1;
638 unsigned NumBuckets = getNumBuckets();
640 this->grow(NumBuckets * 2);
641 LookupBucketFor(
Lookup, TheBucket);
647 incrementNumEntries();
651 template <
typename LookupKeyT>
652 const BucketT *doFind(
const LookupKeyT &Val)
const {
653 const BucketT *BucketsPtr = getBuckets();
654 const unsigned NumBuckets = getNumBuckets();
658 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
659 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
661 const BucketT *Bucket = BucketsPtr + BucketNo;
662 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
664 if (
LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
668 BucketNo = (BucketNo + 1) & (NumBuckets - 1);
672 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
673 return const_cast<BucketT *
>(
680 template <
typename LookupKeyT>
681 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
682 BucketT *BucketsPtr = getBuckets();
683 const unsigned NumBuckets = getNumBuckets();
685 if (NumBuckets == 0) {
686 FoundBucket =
nullptr;
690 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
691 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
692 "Empty value shouldn't be inserted into map!");
694 unsigned BucketNo = KeyInfoT::getHashValue(Val) & (NumBuckets - 1);
696 BucketT *ThisBucket = BucketsPtr + BucketNo;
698 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
699 FoundBucket = ThisBucket;
705 if (
LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
706 FoundBucket = ThisBucket;
711 BucketNo = (BucketNo + 1) & (NumBuckets - 1);
721 return getNumBuckets() *
sizeof(BucketT);
731template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
736 if (
LHS.size() !=
RHS.size())
739 for (
auto &KV :
LHS) {
740 auto I =
RHS.find(KV.first);
741 if (
I ==
RHS.end() ||
I->second != KV.second)
751template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
759template <
typename KeyT,
typename ValueT,
760 typename KeyInfoT = DenseMapInfo<KeyT>,
762class DenseMap :
public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
763 KeyT, ValueT, KeyInfoT, BucketT> {
770 BucketT *Buckets =
nullptr;
771 unsigned NumEntries = 0;
772 unsigned NumBuckets = 0;
774 explicit DenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
781 explicit DenseMap(
unsigned NumElementsToReserve = 0)
789 template <
typename InputIt>
794 template <
typename RangeT>
798 DenseMap(std::initializer_list<typename BaseT::value_type> Vals)
799 : DenseMap(Vals.
begin(), Vals.
end()) {}
827 unsigned getNumEntries()
const {
return NumEntries; }
829 void setNumEntries(
unsigned Num) {
NumEntries = Num; }
831 BucketT *getBuckets()
const {
return Buckets; }
833 unsigned getNumBuckets()
const {
return NumBuckets; }
835 void deallocateBuckets() {
839 bool allocateBuckets(
unsigned Num) {
841 if (NumBuckets == 0) {
846 Buckets =
static_cast<BucketT *
>(
858 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
860 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
863 bool maybeMoveFast(DenseMap &&Other) {
871 std::pair<bool, unsigned> planShrinkAndClear()
const {
872 unsigned NewNumBuckets = 0;
874 NewNumBuckets = std::max(64u, 1u << (
Log2_32_Ceil(NumEntries) + 1));
875 if (NewNumBuckets == NumBuckets)
877 return {
true, NewNumBuckets};
881template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
882 typename KeyInfoT = DenseMapInfo<KeyT>,
886 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
887 ValueT, KeyInfoT, BucketT> {
895 "InlineBuckets must be a power of 2.");
898 unsigned NumEntries : 31;
910 AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
912 SmallDenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
913 this->initWithExactBucketCount(NumBuckets);
928 template <
typename InputIt>
930 : SmallDenseMap(
std::distance(
I,
E)) {
934 template <
typename RangeT>
939 : SmallDenseMap(Vals.
begin(), Vals.
end()) {}
962 unsigned TmpNumEntries =
RHS.NumEntries;
963 RHS.NumEntries = NumEntries;
964 NumEntries = TmpNumEntries;
966 const KeyT EmptyKey = KeyInfoT::getEmptyKey();
967 if (Small &&
RHS.Small) {
972 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
973 BucketT *LHSB = &getInlineBuckets()[i],
974 *RHSB = &
RHS.getInlineBuckets()[i];
975 bool hasLHSValue = !KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey);
976 bool hasRHSValue = !KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey);
977 if (hasLHSValue && hasRHSValue) {
983 std::swap(LHSB->getFirst(), RHSB->getFirst());
985 ::new (&RHSB->getSecond()) ValueT(
std::move(LHSB->getSecond()));
986 LHSB->getSecond().~ValueT();
988 ::new (&LHSB->getSecond()) ValueT(
std::move(RHSB->getSecond()));
989 RHSB->getSecond().~ValueT();
994 if (!Small && !
RHS.Small) {
999 SmallDenseMap &SmallSide =
Small ? *this :
RHS;
1000 SmallDenseMap &LargeSide =
Small ?
RHS : *
this;
1003 LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
1004 LargeSide.getLargeRep()->~LargeRep();
1005 LargeSide.Small =
true;
1010 for (
unsigned i = 0, e = InlineBuckets; i !=
e; ++i) {
1011 BucketT *NewB = &LargeSide.getInlineBuckets()[i],
1012 *OldB = &SmallSide.getInlineBuckets()[i];
1013 ::new (&NewB->getFirst()) KeyT(std::move(OldB->getFirst()));
1014 OldB->getFirst().~KeyT();
1015 if (!KeyInfoT::
isEqual(NewB->getFirst(), EmptyKey)) {
1016 ::new (&NewB->getSecond()) ValueT(std::move(OldB->getSecond()));
1017 OldB->getSecond().~ValueT();
1023 SmallSide.Small = false;
1024 new (SmallSide.getLargeRep()) LargeRep(std::move(TmpRep));
1027 unsigned getNumEntries()
const {
return NumEntries; }
1029 void setNumEntries(
unsigned Num) {
1031 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
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;
1072 iterator_range<BucketT *> inlineBuckets() {
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) {
1122 *getLargeRep() = std::move(*
Other.getLargeRep());
1123 Other.getLargeRep()->NumBuckets = 0;
1130 std::pair<bool, unsigned> planShrinkAndClear()
const {
1131 unsigned NewNumBuckets = 0;
1132 if (!this->
empty()) {
1134 if (NewNumBuckets > InlineBuckets)
1135 NewNumBuckets = std::max(64u, NewNumBuckets);
1137 bool Reuse =
Small ? NewNumBuckets <= InlineBuckets
1138 : NewNumBuckets == getLargeRep()->NumBuckets;
1141 return {
true, NewNumBuckets};
1145template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1148 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
true>;
1149 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
false>;
1153 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1160 std::conditional_t<shouldReverseIterate<KeyT>(),
1161 std::reverse_iterator<pointer>,
pointer>;
1163 BucketItTy Ptr = {};
1164 BucketItTy End = {};
1166 DenseMapIterator(BucketItTy Pos, BucketItTy
E,
const DebugEpochBase &Epoch)
1167 : DebugEpochBase::HandleBase(&Epoch), Ptr(Pos), End(
E) {
1168 assert(isHandleInSync() &&
"invalid construction!");
1179 return makeEnd(Buckets, Epoch);
1180 auto R = maybeReverse(Buckets);
1181 DenseMapIterator Iter(R.begin(), R.end(), Epoch);
1182 Iter.AdvancePastEmptyBuckets();
1188 auto R = maybeReverse(Buckets);
1189 return DenseMapIterator(R.end(), R.end(), Epoch);
1195 auto R = maybeReverse(Buckets);
1197 return DenseMapIterator(BucketItTy(
P +
Offset), R.end(), Epoch);
1203 template <
bool IsConstSrc,
1204 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1206 const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &
I)
1211 assert(Ptr != End &&
"dereferencing end() iterator");
1217 const DenseMapIterator &
RHS) {
1218 assert((!
LHS.getEpochAddress() ||
LHS.isHandleInSync()) &&
1219 "handle not in sync!");
1220 assert((!
RHS.getEpochAddress() ||
RHS.isHandleInSync()) &&
1221 "handle not in sync!");
1222 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1223 "comparing incomparable iterators!");
1224 return LHS.Ptr ==
RHS.Ptr;
1228 const DenseMapIterator &
RHS) {
1234 assert(Ptr != End &&
"incrementing end() iterator");
1236 AdvancePastEmptyBuckets();
1241 DenseMapIterator tmp = *
this;
1247 void AdvancePastEmptyBuckets() {
1249 const KeyT Empty = KeyInfoT::getEmptyKey();
1251 while (Ptr != End && KeyInfoT::isEqual(Ptr->getFirst(),
Empty))
1255 static auto maybeReverse(iterator_range<pointer>
Range) {
1256 if constexpr (shouldReverseIterate<KeyT>())
1257 return reverse(
Range);
1263template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1264[[nodiscard]]
inline size_t
1266 return X.getMemorySize();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isEqual(const Function &Caller, const Function &Callee)
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
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
friend class ValueHandleBase
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)
void eraseFromFilledBucket(BucketT *TheBucket)
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.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
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