17#ifdef LLVM_ENABLE_EXCEPTIONS
27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Waix-compat"
37#pragma GCC diagnostic pop
41 sizeof(
unsigned) * 2 +
sizeof(
void *),
42 "wasted space in SmallVector size 0");
44 "wrong alignment for 16-byte aligned T");
46 "wrong alignment for 32-byte aligned T");
48 "missing padding for 16-byte aligned T");
50 "missing padding for 32-byte aligned T");
52 sizeof(
unsigned) * 2 +
sizeof(
void *) * 2,
53 "wasted space in SmallVector size 1");
56 sizeof(
void *) * 2 +
sizeof(
void *),
57 "1 byte elements have word-sized type for size and capacity");
63 std::string Reason =
"SmallVector unable to grow. Requested capacity (" +
64 std::to_string(MinSize) +
65 ") is larger than maximum value for size type (" +
66 std::to_string(MaxSize) +
")";
67#ifdef LLVM_ENABLE_EXCEPTIONS
68 throw std::length_error(Reason);
79 "SmallVector capacity unable to grow. Already at maximum size " +
80 std::to_string(MaxSize);
81#ifdef LLVM_ENABLE_EXCEPTIONS
82 throw std::length_error(Reason);
89template <
class Size_T>
90static size_t getNewCapacity(
size_t MinSize,
size_t TSize,
size_t OldCapacity) {
91 constexpr size_t MaxSize = std::numeric_limits<Size_T>::max();
95 if (MinSize > MaxSize)
102 if (OldCapacity == MaxSize)
107 size_t NewCapacity = 2 * OldCapacity + 1;
108 return std::clamp(NewCapacity, MinSize, MaxSize);
111template <
class Size_T>
117 memcpy(NewEltsReplace, NewElts, VSize * TSize);
119 return NewEltsReplace;
123template <
class Size_T>
126 size_t &NewCapacity) {
127 NewCapacity = getNewCapacity<Size_T>(MinSize, TSize, this->capacity());
131 if (NewElts == FirstEl)
132 NewElts = replaceAllocation(NewElts, TSize, NewCapacity);
137template <
class Size_T>
140 size_t NewCapacity = getNewCapacity<Size_T>(MinSize, TSize, this->capacity());
142 if (BeginX == FirstEl) {
144 if (NewElts == FirstEl)
145 NewElts = replaceAllocation(NewElts, TSize, NewCapacity);
148 memcpy(NewElts, this->BeginX,
size() * TSize);
152 if (NewElts == FirstEl)
153 NewElts = replaceAllocation(NewElts, TSize, NewCapacity,
size());
156 this->set_allocation_range(NewElts, NewCapacity);
165#if SIZE_MAX > UINT32_MAX
170 "Expected SmallVectorBase<uint64_t> variant to be in use.");
173 "Expected SmallVectorBase<uint32_t> variant to be in use.");
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
static void report_size_overflow(size_t MinSize, size_t MaxSize)
Report that MinSize doesn't fit into this vector's size type.
static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity)
static void report_at_maximum_capacity(size_t MaxSize)
Report that this vector is already at maximum capacity.
This file defines the SmallVector class.
This is all the stuff common to all SmallVectors.
void grow_pod(void *FirstEl, size_t MinSize, size_t TSize)
This is an implementation of the grow() method which only works on POD-like data types and is out of ...
void * mallocForGrow(void *FirstEl, size_t MinSize, size_t TSize, size_t &NewCapacity)
This is a helper for grow() that's out of line to reduce code duplication.
void * replaceAllocation(void *NewElts, size_t TSize, size_t NewCapacity, size_t VSize=0)
If vector was first created with capacity 0, getFirstEl() points to the memory right after,...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::conditional_t< sizeof(T)< 4 &&sizeof(void *) >=8, uint64_t, uint32_t > SmallVectorSizeType
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_malloc(size_t Sz)
LLVM_ATTRIBUTE_RETURNS_NONNULL void * safe_realloc(void *Ptr, size_t Sz)