14 #ifndef LLVM_ADT_SMALLVECTOR_H 15 #define LLVM_ADT_SMALLVECTOR_H 29 #include <initializer_list> 33 #include <type_traits> 46 : BeginX(FirstEl), Capacity(Capacity) {}
50 void grow_pod(
void *FirstEl,
size_t MinCapacity,
size_t TSize);
82 template <
typename T,
typename =
void>
87 void *getFirstEl()
const {
88 return const_cast<void *
>(
reinterpret_cast<const void *
>(
89 reinterpret_cast<const char *
>(
this) +
98 void grow_pod(
size_t MinCapacity,
size_t TSize) {
185 template <typename T, bool = isPodLike<T>::value>
199 template<
typename It1,
typename It2>
201 std::uninitialized_copy(std::make_move_iterator(I),
202 std::make_move_iterator(E), Dest);
207 template<
typename It1,
typename It2>
209 std::uninitialized_copy(I, E, Dest);
215 void grow(
size_t MinSize = 0);
221 ::new ((
void*) this->
end())
T(Elt);
228 ::new ((
void*) this->
end())
T(::std::move(Elt));
239 template <
typename T,
bool isPodLike>
241 if (MinSize > UINT32_MAX)
246 NewCapacity = std::min(
std::max(NewCapacity, MinSize),
size_t(UINT32_MAX));
250 this->uninitialized_move(this->
begin(), this->
end(), NewElts);
253 destroy_range(this->
begin(), this->
end());
256 if (!this->isSmall())
266 template <
typename T>
276 template<
typename It1,
typename It2>
279 uninitialized_copy(I, E, Dest);
284 template<
typename It1,
typename It2>
287 std::uninitialized_copy(I, E, Dest);
292 template <
typename T1,
typename T2>
295 typename std::enable_if<std::is_same<
typename std::remove_const<T1>::type,
296 T2>::value>::
type * =
nullptr) {
302 memcpy(reinterpret_cast<void *>(Dest), I, (E - I) *
sizeof(
T));
313 memcpy(reinterpret_cast<void *>(this->
end()), &Elt,
sizeof(
T));
322 template <
typename T>
342 if (!this->isSmall())
347 this->destroy_range(this->
begin(), this->
end());
352 if (N < this->
size()) {
353 this->destroy_range(this->
begin()+N, this->
end());
355 }
else if (N > this->
size()) {
358 for (
auto I = this->
end(),
E = this->
begin() + N;
I !=
E; ++
I)
365 if (N < this->
size()) {
366 this->destroy_range(this->
begin()+N, this->
end());
368 }
else if (N > this->
size()) {
371 std::uninitialized_fill(this->
end(), this->
begin()+N, NV);
382 T Result = ::std::move(this->back());
390 template <
typename in_iter,
391 typename =
typename std::enable_if<std::is_convertible<
392 typename std::iterator_traits<in_iter>::iterator_category,
393 std::input_iterator_tag>::value>
::type>
394 void append(in_iter in_start, in_iter in_end) {
395 size_type NumInputs = std::distance(in_start, in_end);
398 this->grow(this->
size()+NumInputs);
401 this->uninitialized_copy(in_start, in_end, this->
end());
409 this->grow(this->
size()+NumInputs);
412 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
416 void append(std::initializer_list<T> IL) {
417 append(IL.begin(), IL.end());
428 std::uninitialized_fill(this->
begin(), this->
end(), Elt);
431 template <
typename in_iter,
432 typename =
typename std::enable_if<std::is_convertible<
433 typename std::iterator_traits<in_iter>::iterator_category,
434 std::input_iterator_tag>::value>
::type>
435 void assign(in_iter in_start, in_iter in_end) {
440 void assign(std::initializer_list<T> IL) {
449 assert(I >= this->
begin() &&
"Iterator to erase is out of bounds.");
450 assert(I < this->
end() &&
"Erasing at past-the-end iterator.");
454 std::move(I+1, this->
end(), I);
465 assert(S >= this->
begin() &&
"Range to erase is out of bounds.");
466 assert(S <= E &&
"Trying to erase invalid range.");
467 assert(E <= this->
end() &&
"Trying to erase past the end.");
473 this->destroy_range(I, this->
end());
479 if (I == this->
end()) {
480 this->push_back(::std::move(Elt));
481 return this->
end()-1;
484 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
485 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
488 size_t EltNo = I-this->
begin();
490 I = this->
begin()+EltNo;
493 ::new ((
void*) this->
end())
T(::std::move(this->back()));
495 std::move_backward(I, this->
end()-1, this->
end());
501 if (I <= EltPtr && EltPtr < this->
end())
504 *I = ::std::move(*EltPtr);
509 if (I == this->
end()) {
510 this->push_back(Elt);
511 return this->
end()-1;
514 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
515 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
518 size_t EltNo = I-this->
begin();
520 I = this->
begin()+EltNo;
522 ::new ((
void*) this->
end())
T(std::move(this->back()));
524 std::move_backward(I, this->
end()-1, this->
end());
529 const T *EltPtr = &Elt;
530 if (I <= EltPtr && EltPtr < this->
end())
539 size_t InsertElt = I - this->
begin();
541 if (I == this->
end()) {
543 return this->
begin()+InsertElt;
546 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
547 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
550 reserve(this->
size() + NumToInsert);
553 I = this->
begin()+InsertElt;
559 if (
size_t(this->
end()-I) >= NumToInsert) {
560 T *OldEnd = this->
end();
561 append(std::move_iterator<iterator>(this->
end() - NumToInsert),
562 std::move_iterator<iterator>(this->
end()));
565 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
567 std::fill_n(I, NumToInsert, Elt);
575 T *OldEnd = this->
end();
577 size_t NumOverwritten = OldEnd-
I;
578 this->uninitialized_move(I, OldEnd, this->
end()-NumOverwritten);
581 std::fill_n(I, NumOverwritten, Elt);
584 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
588 template <
typename ItTy,
589 typename =
typename std::enable_if<std::is_convertible<
590 typename std::iterator_traits<ItTy>::iterator_category,
591 std::input_iterator_tag>::value>
::type>
594 size_t InsertElt = I - this->
begin();
596 if (I == this->
end()) {
598 return this->
begin()+InsertElt;
601 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
602 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
604 size_t NumToInsert = std::distance(From, To);
607 reserve(this->
size() + NumToInsert);
610 I = this->
begin()+InsertElt;
616 if (
size_t(this->
end()-I) >= NumToInsert) {
617 T *OldEnd = this->
end();
618 append(std::move_iterator<iterator>(this->
end() - NumToInsert),
619 std::move_iterator<iterator>(this->
end()));
622 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
632 T *OldEnd = this->
end();
634 size_t NumOverwritten = OldEnd-
I;
635 this->uninitialized_move(I, OldEnd, this->
end()-NumOverwritten);
638 for (
T *J = I; NumOverwritten > 0; --NumOverwritten) {
644 this->uninitialized_copy(From, To, OldEnd);
649 insert(I, IL.begin(), IL.end());
655 ::new ((
void *)this->
end())
T(std::forward<ArgTypes>(
Args)...);
664 if (this->
size() != RHS.
size())
return false;
668 return !(*
this == RHS);
672 return std::lexicographical_compare(this->
begin(), this->
end(),
677 template <
typename T>
679 if (
this == &RHS)
return;
682 if (!this->isSmall() && !RHS.
isSmall()) {
689 this->grow(RHS.
size());
691 RHS.
grow(this->size());
694 size_t NumShared = this->
size();
695 if (NumShared > RHS.
size()) NumShared = RHS.
size();
696 for (
size_type i = 0; i != NumShared; ++i)
701 size_t EltDiff = this->
size() - RHS.
size();
702 this->uninitialized_copy(this->
begin()+NumShared, this->
end(), RHS.
end());
704 this->destroy_range(this->
begin()+NumShared, this->
end());
706 }
else if (RHS.
size() > this->
size()) {
707 size_t EltDiff = RHS.
size() - this->
size();
708 this->uninitialized_copy(RHS.
begin()+NumShared, RHS.
end(), this->
end());
710 this->destroy_range(RHS.
begin()+NumShared, RHS.
end());
715 template <
typename T>
719 if (
this == &RHS)
return *
this;
723 size_t RHSSize = RHS.
size();
724 size_t CurSize = this->
size();
725 if (CurSize >= RHSSize) {
731 NewEnd = this->
begin();
734 this->destroy_range(NewEnd, this->
end());
746 this->destroy_range(this->
begin(), this->
end());
750 }
else if (CurSize) {
756 this->uninitialized_copy(RHS.
begin()+CurSize, RHS.
end(),
757 this->
begin()+CurSize);
764 template <
typename T>
767 if (
this == &RHS)
return *
this;
770 if (!RHS.isSmall()) {
771 this->destroy_range(this->
begin(), this->
end());
772 if (!this->isSmall()) free(this->
begin());
773 this->
BeginX = RHS.BeginX;
774 this->
Size = RHS.Size;
782 size_t RHSSize = RHS.size();
783 size_t CurSize = this->
size();
784 if (CurSize >= RHSSize) {
788 NewEnd = std::move(RHS.begin(), RHS.end(), NewEnd);
791 this->destroy_range(NewEnd, this->
end());
806 this->destroy_range(this->
begin(), this->
end());
810 }
else if (CurSize) {
812 std::move(RHS.begin(), RHS.begin()+CurSize, this->
begin());
816 this->uninitialized_move(RHS.begin()+CurSize, RHS.end(),
817 this->
begin()+CurSize);
828 template <
typename T,
unsigned N>
846 template <
typename T,
unsigned N>
853 this->destroy_range(this->
begin(), this->
end());
858 this->assign(Size,
Value);
861 template <
typename ItTy,
862 typename =
typename std::enable_if<std::is_convertible<
863 typename std::iterator_traits<ItTy>::iterator_category,
864 std::input_iterator_tag>::value>
::type>
869 template <
typename RangeTy>
915 template <
typename T,
unsigned N>
932 template<
typename T,
unsigned N>
940 #endif // LLVM_ADT_SMALLVECTOR_H void grow_pod(void *FirstEl, size_t MinCapacity, size_t TSize)
This is an implementation of the grow() method which only works on POD-like data types and is out of ...
static void destroy_range(T *S, T *E)
std::reverse_iterator< const_iterator > const_reverse_iterator
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 ...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
DiagnosticInfoOptimizationBase::Argument NV
typename SuperClass::const_iterator const_iterator
bool operator!=(const SmallVectorImpl &RHS) const
AlignedCharArrayUnion< SmallVectorBase > Base
This class represents lattice values for constants.
LLVM_ATTRIBUTE_ALWAYS_INLINE reference operator[](size_type idx)
const_pointer data() const
Return a pointer to the vector's buffer, even if empty().
void push_back(const T &Elt)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
bool isSmall() const
Return true if this is a smallvector which has not had dynamic memory allocated for it...
void assign(in_iter in_start, in_iter in_end)
SmallVector(ItTy S, ItTy E)
const SmallVector & operator=(SmallVector &&RHS)
iterator insert(iterator I, const T &Elt)
iterator insert(iterator I, size_type NumToInsert, const T &Elt)
void append(size_type NumInputs, const T &Elt)
Add the specified range to the end of the SmallVector.
block Block Frequency true
void reserve(size_type N)
void grow_pod(size_t MinCapacity, size_t TSize)
const_reverse_iterator rend() const
#define LLVM_UNLIKELY(EXPR)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
typename SuperClass::size_type size_type
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
size_type max_size() const
size_t capacity_in_bytes(const BitVector &X)
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)
This file defines counterparts of C library allocation functions defined in the namespace 'std'...
size_t capacity_in_bytes() const
void assign(size_type NumElts, const T &Elt)
SmallVectorTemplateBase(size_t Size)
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
SmallVector(SmallVectorImpl< T > &&RHS)
const SmallVector & operator=(const SmallVector &RHS)
LLVM_ATTRIBUTE_ALWAYS_INLINE const_reference operator[](size_type idx) const
SmallVector(SmallVector &&RHS)
AlignedCharArrayUnion< T > FirstEl
const_reference front() const
SmallVectorTemplateBase<isPodLike = false> - This is where we put method implementations that are des...
void swap(SmallVectorImpl &RHS)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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
#define offsetof(TYPE, MEMBER)
SmallVectorImpl(unsigned N)
const_reverse_iterator rbegin() const
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)
void swap(llvm::SmallVector< T, N > &LHS, llvm::SmallVector< T, N > &RHS)
Implement std::swap in terms of SmallVector swap.
SmallVector(const iterator_range< RangeTy > &R)
void report_bad_alloc_error(const char *Reason, bool GenCrashDiag=true)
Reports a bad alloc error, calling any user defined bad alloc error handler.
const_reference back() const
LLVM_ATTRIBUTE_ALWAYS_INLINE const_iterator begin() const
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
SmallVectorBase(void *FirstEl, size_t Capacity)
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...
const SmallVector & operator=(SmallVectorImpl< T > &&RHS)
BlockVerifier::State From
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void grow(size_t MinSize=0)
Double the size of the allocated memory, guaranteeing space for at least one more element or MinSize ...
LLVM_NODISCARD T pop_back_val()
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...
SmallVector(std::initializer_list< T > IL)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool operator<(const SmallVectorImpl &RHS) const
A range adaptor for a pair of iterators.
void append(std::initializer_list< T > IL)
SmallVectorImpl & operator=(const SmallVectorImpl &RHS)
typename SuperClass::iterator iterator
This union template exposes a suitably aligned and sized character array member which can hold elemen...
static void clear(coro::Shape &Shape)
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.
iterator erase(const_iterator CS, const_iterator CE)
SmallVectorTemplateBase(size_t Size)
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD...
size_type size_in_bytes() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
void emplace_back(ArgTypes &&... Args)
LLVM_NODISCARD bool empty() const
LLVM_ATTRIBUTE_ALWAYS_INLINE const_iterator end() 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.
SmallVectorTemplateCommon(size_t Size)
SmallVector(const SmallVector &RHS)
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
void set_size(size_t Size)
Set the array size to N, which the current array must have enough capacity for.
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 ...
static void destroy_range(T *, T *)
Storage for the SmallVector elements.
bool operator==(const SmallVectorImpl &RHS) const
OutputIt copy(R &&Range, OutputIt Out)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
const SmallVector & operator=(std::initializer_list< T > IL)
void resetToSmall()
Put this vector in a state of being small.
SmallVector(size_t Size, const T &Value=T())
Figure out the offset of the first element.