17#ifndef LLVM_ADT_MAPVECTOR_H
18#define LLVM_ADT_MAPVECTOR_H
33template <
typename KeyT,
typename ValueT,
42 using iterator =
typename VectorType::iterator;
50 return std::move(Vector);
61 Map.reserve(NumEntries);
62 Vector.reserve(NumEntries);
72 return Vector.rbegin();
77 [[nodiscard]]
bool empty()
const {
return Vector.empty(); }
79 [[nodiscard]] std::pair<KeyT, ValueT> &
front() {
return Vector.front(); }
80 [[nodiscard]]
const std::pair<KeyT, ValueT> &
front()
const {
81 return Vector.front();
83 [[nodiscard]] std::pair<KeyT, ValueT> &
back() {
return Vector.back(); }
84 [[nodiscard]]
const std::pair<KeyT, ValueT> &
back()
const {
99 return try_emplace_impl(
Key).first->second;
104 static_assert(std::is_copy_constructible_v<ValueT>,
105 "Cannot call lookup() if ValueT is not copyable.");
106 typename MapType::const_iterator Pos = Map.find(
Key);
107 return Pos == Map.end()? ValueT() : Vector[Pos->second].second;
110 template <
typename... Ts>
112 return try_emplace_impl(
Key, std::forward<Ts>(Args)...);
114 template <
typename... Ts>
116 return try_emplace_impl(std::move(
Key), std::forward<Ts>(Args)...);
119 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
120 return try_emplace_impl(KV.first, KV.second);
122 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
123 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
126 template <
typename V>
130 Ret.first->second = std::forward<V>(Val);
133 template <
typename V>
137 Ret.first->second = std::forward<V>(Val);
142 return Map.find(
Key) != Map.end();
150 typename MapType::const_iterator Pos = Map.find(
Key);
151 return Pos == Map.end()? Vector.end() :
152 (Vector.begin() + Pos->second);
156 typename MapType::const_iterator Pos = Map.find(
Key);
157 return Pos == Map.end()? Vector.end() :
158 (Vector.begin() + Pos->second);
163 typename MapType::iterator Pos = Map.find(Vector.back().first);
175 typename VectorType::iterator
erase(
typename VectorType::iterator Iterator) {
176 Map.erase(Iterator->first);
177 auto Next = Vector.erase(Iterator);
178 if (
Next == Vector.end())
182 size_t Index =
Next - Vector.begin();
183 for (
auto &
I : Map) {
184 assert(
I.second != Index &&
"Index was already erased!");
185 if (
I.second > Index)
196 if (Iterator ==
end())
213 std::is_integral_v<typename MapType::mapped_type>,
214 "The mapped_type of the specified Map must be an integral type");
216 template <
typename KeyArgT,
typename... Ts>
217 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
218 auto [It, Inserted] = Map.try_emplace(
Key);
220 It->second = Vector.size();
221 Vector.emplace_back(std::piecewise_construct,
222 std::forward_as_tuple(std::forward<KeyArgT>(
Key)),
223 std::forward_as_tuple(std::forward<Ts>(Args)...));
224 return {std::prev(
end()),
true};
226 return {
begin() + It->second,
false};
230template <
typename KeyT,
typename ValueT,
typename MapType,
typename VectorType>
231template <
class Function>
233 auto O = Vector.begin();
234 for (
auto I = O,
E = Vector.end();
I !=
E; ++
I) {
244 Map[O->first] = O - Vector.begin();
249 Vector.erase(O, Vector.end());
254template <
typename KeyT,
typename ValueT,
unsigned N>
256 :
MapVector<KeyT, ValueT, SmallDenseMap<KeyT, unsigned, N>,
257 SmallVector<std::pair<KeyT, ValueT>, N>> {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class implements a map that also provides access to all stored values in a deterministic order.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
size_type count(const KeyT &Key) const
typename VectorType::iterator iterator
void pop_back()
Remove the last element from the vector.
const_reverse_iterator rbegin() const
void swap(MapVector &RHS)
ValueT & operator[](const KeyT &Key)
const_iterator end() const
VectorType::iterator erase(typename VectorType::iterator Iterator)
Remove the element given by Iterator.
std::pair< iterator, bool > insert_or_assign(KeyT &&Key, V &&Val)
VectorType takeVector()
Clear the MapVector and return the underlying vector.
typename VectorType::size_type size_type
const std::pair< KeyT, ValueT > & back() const
const std::pair< KeyT, ValueT > & front() const
typename VectorType::const_reverse_iterator const_reverse_iterator
typename VectorType::value_type value_type
iterator find(const KeyT &Key)
void remove_if(Predicate Pred)
Remove the elements that match the predicate.
bool contains(const KeyT &Key) const
const_iterator begin() const
std::pair< iterator, bool > insert_or_assign(const KeyT &Key, V &&Val)
const_iterator find(const KeyT &Key) const
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ArrayRef< value_type > getArrayRef() const
Returns an array reference of the underlying vector.
ValueT lookup(const KeyT &Key) const
void reserve(size_type NumEntries)
Grow the MapVector so that it can contain at least NumEntries items before resizing again.
typename VectorType::reverse_iterator reverse_iterator
size_type erase(const KeyT &Key)
Remove all elements with the key value Key.
typename VectorType::const_iterator const_iterator
std::pair< KeyT, ValueT > & front()
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
const_reverse_iterator rend() const
reverse_iterator rbegin()
std::pair< KeyT, ValueT > & back()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Base class of all SIMD vector types.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionAddr VTableAddr Next
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A MapVector that performs no allocations if smaller than a certain size.