13 #ifndef LLVM_ADT_SMALLVECTOR_H 14 #define LLVM_ADT_SMALLVECTOR_H 28 #include <initializer_list> 32 #include <type_traits> 45 : BeginX(FirstEl),
Capacity(TotalCapacity) {}
49 void grow_pod(
void *FirstEl,
size_t MinCapacity,
size_t TSize);
81 template <
typename T,
typename =
void>
86 void *getFirstEl()
const {
87 return const_cast<void *
>(
reinterpret_cast<const void *
>(
88 reinterpret_cast<const char *
>(
this) +
97 void grow_pod(
size_t MinCapacity,
size_t TSize) {
178 template <typename T, bool = is_trivially_copyable<T>::value>
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 TriviallyCopyable>
234 if (MinSize > UINT32_MAX)
239 NewCapacity = std::min(
std::max(NewCapacity, MinSize),
size_t(UINT32_MAX));
243 this->uninitialized_move(this->
begin(), this->
end(), NewElts);
246 destroy_range(this->
begin(), this->
end());
249 if (!this->isSmall())
258 template <
typename T>
268 template<
typename It1,
typename It2>
271 uninitialized_copy(I, E, Dest);
276 template<
typename It1,
typename It2>
279 std::uninitialized_copy(I, E, Dest);
284 template <
typename T1,
typename T2>
287 typename std::enable_if<std::is_same<
typename std::remove_const<T1>::type,
288 T2>::value>::
type * =
nullptr) {
294 memcpy(reinterpret_cast<void *>(Dest), I, (E - I) *
sizeof(
T));
305 memcpy(reinterpret_cast<void *>(this->
end()), &Elt,
sizeof(
T));
314 template <
typename T>
335 if (!this->isSmall())
340 this->destroy_range(this->
begin(), this->
end());
345 if (N < this->
size()) {
346 this->destroy_range(this->
begin()+N, this->
end());
348 }
else if (N > this->
size()) {
351 for (
auto I = this->
end(),
E = this->
begin() + N;
I !=
E; ++
I)
358 if (N < this->
size()) {
359 this->destroy_range(this->
begin()+N, this->
end());
361 }
else if (N > this->
size()) {
364 std::uninitialized_fill(this->
end(), this->
begin()+N, NV);
375 T Result = ::std::move(this->back());
383 template <
typename in_iter,
384 typename =
typename std::enable_if<std::is_convertible<
385 typename std::iterator_traits<in_iter>::iterator_category,
386 std::input_iterator_tag>::value>
::type>
387 void append(in_iter in_start, in_iter in_end) {
388 size_type NumInputs = std::distance(in_start, in_end);
390 this->grow(this->
size()+NumInputs);
392 this->uninitialized_copy(in_start, in_end, this->
end());
399 this->grow(this->
size()+NumInputs);
401 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
405 void append(std::initializer_list<T> IL) {
406 append(IL.begin(), IL.end());
417 std::uninitialized_fill(this->
begin(), this->
end(), Elt);
420 template <
typename in_iter,
421 typename =
typename std::enable_if<std::is_convertible<
422 typename std::iterator_traits<in_iter>::iterator_category,
423 std::input_iterator_tag>::value>
::type>
424 void assign(in_iter in_start, in_iter in_end) {
429 void assign(std::initializer_list<T> IL) {
438 assert(I >= this->
begin() &&
"Iterator to erase is out of bounds.");
439 assert(I < this->
end() &&
"Erasing at past-the-end iterator.");
443 std::move(I+1, this->
end(), I);
454 assert(S >= this->
begin() &&
"Range to erase is out of bounds.");
455 assert(S <= E &&
"Trying to erase invalid range.");
456 assert(E <= this->
end() &&
"Trying to erase past the end.");
462 this->destroy_range(I, this->
end());
468 if (I == this->
end()) {
469 this->push_back(::std::move(Elt));
470 return this->
end()-1;
473 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
474 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
477 size_t EltNo = I-this->
begin();
479 I = this->
begin()+EltNo;
482 ::new ((
void*) this->
end())
T(::std::move(this->back()));
484 std::move_backward(I, this->
end()-1, this->
end());
490 if (I <= EltPtr && EltPtr < this->
end())
493 *I = ::std::move(*EltPtr);
498 if (I == this->
end()) {
499 this->push_back(Elt);
500 return this->
end()-1;
503 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
504 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
507 size_t EltNo = I-this->
begin();
509 I = this->
begin()+EltNo;
511 ::new ((
void*) this->
end())
T(std::move(this->back()));
513 std::move_backward(I, this->
end()-1, this->
end());
518 const T *EltPtr = &Elt;
519 if (I <= EltPtr && EltPtr < this->
end())
528 size_t InsertElt = I - this->
begin();
530 if (I == this->
end()) {
532 return this->
begin()+InsertElt;
535 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
536 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
539 reserve(this->
size() + NumToInsert);
542 I = this->
begin()+InsertElt;
548 if (
size_t(this->
end()-I) >= NumToInsert) {
549 T *OldEnd = this->
end();
550 append(std::move_iterator<iterator>(this->
end() - NumToInsert),
551 std::move_iterator<iterator>(this->
end()));
554 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
556 std::fill_n(I, NumToInsert, Elt);
564 T *OldEnd = this->
end();
566 size_t NumOverwritten = OldEnd-
I;
567 this->uninitialized_move(I, OldEnd, this->
end()-NumOverwritten);
570 std::fill_n(I, NumOverwritten, Elt);
573 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
577 template <
typename ItTy,
578 typename =
typename std::enable_if<std::is_convertible<
579 typename std::iterator_traits<ItTy>::iterator_category,
580 std::input_iterator_tag>::value>
::type>
583 size_t InsertElt = I - this->
begin();
585 if (I == this->
end()) {
587 return this->
begin()+InsertElt;
590 assert(I >= this->
begin() &&
"Insertion iterator is out of bounds.");
591 assert(I <= this->
end() &&
"Inserting past the end of the vector.");
593 size_t NumToInsert = std::distance(From, To);
596 reserve(this->
size() + NumToInsert);
599 I = this->
begin()+InsertElt;
605 if (
size_t(this->
end()-I) >= NumToInsert) {
606 T *OldEnd = this->
end();
607 append(std::move_iterator<iterator>(this->
end() - NumToInsert),
608 std::move_iterator<iterator>(this->
end()));
611 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
621 T *OldEnd = this->
end();
623 size_t NumOverwritten = OldEnd-
I;
624 this->uninitialized_move(I, OldEnd, this->
end()-NumOverwritten);
627 for (
T *J = I; NumOverwritten > 0; --NumOverwritten) {
633 this->uninitialized_copy(From, To, OldEnd);
638 insert(I, IL.begin(), IL.end());
644 ::new ((
void *)this->
end())
T(std::forward<ArgTypes>(
Args)...);
654 if (this->
size() != RHS.
size())
return false;
658 return !(*
this == RHS);
662 return std::lexicographical_compare(this->
begin(), this->
end(),
667 template <
typename T>
669 if (
this == &RHS)
return;
672 if (!this->isSmall() && !RHS.
isSmall()) {
679 this->grow(RHS.
size());
681 RHS.
grow(this->size());
684 size_t NumShared = this->
size();
685 if (NumShared > RHS.
size()) NumShared = RHS.
size();
686 for (
size_type i = 0; i != NumShared; ++i)
691 size_t EltDiff = this->
size() - RHS.
size();
692 this->uninitialized_copy(this->
begin()+NumShared, this->
end(), RHS.
end());
694 this->destroy_range(this->
begin()+NumShared, this->
end());
696 }
else if (RHS.
size() > this->
size()) {
697 size_t EltDiff = RHS.
size() - this->
size();
698 this->uninitialized_copy(RHS.
begin()+NumShared, RHS.
end(), this->
end());
700 this->destroy_range(RHS.
begin()+NumShared, RHS.
end());
705 template <
typename T>
709 if (
this == &RHS)
return *
this;
713 size_t RHSSize = RHS.
size();
714 size_t CurSize = this->
size();
715 if (CurSize >= RHSSize) {
721 NewEnd = this->
begin();
724 this->destroy_range(NewEnd, this->
end());
736 this->destroy_range(this->
begin(), this->
end());
740 }
else if (CurSize) {
746 this->uninitialized_copy(RHS.
begin()+CurSize, RHS.
end(),
747 this->
begin()+CurSize);
754 template <
typename T>
757 if (
this == &RHS)
return *
this;
760 if (!RHS.isSmall()) {
761 this->destroy_range(this->
begin(), this->
end());
762 if (!this->isSmall()) free(this->
begin());
763 this->
BeginX = RHS.BeginX;
764 this->
Size = RHS.Size;
772 size_t RHSSize = RHS.size();
773 size_t CurSize = this->
size();
774 if (CurSize >= RHSSize) {
778 NewEnd = std::move(RHS.begin(), RHS.end(), NewEnd);
781 this->destroy_range(NewEnd, this->
end());
796 this->destroy_range(this->
begin(), this->
end());
800 }
else if (CurSize) {
802 std::move(RHS.begin(), RHS.begin()+CurSize, this->
begin());
806 this->uninitialized_move(RHS.begin()+CurSize, RHS.end(),
807 this->
begin()+CurSize);
818 template <
typename T,
unsigned N>
836 template <
typename T,
unsigned N>
843 this->destroy_range(this->
begin(), this->
end());
848 this->assign(Size,
Value);
851 template <
typename ItTy,
852 typename =
typename std::enable_if<std::is_convertible<
853 typename std::iterator_traits<ItTy>::iterator_category,
854 std::input_iterator_tag>::value>
::type>
859 template <
typename RangeTy>
905 template <
typename T,
unsigned N>
913 template <
unsigned Size,
typename R>
914 SmallVector<
typename std::remove_const<
typename std::remove_reference<
933 template<
typename T,
unsigned N>
941 #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.
reference emplace_back(ArgTypes &&... Args)
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")
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.
const_iterator begin() const
#define LLVM_UNLIKELY(EXPR)
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)
Append NumInputs copies of Elt to the end.
block Block Frequency true
void reserve(size_type N)
void grow_pod(size_t MinCapacity, size_t TSize)
const_reverse_iterator rend() const
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)
SmallVector(SmallVectorImpl< T > &&RHS)
const SmallVector & operator=(const SmallVector &RHS)
SmallVector(SmallVector &&RHS)
AlignedCharArrayUnion< T > FirstEl
SmallVector< typename std::remove_const< typename std::remove_reference< decltype(*std::begin(std::declval< R & >)))>::type >::type, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
const_reference front() const
SmallVectorTemplateBase<TriviallyCopyable = false> - This is where we put method implementations that...
void grow(size_t MinSize=0)
Grow the allocated memory (without initializing new elements), doubling the size of the allocated mem...
void swap(SmallVectorImpl &RHS)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void set_size(size_t N)
Set the array size to N, which the current array must have enough capacity for.
std::reverse_iterator< iterator > reverse_iterator
reference operator[](size_type idx)
#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.
typename SuperClass::reference reference
const_reference back() const
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
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
Align max(MaybeAlign Lhs, Align Rhs)
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
A suitably aligned and sized character array member which can hold elements of any type...
const_reference operator[](size_type idx) const
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
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
LLVM_NODISCARD bool empty() 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.
SmallVectorBase(void *FirstEl, size_t TotalCapacity)
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 ...
static void destroy_range(T *, T *)
const_iterator end() const
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.