14 #ifndef LLVM_ADT_SMALLVECTOR_H
15 #define LLVM_ADT_SMALLVECTOR_H
43 void grow_pod(
void *FirstEl,
size_t MinSizeInBytes,
size_t TSize);
65 template <
typename T,
typename =
void>
80 void grow_pod(
size_t MinSizeInBytes,
size_t TSize) {
87 return BeginX ==
static_cast<const void*
>(&FirstEl);
169 template <
typename T,
bool isPodLike>
184 template<
typename It1,
typename It2>
185 static It2
move(It1
I, It1 E, It2 Dest) {
186 #if LLVM_HAS_RVALUE_REFERENCES
187 for (; I != E; ++
I, ++Dest)
188 *Dest = ::std::move(*I);
191 return ::std::copy(I, E, Dest);
199 template<
typename It1,
typename It2>
201 #if LLVM_HAS_RVALUE_REFERENCES
203 *--Dest = ::std::move(*--E);
206 return ::std::copy_backward(I, E, Dest);
212 template<
typename It1,
typename It2>
214 #if LLVM_HAS_RVALUE_REFERENCES
215 for (; I != E; ++
I, ++Dest)
216 ::
new ((
void*) &*Dest)
T(::std::move(*I));
218 ::std::uninitialized_copy(I, E, Dest);
224 template<
typename It1,
typename It2>
226 std::uninitialized_copy(I, E, Dest);
233 void grow(
size_t MinSize = 0);
239 ::new ((
void*) this->
end())
T(Elt);
247 #if LLVM_HAS_RVALUE_REFERENCES
251 ::new ((
void*) this->
end())
T(::std::
move(Elt));
267 template <
typename T,
bool isPodLike>
269 size_t CurCapacity = this->
capacity();
270 size_t CurSize = this->
size();
272 size_t NewCapacity = size_t(
NextPowerOf2(CurCapacity+2));
273 if (NewCapacity < MinSize)
274 NewCapacity = MinSize;
275 T *NewElts =
static_cast<T*
>(
malloc(NewCapacity*
sizeof(
T)));
287 this->
setEnd(NewElts+CurSize);
289 this->CapacityX = this->
begin()+NewCapacity;
295 template <
typename T>
305 template<
typename It1,
typename It2>
306 static It2
move(It1
I, It1 E, It2 Dest) {
307 return ::std::copy(I, E, Dest);
313 template<
typename It1,
typename It2>
315 return ::std::copy_backward(I, E, Dest);
320 template<
typename It1,
typename It2>
328 template<
typename It1,
typename It2>
331 std::uninitialized_copy(I, E, Dest);
336 template<
typename T1,
typename T2>
341 memcpy(Dest, I, (E-I)*
sizeof(
T));
346 void grow(
size_t MinSize = 0) {
351 if (this->EndX < this->CapacityX) {
370 template <
typename T>
372 typedef SmallVectorTemplateBase<T, isPodLike<T>::value >
SuperClass;
402 if (N < this->
size()) {
405 }
else if (N > this->
size()) {
408 std::uninitialized_fill(this->
end(), this->
begin()+N,
T());
414 if (N < this->
size()) {
417 }
else if (N > this->
size()) {
420 std::uninitialized_fill(this->
end(), this->
begin()+N, NV);
431 #if LLVM_HAS_RVALUE_REFERENCES
432 T Result = ::std::move(this->
back());
434 T Result = this->
back();
444 template<
typename in_iter>
445 void append(in_iter in_start, in_iter in_end) {
446 size_type NumInputs = std::distance(in_start, in_end);
454 std::uninitialized_copy(in_start, in_end, this->
end());
466 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
475 std::uninitialized_fill(this->
begin(), this->
end(), Elt);
479 assert(I >= this->
begin() &&
"Iterator to erase is out of bounds.");
480 assert(I < this->
end() &&
"Erasing at past-the-end iterator.");
484 this->
move(I+1, this->
end(), I);
491 assert(S >= this->
begin() &&
"Range to erase is out of bounds.");
492 assert(S <= E &&
"Trying to erase invalid range.");
493 assert(E <= this->
end() &&
"Trying to erase past the end.");
504 #if LLVM_HAS_RVALUE_REFERENCES
506 if (I == this->
end()) {
508 return this->
end()-1;
511 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
512 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
514 if (this->EndX < this->CapacityX) {
516 ::new ((
void*) this->
end())
T(::std::
move(this->
back()));
524 if (I <= EltPtr && EltPtr < this->
EndX)
527 *I = ::std::
move(*EltPtr);
530 size_t EltNo = I-this->
begin();
532 I = this->begin()+EltNo;
538 if (I == this->
end()) {
540 return this->
end()-1;
543 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
544 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
546 if (this->EndX < this->CapacityX) {
548 ::new ((
void*) this->
end())
T(this->
back());
555 const T *EltPtr = &Elt;
556 if (I <= EltPtr && EltPtr < this->
EndX)
562 size_t EltNo = I-this->
begin();
564 I = this->
begin()+EltNo;
570 size_t InsertElt = I - this->
begin();
572 if (I == this->
end()) {
574 return this->
begin()+InsertElt;
577 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
578 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
581 reserve(static_cast<unsigned>(this->
size() + NumToInsert));
584 I = this->
begin()+InsertElt;
590 if (
size_t(this->
end()-I) >= NumToInsert) {
591 T *OldEnd = this->
end();
597 std::fill_n(I, NumToInsert, Elt);
605 T *OldEnd = this->
end();
607 size_t NumOverwritten = OldEnd-
I;
611 std::fill_n(I, NumOverwritten, Elt);
614 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
618 template<
typename ItTy>
621 size_t InsertElt = I - this->
begin();
623 if (I == this->
end()) {
625 return this->
begin()+InsertElt;
628 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
629 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
631 size_t NumToInsert = std::distance(From, To);
634 reserve(static_cast<unsigned>(this->
size() + NumToInsert));
637 I = this->
begin()+InsertElt;
643 if (
size_t(this->
end()-I) >= NumToInsert) {
644 T *OldEnd = this->
end();
650 std::copy(From, To, I);
658 T *OldEnd = this->
end();
660 size_t NumOverwritten = OldEnd-
I;
664 for (
T *J = I; NumOverwritten > 0; --NumOverwritten) {
676 #if LLVM_HAS_RVALUE_REFERENCES
681 if (this->
size() != RHS.size())
return false;
685 return !(*
this == RHS);
689 return std::lexicographical_compare(this->
begin(), this->
end(),
690 RHS.begin(), RHS.end());
709 template <
typename T>
711 if (
this == &RHS)
return;
714 if (!this->
isSmall() && !RHS.isSmall()) {
717 std::swap(this->CapacityX, RHS.CapacityX);
721 this->
grow(RHS.size());
722 if (this->
size() > RHS.capacity())
723 RHS.grow(this->size());
726 size_t NumShared = this->
size();
727 if (NumShared > RHS.size()) NumShared = RHS.size();
728 for (
unsigned i = 0; i !=
static_cast<unsigned>(NumShared); ++i)
732 if (this->
size() > RHS.size()) {
733 size_t EltDiff = this->
size() - RHS.size();
735 RHS.setEnd(RHS.end()+EltDiff);
738 }
else if (RHS.size() > this->
size()) {
739 size_t EltDiff = RHS.size() - this->
size();
743 RHS.setEnd(RHS.begin()+NumShared);
747 template <
typename T>
751 if (
this == &RHS)
return *
this;
755 size_t RHSSize = RHS.size();
756 size_t CurSize = this->
size();
757 if (CurSize >= RHSSize) {
761 NewEnd = std::copy(RHS.begin(), RHS.begin()+RHSSize, this->
begin());
763 NewEnd = this->
begin();
782 }
else if (CurSize) {
784 std::copy(RHS.begin(), RHS.begin()+CurSize, this->
begin());
789 this->
begin()+CurSize);
796 #if LLVM_HAS_RVALUE_REFERENCES
797 template <
typename T>
800 if (
this == &RHS)
return *
this;
803 if (!RHS.isSmall()) {
806 this->
BeginX = RHS.BeginX;
807 this->
EndX = RHS.EndX;
808 this->CapacityX = RHS.CapacityX;
815 size_t RHSSize = RHS.size();
816 size_t CurSize = this->
size();
817 if (CurSize >= RHSSize) {
821 NewEnd = this->
move(RHS.begin(), RHS.end(), NewEnd);
843 }
else if (CurSize) {
845 this->
move(RHS.begin(), RHS.end(), this->
begin());
850 this->
begin()+CurSize);
864 template <
typename T,
unsigned N>
879 template <
typename T,
unsigned N>
889 this->assign(Size,
Value);
892 template<
typename ItTy>
907 #if LLVM_HAS_RVALUE_REFERENCES
913 const SmallVector &operator=(SmallVector &&RHS) {
921 template<
typename T,
unsigned N>
937 template<
typename T,
unsigned N>
void set_size(unsigned N)
std::reverse_iterator< iterator > reverse_iterator
void push_back(const T &Elt)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
#define LLVM_ATTRIBUTE_UNUSED_RESULT
static It2 move_backward(It1 I, It1 E, It2 Dest)
static It2 move(It1 I, It1 E, It2 Dest)
iterator insert(iterator I, const T &Elt)
iterator insert(iterator I, size_type NumToInsert, const T &Elt)
static void uninitialized_move(It1 I, It1 E, It2 Dest)
void append(size_type NumInputs, const T &Elt)
size_t capacity_in_bytes() const
capacity_in_bytes - This returns capacity()*sizeof(T).
void resize(unsigned N, const T &NV)
const T & const_reference
static It2 move_backward(It1 I, It1 E, It2 Dest)
void swap(OwningPtr< T > &a, OwningPtr< T > &b)
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
const_iterator end() const
SmallVectorTemplateBase(size_t Size)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
void assign(unsigned NumElts, const T &Elt)
const_reverse_iterator rend() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
SmallVectorTemplateBase(size_t Size)
const SmallVector & operator=(const SmallVector &RHS)
ptrdiff_t difference_type
static It2 move(It1 I, It1 E, It2 Dest)
const_reference front() const
* if(!EatIfPresent(lltok::kw_thread_local)) return false
bool operator==(const SmallVectorImpl &RHS) const
reference operator[](unsigned idx)
void swap(SmallVectorImpl &RHS)
const_iterator begin() const
const_reference back() const
void grow(size_t MinSize=0)
bool operator!=(const SmallVectorImpl &RHS) const
bool operator<(const SmallVectorImpl &RHS) const
const_reference operator[](unsigned idx) const
SmallVectorBase(void *FirstEl, size_t Size)
iterator erase(iterator S, iterator E)
void append(in_iter in_start, in_iter in_end)
uint64_t NextPowerOf2(uint64_t A)
iterator erase(iterator I)
const_iterator capacity_ptr() const
friend struct SmallVectorStorage
SmallVector(ItTy S, ItTy E)
void grow(size_t MinSize=0)
std::reverse_iterator< const_iterator > const_reverse_iterator
iterator insert(iterator I, ItTy From, ItTy To)
#define LLVM_DELETED_FUNCTION
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
SmallVectorImpl & operator=(const SmallVectorImpl &RHS)
SuperClass::size_type size_type
static void destroy_range(T *S, T *E)
void push_back(const T &Elt)
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
void *malloc(size_t size);
size_t size_in_bytes() const
size_in_bytes - This returns size()*sizeof(T).
SmallVectorTemplateCommon(size_t Size)
SmallVector(const SmallVector &RHS)
reverse_iterator rbegin()
LLVM Value Representation.
static void uninitialized_move(It1 I, It1 E, It2 Dest)
void grow_pod(size_t MinSizeInBytes, size_t TSize)
static void destroy_range(T *, T *)
static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest)
void grow_pod(void *FirstEl, size_t MinSizeInBytes, size_t TSize)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
size_type max_size() const
void resetToSmall()
resetToSmall - Put this vector in a state of being small.
const_pointer data() const
data - Return a pointer to the vector's buffer, even if empty().
SmallVector(unsigned Size, const T &Value=T())
const_reverse_iterator rbegin() const