10 #ifndef LLVM_ADT_TINYPTRVECTOR_H
11 #define LLVM_ADT_TINYPTRVECTOR_H
25 template <
typename EltTy>
38 if (
VecTy *V = Val.template dyn_cast<VecTy*>())
43 if (
VecTy *V = Val.template dyn_cast<VecTy*>())
56 if (Val.template is<EltTy>()) {
60 Val =
new VecTy(*RHS.Val.template get<VecTy*>());
65 if (RHS.Val.template is<EltTy>()) {
66 Val.template get<VecTy*>()->
clear();
69 *Val.template get<VecTy*>() = *RHS.Val.template get<VecTy*>();
75 RHS.Val = (EltTy)
nullptr;
88 if (
VecTy *V = Val.template dyn_cast<VecTy*>()) {
89 if (RHS.Val.template is<EltTy>()) {
91 V->push_back(RHS.front());
98 RHS.Val = (EltTy)
nullptr;
114 if (Val.template is<EltTy>())
116 return *Val.template get<VecTy*>();
123 if (Val.template is<EltTy>())
125 return *Val.template get<VecTy*>();
131 if (Val.
isNull())
return true;
132 if (
VecTy *Vec = Val.template dyn_cast<VecTy*>())
140 if (Val.template is<EltTy>())
142 return Val.template get<VecTy*>()->
size();
149 if (Val.template is<EltTy>())
152 return Val.template get<VecTy *>()->
begin();
156 if (Val.template is<EltTy>())
159 return Val.template get<VecTy *>()->
end();
171 assert(!Val.
isNull() &&
"can't index into an empty vector");
172 if (EltTy V = Val.template dyn_cast<EltTy>()) {
173 assert(i == 0 &&
"tinyvector index out of range");
177 assert(i < Val.template get<VecTy*>()->size() &&
178 "tinyvector index out of range");
179 return (*Val.template get<VecTy*>())[i];
183 assert(!
empty() &&
"vector empty");
184 if (EltTy V = Val.template dyn_cast<EltTy>())
186 return Val.template get<VecTy*>()->
front();
190 assert(!
empty() &&
"vector empty");
191 if (EltTy V = Val.template dyn_cast<EltTy>())
193 return Val.template get<VecTy*>()->
back();
197 assert(NewVal &&
"Can't add a null value");
206 if (EltTy V = Val.template dyn_cast<EltTy>()) {
208 Val.template get<VecTy*>()->
push_back(V);
212 Val.template get<VecTy*>()->
push_back(NewVal);
217 if (Val.template is<EltTy>())
218 Val = (EltTy)
nullptr;
219 else if (
VecTy *Vec = Val.template get<VecTy*>())
225 if (Val.template is<EltTy>()) {
226 Val = (EltTy)
nullptr;
227 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
235 assert(I >=
begin() &&
"Iterator to erase is out of bounds.");
236 assert(I <
end() &&
"Erasing at past-the-end iterator.");
239 if (Val.template is<EltTy>()) {
241 Val = (EltTy)
nullptr;
242 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
245 return Vec->erase(I);
251 assert(S >=
begin() &&
"Range to erase is out of bounds.");
252 assert(S <= E &&
"Trying to erase invalid range.");
253 assert(E <=
end() &&
"Trying to erase past the end.");
255 if (Val.template is<EltTy>()) {
256 if (S ==
begin() && S != E)
257 Val = (EltTy)
nullptr;
258 }
else if (
VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
259 return Vec->erase(S, E);
265 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
266 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
269 return std::prev(
end());
271 assert(!Val.
isNull() &&
"Null value with non-end insert iterator.");
272 if (EltTy V = Val.template dyn_cast<EltTy>()) {
273 assert(I ==
begin());
279 return Val.template get<VecTy*>()->
insert(I, Elt);
282 template<
typename ItTy>
284 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
285 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
290 ptrdiff_t Offset = I -
begin();
292 if (std::next(From) == To) {
298 }
else if (EltTy V = Val.template dyn_cast<EltTy>()) {
300 Val.template get<VecTy*>()->
push_back(V);
302 return Val.template get<VecTy*>()->
insert(
begin() + Offset, From, To);
const_iterator end() const
TinyPtrVector(const TinyPtrVector &RHS)
const EltTy * const_iterator
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
iterator erase(iterator I)
EltTy operator[](unsigned i) const
TinyPtrVector & operator=(const TinyPtrVector &RHS)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
llvm::PointerUnion< EltTy, VecTy * > PtrUnion
TinyPtrVector(ArrayRef< EltTy > Elts)
Constructor from an ArrayRef.
iterator insert(iterator I, const EltTy &Elt)
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
LLVM Basic Block Representation.
void push_back(EltTy NewVal)
PT1 const * getAddrOfPtr1() const
If the union is set to the first pointer type get an address pointing to it.
llvm::SmallVector< EltTy, 4 > VecTy
bool isNull() const
isNull - Return true if the pointer held in the union is null, regardless of which type it is...
TinyPtrVector(TinyPtrVector &&RHS)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
TinyPtrVector & operator=(TinyPtrVector &&RHS)
const_iterator begin() const
iterator erase(iterator S, iterator E)
VecTy::value_type value_type
iterator insert(iterator I, ItTy From, ItTy To)