16 #ifndef LLVM_ADT_MAPVECTOR_H 17 #define LLVM_ADT_MAPVECTOR_H 25 #include <type_traits> 34 template<
typename KeyT,
typename ValueT,
35 typename MapType = DenseMap<KeyT, unsigned>,
36 typename VectorType = std::vector<std::pair<KeyT, ValueT>>>
42 std::is_integral<typename MapType::mapped_type>::value,
43 "The mapped_type of the specified Map must be an integral type");
49 using iterator =
typename VectorType::iterator;
57 return std::move(Vector);
65 Map.reserve(NumEntries);
66 Vector.reserve(NumEntries);
80 return Vector.empty();
83 std::pair<KeyT, ValueT> &
front() {
return Vector.front(); }
84 const std::pair<KeyT, ValueT> &
front()
const {
return Vector.front(); }
85 std::pair<KeyT, ValueT> &
back() {
return Vector.back(); }
86 const std::pair<KeyT, ValueT> &
back()
const {
return Vector.back(); }
99 std::pair<KeyT, typename MapType::mapped_type> Pair = std::make_pair(Key, 0);
100 std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
101 auto &
I = Result.first->second;
103 Vector.push_back(std::make_pair(Key, ValueT()));
104 I = Vector.size() - 1;
106 return Vector[
I].second;
111 static_assert(std::is_copy_constructible<ValueT>::value,
112 "Cannot call lookup() if ValueT is not copyable.");
113 typename MapType::const_iterator Pos = Map.find(Key);
114 return Pos == Map.end()? ValueT() : Vector[Pos->second].second;
117 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
118 std::pair<KeyT, typename MapType::mapped_type> Pair = std::make_pair(KV.first, 0);
119 std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
120 auto &
I = Result.first->second;
122 Vector.push_back(std::make_pair(KV.first, KV.second));
123 I = Vector.size() - 1;
124 return std::make_pair(std::prev(
end()),
true);
126 return std::make_pair(
begin() +
I,
false);
129 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
131 std::pair<KeyT, typename MapType::mapped_type> Pair = std::make_pair(KV.first, 0);
132 std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
133 auto &
I = Result.first->second;
135 Vector.push_back(std::move(KV));
136 I = Vector.size() - 1;
137 return std::make_pair(std::prev(
end()),
true);
139 return std::make_pair(
begin() +
I,
false);
143 typename MapType::const_iterator Pos = Map.find(Key);
144 return Pos == Map.end()? 0 : 1;
148 typename MapType::const_iterator Pos = Map.find(Key);
149 return Pos == Map.end()? Vector.end() :
150 (Vector.begin() + Pos->second);
154 typename MapType::const_iterator Pos = Map.find(Key);
155 return Pos == Map.end()? Vector.end() :
156 (Vector.begin() + Pos->second);
161 typename MapType::iterator Pos = Map.find(Vector.back().first);
173 typename VectorType::iterator
erase(
typename VectorType::iterator Iterator) {
174 Map.erase(Iterator->first);
175 auto Next = Vector.erase(Iterator);
176 if (Next == Vector.end())
180 size_t Index = Next - Vector.begin();
181 for (
auto &
I : Map) {
182 assert(
I.second != Index &&
"Index was already erased!");
183 if (
I.second > Index)
193 auto Iterator =
find(Key);
194 if (Iterator ==
end())
207 template <
typename KeyT,
typename ValueT,
typename MapType,
typename VectorType>
208 template <
class Function>
210 auto O = Vector.begin();
211 for (
auto I =
O,
E = Vector.end();
I !=
E; ++
I) {
221 Map[
O->first] =
O - Vector.begin();
226 Vector.erase(
O, Vector.end());
231 template <
typename KeyT,
typename ValueT,
unsigned N>
233 :
MapVector<KeyT, ValueT, SmallDenseMap<KeyT, unsigned, N>,
234 SmallVector<std::pair<KeyT, ValueT>, N>> {
239 #endif // LLVM_ADT_MAPVECTOR_H const_iterator begin() const
const_reverse_iterator rend() const
This class represents lattice values for constants.
void pop_back()
Remove the last element from the vector.
This class implements a map that also provides access to all stored values in a deterministic order...
VectorType::iterator erase(typename VectorType::iterator Iterator)
Remove the element given by Iterator.
std::pair< KeyT, ValueT > & back()
A MapVector that performs no allocations if smaller than a certain size.
ValueT & operator[](const KeyT &Key)
typename std::vector< std::pair< AssertingVH< Instruction >, AssertingVH< Value > >> ::const_reverse_iterator const_reverse_iterator
iterator find(const KeyT &Key)
typename std::vector< std::pair< AssertingVH< Instruction >, AssertingVH< Value > >> ::reverse_iterator reverse_iterator
typename std::vector< std::pair< AssertingVH< Instruction >, AssertingVH< Value > >> ::value_type value_type
void remove_if(Predicate Pred)
Remove the elements that match the predicate.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const_iterator find(const KeyT &Key) const
const std::pair< KeyT, ValueT > & back() const
VectorType takeVector()
Clear the MapVector and return the underlying vector.
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
typename std::vector< std::pair< AssertingVH< Instruction >, AssertingVH< Value > >> ::const_iterator const_iterator
size_type count(const KeyT &Key) const
const std::pair< KeyT, ValueT > & front() const
reverse_iterator rbegin()
typename std::vector< std::pair< AssertingVH< Instruction >, AssertingVH< Value > >> ::iterator iterator
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
ValueT lookup(const KeyT &Key) const
std::pair< KeyT, ValueT > & front()
void reserve(size_type NumEntries)
Grow the MapVector so that it can contain at least NumEntries items before resizing again...
const_reverse_iterator rbegin() const
size_type erase(const KeyT &Key)
Remove all elements with the key value Key.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
typename std::vector< std::pair< AssertingVH< Instruction >, AssertingVH< Value > >> ::size_type size_type
const_iterator end() const
void swap(MapVector &RHS)