21#ifndef LLVM_ADT_DENSEMAP_H
22#define LLVM_ADT_DENSEMAP_H
40#include <initializer_list>
52template <
typename KeyT,
typename ValueT>
54 using std::pair<
KeyT, ValueT>::pair;
57 const KeyT &
getFirst()
const {
return std::pair<KeyT, ValueT>::first; }
58 ValueT &
getSecond() {
return std::pair<KeyT, ValueT>::second; }
59 const ValueT &
getSecond()
const {
return std::pair<KeyT, ValueT>::second; }
70 "bucket count must be zero or a power of two");
75 return (U[
I >> 5] >> (
I & 31)) & 1;
79 U[
I >> 5] &= ~(
UsedT(1) << (
I & 31));
89 for (
unsigned W = 0; W != NW; ++W) {
102 return std::max(
alignof(BucketT),
alignof(
UsedT));
105 return sizeof(BucketT) *
static_cast<size_t>(Num) +
115template <
typename KeyT,
typename ValueT,
118 bool IsConst =
false>
121template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
124 template <
typename T>
156 [[nodiscard]]
inline auto keys() {
157 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
162 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
165 [[nodiscard]]
inline auto keys()
const {
166 return map_range(*
this, [](
const BucketT &
P) {
return P.getFirst(); });
169 [[nodiscard]]
inline auto values()
const {
170 return map_range(*
this, [](
const BucketT &
P) {
return P.getSecond(); });
173 [[nodiscard]]
bool empty()
const {
return getNumEntries() == 0; }
174 [[nodiscard]]
unsigned size()
const {
return getNumEntries(); }
181 if (NumBuckets > getNumBuckets())
187 if (getNumEntries() == 0)
192 if (getNumEntries() * 4 < getNumBuckets() && getNumBuckets() > 64) {
198 std::memset(getUsed(), 0,
205 auto [Reallocate, NewNumBuckets] = derived().planShrinkAndClear();
211 derived().deallocateBuckets();
216 [[nodiscard]]
bool contains(const_arg_type_t<KeyT> Val)
const {
217 return doFind(Val) !=
nullptr;
237 template <
class LookupKeyT>
239 if (BucketT *Bucket = doFind(Val))
240 return makeIterator(Bucket);
243 template <
class LookupKeyT>
245 if (
const BucketT *Bucket = doFind(Val))
246 return makeConstIterator(Bucket);
252 [[nodiscard]] ValueT
lookup(const_arg_type_t<KeyT> Val)
const {
253 if (
const BucketT *Bucket = doFind(Val))
254 return Bucket->getSecond();
261 template <
typename U = std::remove_cv_t<ValueT>>
262 [[nodiscard]] ValueT
lookup_or(const_arg_type_t<KeyT> Val,
264 if (
const BucketT *Bucket = doFind(Val))
265 return Bucket->getSecond();
270 [[nodiscard]] ValueT &
at(const_arg_type_t<KeyT> Val) {
271 auto Iter = this->
find(std::move(Val));
272 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
277 [[nodiscard]]
const ValueT &
at(const_arg_type_t<KeyT> Val)
const {
278 auto Iter = this->
find(std::move(Val));
279 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
286 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
287 return try_emplace_impl(KV.first, KV.second);
293 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
294 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
300 template <
typename... Ts>
302 return try_emplace_impl(std::move(
Key), std::forward<Ts>(Args)...);
308 template <
typename... Ts>
310 return try_emplace_impl(
Key, std::forward<Ts>(Args)...);
318 template <
typename LookupKeyT>
319 std::pair<iterator, bool>
insert_as(std::pair<KeyT, ValueT> &&KV,
320 const LookupKeyT &Val) {
322 if (LookupBucketFor(Val, TheBucket))
323 return {makeIterator(TheBucket),
false};
326 TheBucket = findBucketForInsertion(Val, TheBucket);
327 ::new (&TheBucket->getFirst())
KeyT(std::move(KV.first));
328 ::new (&TheBucket->getSecond()) ValueT(std::move(KV.second));
329 return {makeIterator(TheBucket),
true};
333 template <
typename InputIt>
void insert(InputIt
I, InputIt
E) {
343 template <
typename V>
347 Ret.first->second = std::forward<V>(Val);
351 template <
typename V>
355 Ret.first->second = std::forward<V>(Val);
359 template <
typename... Ts>
363 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
367 template <
typename... Ts>
369 auto Ret =
try_emplace(std::move(
Key), std::forward<Ts>(Args)...);
371 Ret.first->second = ValueT(std::forward<Ts>(Args)...);
380 BucketT *TheBucket = doFind(Val);
396 UsedT *U = getUsed();
397 unsigned NumBuckets = getNumBuckets();
398 BucketT *
B = getBuckets();
399 bool Removed =
false;
400 for (
unsigned I = 0;
I != NumBuckets; ++
I) {
404 B[
I].getSecond().~ValueT();
405 B[
I].getFirst().~KeyT();
407 decrementNumEntries();
413 this->grow(NumBuckets);
419 return lookupOrInsertIntoBucket(
Key).first->second;
423 return lookupOrInsertIntoBucket(std::move(
Key)).first->second;
429 return Ptr >= getBuckets() && Ptr < getBucketsEnd();
441 RHS.incrementEpoch();
442 derived().swapImpl(
RHS);
460 if (derived().allocateBuckets(NewNumBuckets))
469 if constexpr (std::is_trivially_destructible_v<KeyT> &&
470 std::is_trivially_destructible_v<ValueT>)
473 if (getNumBuckets() == 0)
476 BucketT *
B = getBuckets();
477 const UsedT *U = getUsed();
478 const unsigned E = getNumBuckets();
480 B[
I].getSecond().~ValueT();
481 B[
I].getFirst().~KeyT();
486 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
487 "Must pass the derived type to this template!");
490 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
491 "# initial buckets must be a power of two!");
492 if (getNumBuckets()) {
493 std::memset(getUsed(), 0,
513 assert(getNumEntries() == 0 &&
"moveFrom requires an empty destination");
514 BucketT *OtherB =
Other.getBuckets();
515 UsedT *OtherU =
Other.getUsed();
516 const unsigned E =
Other.getNumBuckets();
517 UsedT *U = getUsed();
518 BucketT *
B = getBuckets();
519 const unsigned Mask = getNumBuckets() - 1;
523 unsigned BucketNo = KeyInfoT::getHashValue(OtherB[
I].getFirst()) & Mask;
525 BucketNo = (BucketNo + 1) & Mask;
526 BucketT *DestBucket =
B + BucketNo;
527 ::new (&DestBucket->getFirst())
KeyT(std::move(OtherB[
I].getFirst()));
528 ::new (&DestBucket->getSecond()) ValueT(std::move(OtherB[
I].getSecond()));
532 OtherB[
I].getSecond().~ValueT();
533 OtherB[
I].getFirst().~KeyT();
535 setNumEntries(
Other.getNumEntries());
536 Other.derived().kill();
541 derived().deallocateBuckets();
543 if (!derived().allocateBuckets(other.getNumBuckets())) {
549 assert(getNumBuckets() == other.getNumBuckets());
551 setNumEntries(other.getNumEntries());
553 BucketT *Buckets = getBuckets();
554 const BucketT *OtherBuckets = other.getBuckets();
555 const unsigned NumBuckets = getNumBuckets();
556 UsedT *U = getUsed();
557 const UsedT *OtherU = other.getUsed();
558 std::memcpy(U, OtherU,
560 if constexpr (std::is_trivially_copyable_v<KeyT> &&
561 std::is_trivially_copyable_v<ValueT>) {
562 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
563 NumBuckets *
sizeof(BucketT));
566 ::new (&Buckets[
I].getFirst())
KeyT(OtherBuckets[
I].getFirst());
567 ::new (&Buckets[
I].getSecond()) ValueT(OtherBuckets[
I].getSecond());
581 template <
typename OnMovedT>
583 OnMovedT &&OnMoved) {
585 TheBucket->getSecond().~ValueT();
586 TheBucket->getFirst().~KeyT();
587 decrementNumEntries();
589 BucketT *BucketsPtr = getBuckets();
590 UsedT *U = getUsed();
591 const unsigned Mask = getNumBuckets() - 1;
592 unsigned I = TheBucket - BucketsPtr;
596 BucketT &BJ = BucketsPtr[J];
599 auto Ideal = KeyInfoT::getHashValue(BJ.getFirst());
602 if (((
I - Ideal) & Mask) < ((J - Ideal) & Mask)) {
603 BucketT &BI = BucketsPtr[
I];
604 ::new (&BI.getFirst())
KeyT(
std::
move(BJ.getFirst()));
605 ::new (&BI.getSecond()) ValueT(
std::
move(BJ.getSecond()));
606 BJ.getSecond().~ValueT();
607 BJ.getFirst().~
KeyT();
618 template <typename OnMovedT>
bool erase(
const KeyT &Val, OnMovedT &&OnMoved) {
619 BucketT *TheBucket = doFind(Val);
626 DerivedT &derived() {
return *
static_cast<DerivedT *
>(
this); }
627 const DerivedT &derived()
const {
628 return *
static_cast<const DerivedT *
>(
this);
631 template <
typename KeyArgT,
typename... Ts>
632 std::pair<BucketT *, bool> lookupOrInsertIntoBucket(KeyArgT &&
Key,
634 BucketT *TheBucket =
nullptr;
635 if (LookupBucketFor(
Key, TheBucket))
636 return {TheBucket,
false};
639 TheBucket = findBucketForInsertion(
Key, TheBucket);
640 ::new (&TheBucket->getFirst()) KeyT(std::forward<KeyArgT>(
Key));
641 ::new (&TheBucket->getSecond()) ValueT(std::forward<Ts>(Args)...);
642 return {TheBucket,
true};
645 template <
typename KeyArgT,
typename... Ts>
646 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
647 auto [Bucket,
Inserted] = lookupOrInsertIntoBucket(
648 std::forward<KeyArgT>(
Key), std::forward<Ts>(Args)...);
649 return {makeIterator(Bucket),
Inserted};
652 iterator makeIterator(BucketT *TheBucket) {
654 getNumBuckets(), *
this);
657 const_iterator makeConstIterator(
const BucketT *TheBucket)
const {
659 getNumBuckets(), *
this);
662 unsigned getNumEntries()
const {
return derived().getNumEntries(); }
664 void setNumEntries(
unsigned Num) { derived().setNumEntries(Num); }
666 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
668 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
670 const BucketT *getBuckets()
const {
return derived().getBuckets(); }
672 BucketT *getBuckets() {
return derived().getBuckets(); }
674 Rep getRep()
const {
return derived().getRep(); }
676 const UsedT *getUsed()
const {
return derived().getUsed(); }
678 UsedT *getUsed() {
return derived().getUsed(); }
680 unsigned getNumBuckets()
const {
return derived().getNumBuckets(); }
682 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
684 const BucketT *getBucketsEnd()
const {
685 return getBuckets() + getNumBuckets();
689 unsigned NumBuckets = DerivedT::roundUpNumBuckets(MinNumBuckets);
691 Tmp.moveFrom(derived());
692 if (derived().maybeMoveFast(std::move(Tmp)))
698 template <
typename LookupKeyT>
699 BucketT *findBucketForInsertion(
const LookupKeyT &
Lookup,
700 BucketT *TheBucket) {
707 unsigned NewNumEntries = getNumEntries() + 1;
708 unsigned NumBuckets = getNumBuckets();
710 this->grow(NumBuckets * 2);
711 LookupBucketFor(
Lookup, TheBucket);
720 incrementNumEntries();
724 template <
typename LookupKeyT>
725 const BucketT *doFind(
const LookupKeyT &Val)
const {
726 auto [BucketsPtr,
U, NumBuckets] = getRep();
730 const unsigned Mask = NumBuckets - 1;
731 unsigned BucketNo = KeyInfoT::getHashValue(Val) &
Mask;
736 const BucketT *Bucket = BucketsPtr + BucketNo;
737 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
741 BucketNo = (BucketNo + 1) & Mask;
745 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
746 return const_cast<BucketT *
>(
753 template <
typename LookupKeyT>
754 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
755 auto [CBuckets,
U, NumBuckets] = getRep();
756 if (NumBuckets == 0) {
757 FoundBucket =
nullptr;
762 BucketT *BucketsPtr =
const_cast<BucketT *
>(CBuckets);
764 const unsigned Mask = NumBuckets - 1;
765 unsigned BucketNo = KeyInfoT::getHashValue(Val) &
Mask;
767 BucketT *ThisBucket = BucketsPtr + BucketNo;
771 FoundBucket = ThisBucket;
776 if (
LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
777 FoundBucket = ThisBucket;
782 BucketNo = (BucketNo + 1) & Mask;
802template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
807 if (
LHS.size() !=
RHS.size())
810 for (
auto &KV :
LHS) {
811 auto I =
RHS.find(KV.first);
812 if (
I ==
RHS.end() ||
I->second != KV.second)
822template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
830template <
typename KeyT,
typename ValueT,
831 typename KeyInfoT = DenseMapInfo<KeyT>,
833class DenseMap :
public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
834 KeyT, ValueT, KeyInfoT, BucketT> {
842 BucketT *Buckets =
nullptr;
843 UsedT *Used =
nullptr;
844 unsigned NumEntries = 0;
845 unsigned NumBuckets = 0;
847 explicit DenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
854 explicit DenseMap(
unsigned NumElementsToReserve = 0)
862 template <
typename InputIt>
867 template <
typename RangeT>
871 DenseMap(std::initializer_list<typename BaseT::value_type> Vals)
872 : DenseMap(Vals.
begin(), Vals.
end()) {}
901 unsigned getNumEntries()
const {
return NumEntries; }
903 void setNumEntries(
unsigned Num) {
NumEntries = Num; }
905 BucketT *getBuckets()
const {
return Buckets; }
907 typename BaseT::Rep getRep()
const {
return {Buckets,
Used, NumBuckets}; }
911 unsigned getNumBuckets()
const {
return NumBuckets; }
913 void deallocateBuckets() {
924 bool allocateBuckets(
unsigned Num) {
926 if (NumBuckets == 0) {
932 auto *Storage =
static_cast<char *
>(
935 Buckets =
reinterpret_cast<BucketT *
>(Storage);
938 assert(
sizeof(BucketT) * NumBuckets %
alignof(UsedT) == 0 &&
939 "used array would be misaligned");
940 Used =
reinterpret_cast<UsedT *
>(Storage +
sizeof(BucketT) * NumBuckets);
946 void kill() { deallocateBuckets(); }
948 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
950 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
953 bool maybeMoveFast(DenseMap &&Other) {
961 std::pair<bool, unsigned> planShrinkAndClear()
const {
962 unsigned NewNumBuckets = 0;
964 NewNumBuckets = std::max(64u, 1u << (
Log2_32_Ceil(NumEntries) + 1));
965 if (NewNumBuckets == NumBuckets)
967 return {
true, NewNumBuckets};
971template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
972 typename KeyInfoT = DenseMapInfo<KeyT>,
976 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
977 ValueT, KeyInfoT, BucketT> {
986 "InlineBuckets must be a power of 2.");
989 static constexpr unsigned InlineUsedWords =
993 unsigned NumEntries : 31;
997 alignas(BucketT)
char Buckets[
sizeof(BucketT) * InlineBuckets];
998 UsedT Used[InlineUsedWords];
1003 unsigned NumBuckets;
1012 SmallDenseMap(
unsigned NumBuckets,
typename BaseT::ExactBucketCount) {
1013 this->initWithExactBucketCount(NumBuckets);
1028 template <
typename InputIt>
1030 : SmallDenseMap(
std::distance(
I,
E)) {
1034 template <
typename RangeT>
1039 : SmallDenseMap(Vals.
begin(), Vals.
end()) {}
1043 deallocateBuckets();
1054 deallocateBuckets();
1062 static void relocateBucket(BucketT *Dst, BucketT *Src) {
1063 ::new (&Dst->getFirst())
KeyT(
std::
move(Src->getFirst()));
1064 ::new (&Dst->getSecond()) ValueT(
std::
move(Src->getSecond()));
1065 Src->getSecond().~ValueT();
1066 Src->getFirst().~
KeyT();
1070 unsigned TmpNumEntries =
RHS.NumEntries;
1071 RHS.NumEntries = NumEntries;
1072 NumEntries = TmpNumEntries;
1074 if (Small &&
RHS.Small) {
1078 UsedT *LU = getInlineUsed(), *RU = RHS.getInlineUsed();
1079 BucketT *LB = getInlineBuckets(), *RB = RHS.getInlineBuckets();
1080 for (unsigned I = 0; I != InlineBuckets; ++I) {
1081 bool L = llvm::densemap::detail::used(LU, I);
1082 bool R = llvm::densemap::detail::used(RU, I);
1085 alignas(BucketT) char Tmp[sizeof(BucketT)];
1086 BucketT *T = reinterpret_cast<BucketT *>(Tmp);
1087 relocateBucket(T, &LB[I]);
1088 relocateBucket(&LB[I], &RB[I]);
1089 relocateBucket(&RB[I], T);
1091 relocateBucket(&RB[I], &LB[I]);
1093 relocateBucket(&LB[I], &RB[I]);
1096 for (
unsigned W = 0; W != InlineUsedWords; ++W)
1100 if (!Small && !
RHS.Small) {
1105 SmallDenseMap &SmallSide =
Small ? *this :
RHS;
1106 SmallDenseMap &LargeSide =
Small ?
RHS : *
this;
1111 LargeRep TmpRep = LargeSide.storage.Large;
1112 LargeSide.Small =
true;
1114 UsedT *SU = SmallSide.getInlineUsed(), *LU = LargeSide.getInlineUsed();
1115 BucketT *SB = SmallSide.getInlineBuckets(),
1116 *LB = LargeSide.getInlineBuckets();
1117 for (
unsigned I = 0;
I != InlineBuckets; ++
I)
1119 relocateBucket(&LB[
I], &SB[
I]);
1120 for (
unsigned W = 0;
W != InlineUsedWords; ++
W)
1123 SmallSide.Small =
false;
1124 SmallSide.storage.Large = TmpRep;
1127 unsigned getNumEntries()
const {
return NumEntries; }
1129 void setNumEntries(
unsigned Num) {
1131 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1135 const BucketT *getInlineBuckets()
const {
1140 return reinterpret_cast<const BucketT *
>(storage.Inline.Buckets);
1143 BucketT *getInlineBuckets() {
1145 return reinterpret_cast<BucketT *
>(storage.Inline.Buckets);
1148 const UsedT *getInlineUsed()
const {
1150 return storage.Inline.Used;
1153 UsedT *getInlineUsed() {
1155 return storage.Inline.Used;
1158 const BucketT *getBuckets()
const {
1159 return Small ? getInlineBuckets() : storage.
Large.Buckets;
1162 typename BaseT::Rep getRep()
const {
1164 return {getInlineBuckets(), getInlineUsed(), InlineBuckets};
1165 return {storage.Large.Buckets, storage.Large.Used,
1166 storage.Large.NumBuckets};
1169 BucketT *getBuckets() {
1170 return const_cast<BucketT *
>(
1171 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1174 const UsedT *getUsed()
const {
1179 return const_cast<UsedT *
>(
1180 const_cast<const SmallDenseMap *
>(
this)->getUsed());
1183 unsigned getNumBuckets()
const {
1184 return Small ? InlineBuckets : storage.Large.NumBuckets;
1187 void deallocateBuckets() {
1190 if (Small || storage.Large.NumBuckets == 0)
1194 storage.Large.Buckets,
1197 storage.Large.NumBuckets = 0;
1200 bool allocateBuckets(
unsigned Num) {
1201 if (Num <= InlineBuckets) {
1206 auto *S =
static_cast<char *
>(
1209 storage.Large.Buckets =
reinterpret_cast<BucketT *
>(S);
1210 storage.Large.Used =
reinterpret_cast<UsedT *
>(S +
sizeof(BucketT) * Num);
1211 storage.Large.NumBuckets = Num;
1217 deallocateBuckets();
1219 storage.Large = LargeRep{
nullptr,
nullptr, 0};
1222 static unsigned roundUpNumBuckets(
unsigned MinNumBuckets) {
1223 if (MinNumBuckets <= InlineBuckets)
1224 return InlineBuckets;
1225 return std::max(64u,
1226 static_cast<unsigned>(
NextPowerOf2(MinNumBuckets - 1)));
1229 bool maybeMoveFast(SmallDenseMap &&Other) {
1235 storage.Large =
Other.storage.Large;
1236 Other.storage.Large.NumBuckets = 0;
1243 std::pair<bool, unsigned> planShrinkAndClear()
const {
1244 unsigned NewNumBuckets = 0;
1245 if (!this->
empty()) {
1247 if (NewNumBuckets > InlineBuckets)
1248 NewNumBuckets = std::max(64u, NewNumBuckets);
1250 bool Reuse =
Small ? NewNumBuckets <= InlineBuckets
1251 : NewNumBuckets == storage.Large.NumBuckets;
1254 return {
true, NewNumBuckets};
1258template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1261 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
true>;
1262 friend class DenseMapIterator<
KeyT, ValueT, KeyInfoT, Bucket,
false>;
1268 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1275 std::conditional_t<shouldReverseIterate<KeyT>(),
1276 std::reverse_iterator<pointer>,
pointer>;
1278 BucketItTy Ptr = {};
1279 BucketItTy End = {};
1282 pointer Buckets = {};
1285 DenseMapIterator(BucketItTy Pos, BucketItTy
E, pointer BucketsBase,
1286 const UsedT *U,
const DebugEpochBase &Epoch)
1287 : DebugEpochBase::HandleBase(&Epoch), Ptr(Pos), End(
E),
1288 Buckets(BucketsBase),
Used(
U) {
1289 assert(isHandleInSync() &&
"invalid construction!");
1296 unsigned NumBuckets,
bool IsEmpty,
1301 return makeEnd(Buckets, Used, NumBuckets, Epoch);
1303 DenseMapIterator Iter(R.begin(), R.end(), Buckets, Used, Epoch);
1304 Iter.AdvancePastEmptyBuckets();
1309 unsigned NumBuckets,
1312 return DenseMapIterator(R.end(), R.end(), Buckets, Used, Epoch);
1316 const UsedT *Used,
unsigned NumBuckets,
1320 return DenseMapIterator(BucketItTy(
P +
Offset), R.end(), Buckets, Used,
1327 template <
bool IsConstSrc,
1328 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1330 const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &
I)
1332 Buckets(
I.Buckets), Used(
I.Used) {}
1336 assert(Ptr != End &&
"dereferencing end() iterator");
1342 const DenseMapIterator &
RHS) {
1343 assert((!
LHS.getEpochAddress() ||
LHS.isHandleInSync()) &&
1344 "handle not in sync!");
1345 assert((!
RHS.getEpochAddress() ||
RHS.isHandleInSync()) &&
1346 "handle not in sync!");
1347 assert(
LHS.getEpochAddress() ==
RHS.getEpochAddress() &&
1348 "comparing incomparable iterators!");
1349 return LHS.Ptr ==
RHS.Ptr;
1353 const DenseMapIterator &
RHS) {
1359 assert(Ptr != End &&
"incrementing end() iterator");
1361 AdvancePastEmptyBuckets();
1366 DenseMapIterator tmp = *
this;
1372 void AdvancePastEmptyBuckets() {
1379 const size_t N = End - Buckets;
1380 size_t I = Ptr - Buckets;
1399 static auto maybeReverse(iterator_range<pointer>
Range) {
1400 if constexpr (shouldReverseIterate<KeyT>())
1407template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
1408[[nodiscard]]
inline size_t
1410 return X.getMemorySize();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
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_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
#define LLVM_ATTRIBUTE_NOINLINE
LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, mark a method "not for inl...
#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 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)
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,...
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.
LLVM_ATTRIBUTE_NOINLINE void copyFrom(const DerivedT &other)
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.
LLVM_ATTRIBUTE_NOINLINE void moveFrom(DerivedT &Other)
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
friend bool operator!=(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
DenseMapIterator & operator++()
pointer operator->() const
reference operator*() const
DenseMapIterator()=default
DenseMapIterator operator++(int)
DenseMapIterator(const DenseMapIterator< KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc > &I)
static DenseMapIterator makeIterator(pointer P, pointer Buckets, const UsedT *Used, unsigned NumBuckets, const DebugEpochBase &Epoch)
ptrdiff_t difference_type
friend bool operator==(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
std::forward_iterator_tag iterator_category
static DenseMapIterator makeBegin(pointer Buckets, const UsedT *Used, unsigned NumBuckets, bool IsEmpty, const DebugEpochBase &Epoch)
static DenseMapIterator makeEnd(pointer Buckets, const UsedT *Used, unsigned NumBuckets, const DebugEpochBase &Epoch)
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)
This is the common base class of value handles.
constexpr char IsConst[]
Key for Kernel::Arg::Metadata::mIsConst.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
void setUsed(UsedT *U, size_t I)
constexpr size_t usedWords(size_t N)
LLVM_ATTRIBUTE_ALWAYS_INLINE void forEachUsed(const UsedT *U, unsigned N, Fn Func)
constexpr size_t allocAlign()
size_t allocBytes(unsigned Num)
bool used(const UsedT *U, size_t I)
void unsetUsed(UsedT *U, size_t I)
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.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
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.
auto reverse(ContainerTy &&C)
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
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.
An information struct used to provide DenseMap with the various necessary components for a given valu...
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