14 #ifndef LLVM_ADT_SMALLVECTOR_H
15 #define LLVM_ADT_SMALLVECTOR_H
27 #include <initializer_list>
31 #include <type_traits>
47 void grow_pod(
void *FirstEl,
size_t MinSizeInBytes,
size_t TSize);
66 template <
typename T,
typename =
void>
81 void grow_pod(
size_t MinSizeInBytes,
size_t TSize) {
88 return BeginX ==
static_cast<const void*
>(&FirstEl);
178 template <
typename T,
bool isPodLike>
192 template<
typename It1,
typename It2>
194 std::uninitialized_copy(std::make_move_iterator(I),
195 std::make_move_iterator(E), Dest);
200 template<
typename It1,
typename It2>
202 std::uninitialized_copy(I, E, Dest);
208 void grow(
size_t MinSize = 0);
214 ::new ((
void*) this->
end())
T(Elt);
221 ::new ((
void*) this->
end())
T(::std::move(Elt));
232 template <
typename T,
bool isPodLike>
234 size_t CurCapacity = this->capacity();
235 size_t CurSize = this->size();
238 if (NewCapacity < MinSize)
239 NewCapacity = MinSize;
240 T *NewElts =
static_cast<T*
>(malloc(NewCapacity*
sizeof(
T)));
243 this->uninitialized_move(this->
begin(), this->
end(), NewElts);
246 destroy_range(this->
begin(), this->
end());
249 if (!this->isSmall())
252 this->setEnd(NewElts+CurSize);
253 this->BeginX = NewElts;
254 this->CapacityX = this->
begin()+NewCapacity;
260 template <
typename T>
270 template<
typename It1,
typename It2>
278 template<
typename It1,
typename It2>
281 std::uninitialized_copy(I, E, Dest);
286 template <
typename T1,
typename T2>
289 typename std::enable_if<std::is_same<
typename std::remove_const<T1>::type,
290 T2>::value>::type * =
nullptr) {
296 memcpy(Dest, I, (E - I) *
sizeof(
T));
301 void grow(
size_t MinSize = 0) {
309 memcpy(this->
end(), &Elt,
sizeof(
T));
320 template <
typename T>
321 class SmallVectorImpl :
public SmallVectorTemplateBase<T, isPodLike<T>::value> {
322 using SuperClass = SmallVectorTemplateBase<T, isPodLike<T>::value>;
353 if (N < this->
size()) {
356 }
else if (N > this->
size()) {
359 for (
auto I = this->
end(),
E = this->
begin() + N;
I !=
E; ++
I)
366 if (N < this->
size()) {
369 }
else if (N > this->
size()) {
372 std::uninitialized_fill(this->
end(), this->
begin()+N, NV);
383 T Result = ::std::move(this->
back());
391 template <
typename in_iter,
392 typename =
typename std::enable_if<std::is_convertible<
393 typename std::iterator_traits<in_iter>::iterator_category,
394 std::input_iterator_tag>::value>::type>
395 void append(in_iter in_start, in_iter in_end) {
396 size_type NumInputs = std::distance(in_start, in_end);
413 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
417 void append(std::initializer_list<T> IL) {
418 append(IL.begin(), IL.end());
429 std::uninitialized_fill(this->
begin(), this->
end(), Elt);
432 template <
typename in_iter,
433 typename =
typename std::enable_if<std::is_convertible<
434 typename std::iterator_traits<in_iter>::iterator_category,
435 std::input_iterator_tag>::value>::type>
436 void assign(in_iter in_start, in_iter in_end) {
441 void assign(std::initializer_list<T> IL) {
450 assert(I >= this->
begin() &&
"Iterator to erase is out of bounds.");
451 assert(I < this->
end() &&
"Erasing at past-the-end iterator.");
455 std::move(I+1, this->
end(), I);
466 assert(S >= this->
begin() &&
"Range to erase is out of bounds.");
467 assert(S <= E &&
"Trying to erase invalid range.");
468 assert(E <= this->
end() &&
"Trying to erase past the end.");
480 if (I == this->
end()) {
482 return this->
end()-1;
485 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
486 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
489 size_t EltNo = I-this->
begin();
491 I = this->
begin()+EltNo;
494 ::new ((
void*) this->
end())
T(::std::move(this->
back()));
496 std::move_backward(I, this->
end()-1, this->
end());
502 if (I <= EltPtr && EltPtr < this->
EndX)
505 *I = ::std::move(*EltPtr);
510 if (I == this->
end()) {
512 return this->
end()-1;
515 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
516 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
519 size_t EltNo = I-this->
begin();
521 I = this->
begin()+EltNo;
523 ::new ((
void*) this->
end())
T(std::move(this->
back()));
525 std::move_backward(I, this->
end()-1, this->
end());
530 const T *EltPtr = &Elt;
531 if (I <= EltPtr && EltPtr < this->
EndX)
540 size_t InsertElt = I - this->
begin();
542 if (I == this->
end()) {
544 return this->
begin()+InsertElt;
547 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
548 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
554 I = this->
begin()+InsertElt;
560 if (
size_t(this->
end()-I) >= NumToInsert) {
561 T *OldEnd = this->
end();
562 append(std::move_iterator<iterator>(this->
end() - NumToInsert),
563 std::move_iterator<iterator>(this->
end()));
566 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
568 std::fill_n(I, NumToInsert, Elt);
576 T *OldEnd = this->
end();
578 size_t NumOverwritten = OldEnd-
I;
582 std::fill_n(I, NumOverwritten, Elt);
585 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
589 template <
typename ItTy,
590 typename =
typename std::enable_if<std::is_convertible<
591 typename std::iterator_traits<ItTy>::iterator_category,
592 std::input_iterator_tag>::value>::type>
595 size_t InsertElt = I - this->
begin();
597 if (I == this->
end()) {
599 return this->
begin()+InsertElt;
602 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
603 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
605 size_t NumToInsert = std::distance(From, To);
611 I = this->
begin()+InsertElt;
617 if (
size_t(this->
end()-I) >= NumToInsert) {
618 T *OldEnd = this->
end();
619 append(std::move_iterator<iterator>(this->
end() - NumToInsert),
620 std::move_iterator<iterator>(this->
end()));
623 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
625 std::copy(From, To, I);
633 T *OldEnd = this->
end();
635 size_t NumOverwritten = OldEnd-
I;
639 for (
T *J = I; NumOverwritten > 0; --NumOverwritten) {
650 insert(I, IL.begin(), IL.end());
656 ::new ((
void *)this->
end())
T(std::forward<ArgTypes>(
Args)...);
665 if (this->
size() != RHS.size())
return false;
669 return !(*
this == RHS);
673 return std::lexicographical_compare(this->
begin(), this->
end(),
674 RHS.begin(), RHS.end());
692 template <
typename T>
694 if (
this == &RHS)
return;
697 if (!this->isSmall() && !RHS.isSmall()) {
700 std::swap(this->CapacityX, RHS.CapacityX);
703 if (RHS.size() > this->capacity())
704 this->grow(RHS.size());
705 if (this->size() > RHS.capacity())
706 RHS.grow(this->size());
709 size_t NumShared = this->size();
710 if (NumShared > RHS.size()) NumShared = RHS.size();
711 for (
size_type i = 0; i != NumShared; ++i)
715 if (this->size() > RHS.size()) {
716 size_t EltDiff = this->size() - RHS.size();
717 this->uninitialized_copy(this->
begin()+NumShared, this->
end(), RHS.end());
718 RHS.setEnd(RHS.end()+EltDiff);
719 this->destroy_range(this->
begin()+NumShared, this->
end());
720 this->setEnd(this->
begin()+NumShared);
721 }
else if (RHS.size() > this->size()) {
722 size_t EltDiff = RHS.size() - this->size();
723 this->uninitialized_copy(RHS.begin()+NumShared, RHS.end(), this->
end());
724 this->setEnd(this->
end() + EltDiff);
725 this->destroy_range(RHS.begin()+NumShared, RHS.end());
726 RHS.setEnd(RHS.begin()+NumShared);
730 template <
typename T>
734 if (
this == &RHS)
return *
this;
738 size_t RHSSize = RHS.size();
739 size_t CurSize = this->size();
740 if (CurSize >= RHSSize) {
744 NewEnd = std::copy(RHS.begin(), RHS.begin()+RHSSize, this->
begin());
746 NewEnd = this->
begin();
749 this->destroy_range(NewEnd, this->
end());
752 this->setEnd(NewEnd);
759 if (this->capacity() < RHSSize) {
761 this->destroy_range(this->
begin(), this->
end());
762 this->setEnd(this->
begin());
765 }
else if (CurSize) {
767 std::copy(RHS.begin(), RHS.begin()+CurSize, this->
begin());
771 this->uninitialized_copy(RHS.begin()+CurSize, RHS.end(),
772 this->
begin()+CurSize);
775 this->setEnd(this->
begin()+RHSSize);
779 template <
typename T>
782 if (
this == &RHS)
return *
this;
785 if (!RHS.isSmall()) {
786 this->destroy_range(this->
begin(), this->
end());
787 if (!this->isSmall()) free(this->
begin());
788 this->BeginX = RHS.BeginX;
789 this->EndX = RHS.EndX;
790 this->CapacityX = RHS.CapacityX;
797 size_t RHSSize = RHS.size();
798 size_t CurSize = this->size();
799 if (CurSize >= RHSSize) {
803 NewEnd = std::move(RHS.begin(), RHS.end(), NewEnd);
806 this->destroy_range(NewEnd, this->
end());
807 this->setEnd(NewEnd);
819 if (this->capacity() < RHSSize) {
821 this->destroy_range(this->
begin(), this->
end());
822 this->setEnd(this->
begin());
825 }
else if (CurSize) {
827 std::move(RHS.begin(), RHS.begin()+CurSize, this->
begin());
831 this->uninitialized_move(RHS.begin()+CurSize, RHS.end(),
832 this->
begin()+CurSize);
835 this->setEnd(this->
begin()+RHSSize);
845 template <
typename T,
unsigned N>
860 template <
typename T,
unsigned N>
873 template <
typename ItTy,
874 typename =
typename std::enable_if<std::is_convertible<
875 typename std::iterator_traits<ItTy>::iterator_category,
876 std::input_iterator_tag>::value>::type>
881 template <
typename RangeTy>
927 template<
typename T,
unsigned N>
944 template<
typename T,
unsigned N>
952 #endif // LLVM_ADT_SMALLVECTOR_H
std::reverse_iterator< const_iterator > const_reverse_iterator
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
Copy the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements into ...
std::pair< llvm::RelocationValueRef, llvm::RelocationEntry > * iterator
const std::pair< llvm::RelocationValueRef, llvm::RelocationEntry > & const_reference
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
DiagnosticInfoOptimizationBase::Argument NV
typename SuperClass::const_iterator const_iterator
size_t capacity() const
Return the total number of elements in the currently allocated buffer.
LLVM_ATTRIBUTE_ALWAYS_INLINE reference operator[](size_type idx)
#define LLVM_UNLIKELY(EXPR)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
void assign(in_iter in_start, in_iter in_end)
SmallVector(ItTy S, ItTy E)
LLVM_ATTRIBUTE_ALWAYS_INLINE const_iterator end() const
const SmallVector & operator=(SmallVector &&RHS)
static size_t capacity_in_bytes(const BitVector &X)
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)
Move the range [I, E) into the uninitialized memory starting with "Dest", constructing elements as ne...
void append(size_type NumInputs, const T &Elt)
Add the specified range to the end of the SmallVector.
size_t capacity_in_bytes() const
capacity_in_bytes - This returns capacity()*sizeof(T).
void reserve(size_type N)
typename SuperClass::size_type size_type
SmallVectorTemplateBase(size_t Size)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
Copy the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements as ne...
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize(size_type N, const T &NV)
LLVM_NODISCARD bool empty() const
LLVM_ATTRIBUTE_ALWAYS_INLINE const_iterator begin() const
void assign(size_type NumElts, const T &Elt)
const_reverse_iterator rend() const
SmallVectorTemplateBase(size_t Size)
SmallVector(SmallVectorImpl< T > &&RHS)
const SmallVector & operator=(const SmallVector &RHS)
std::pair< llvm::RelocationValueRef, llvm::RelocationEntry > & reference
SmallVector(SmallVector &&RHS)
SmallVectorTemplateBase<isPodLike = false> - This is where we put method implementations that are desig...
const_reference front() const
bool operator==(const SmallVectorImpl &RHS) const
void swap(SmallVectorImpl &RHS)
const_reference back() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void grow(size_t MinSize=0)
Grow the allocated memory (without initializing new elements), doubling the size of the allocated mem...
std::reverse_iterator< iterator > reverse_iterator
bool operator!=(const SmallVectorImpl &RHS) const
SmallVectorImpl(unsigned N)
bool operator<(const SmallVectorImpl &RHS) const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
LLVM_ATTRIBUTE_ALWAYS_INLINE const_reference operator[](size_type idx) const
const std::pair< llvm::RelocationValueRef, llvm::RelocationEntry > * const_iterator
SmallVectorBase(void *FirstEl, size_t Size)
void assign(std::initializer_list< T > IL)
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
iterator erase(const_iterator CI)
SmallVector(const iterator_range< RangeTy > &R)
const_iterator capacity_ptr() const
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
const SmallVector & operator=(SmallVectorImpl< T > &&RHS)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
std::pair< llvm::RelocationValueRef, llvm::RelocationEntry > * pointer
bool isSmall() const
Return true if this is a smallvector which has not had dynamic memory allocated for it...
void grow(size_t MinSize=0)
Double the size of the allocated memory, guaranteeing space for at least one more element or MinSize ...
SmallVectorTemplateCommon< T >::U InlineElts[N-1]
LLVM_NODISCARD T pop_back_val()
SmallVector(std::initializer_list< T > IL)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A range adaptor for a pair of iterators.
void append(std::initializer_list< T > IL)
SmallVectorImpl & operator=(const SmallVectorImpl &RHS)
typename SuperClass::iterator iterator
iterator insert(iterator I, T &&Elt)
void insert(iterator I, std::initializer_list< T > IL)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static void destroy_range(T *S, T *E)
iterator erase(const_iterator CS, const_iterator CE)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const std::pair< llvm::RelocationValueRef, llvm::RelocationEntry > * const_pointer
std::pair< llvm::RelocationValueRef, llvm::RelocationEntry > value_type
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void set_size(size_type N)
Set the array size to N, which the current array must have enough capacity for.
void emplace_back(ArgTypes &&...Args)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest, typename std::enable_if< std::is_same< typename std::remove_const< T1 >::type, T2 >::value >::type *=nullptr)
Copy the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements into ...
This is all the non-templated stuff common to all SmallVectors.
size_t size_in_bytes() const
This returns size()*sizeof(T).
SmallVectorTemplateCommon(size_t Size)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
SmallVector(const SmallVector &RHS)
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
iterator insert(iterator I, ItTy From, ItTy To)
static void uninitialized_move(It1 I, It1 E, It2 Dest)
Move the range [I, E) onto the uninitialized memory starting with "Dest", constructing elements into ...
void grow_pod(size_t MinSizeInBytes, size_t TSize)
static void destroy_range(T *, T *)
void grow_pod(void *FirstEl, size_t MinSizeInBytes, size_t TSize)
This is an implementation of the grow() method which only works on POD-like data types and is out of ...
Storage for the SmallVector elements which aren't contained in SmallVectorTemplateCommon.
size_type max_size() const
const SmallVector & operator=(std::initializer_list< T > IL)
void resetToSmall()
Put this vector in a state of being small.
const_pointer data() const
Return a pointer to the vector's buffer, even if empty().
SmallVector(size_t Size, const T &Value=T())
const_reverse_iterator rbegin() const