19 #ifndef LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H
20 #define LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H
22 #include "llvm/ADT/PointerIntPair.h"
23 #include "llvm/Support/Allocator.h"
24 #include "llvm/Support/type_traits.h"
33 llvm::PointerIntPair<llvm::BumpPtrAllocator*, 1> Alloc;
40 Other.Alloc.setInt(
false);
41 Other.Alloc.setPointer(
nullptr);
51 delete Alloc.getPointer();
54 llvm::BumpPtrAllocator &
getAllocator() {
return *Alloc.getPointer(); }
59 T *Begin, *End, *Capacity;
63 : Begin(nullptr), End(nullptr), Capacity(nullptr) {
68 if (std::is_class<T>::value) {
70 destroy_range(Begin, End);
100 bool empty()
const {
return Begin == End; }
104 assert(Begin + idx < End);
108 assert(Begin + idx < End);
138 if (std::is_class<T>::value) {
139 destroy_range(Begin, End);
155 if (End < Capacity) {
169 assert (I >= Begin && I <= End &&
"Iterator out of bounds.");
170 if (End + Cnt <= Capacity) {
172 move_range_right(I, End, Cnt);
173 construct_range(I, I + Cnt, E);
178 grow(C,
size() + Cnt);
184 if (
unsigned(Capacity-Begin) < N)
190 size_t capacity()
const {
return Capacity - Begin; }
197 void construct_range(T *
S, T *
E,
const T &Elt) {
202 void destroy_range(T *S, T *E) {
209 void move_range_right(T *S, T *E,
size_t D) {
210 for (T *
I = E + D - 1, *IL = S + D - 1;
I != IL; --
I) {
219 template <
typename T>
220 void BumpVector<T>::grow(BumpVectorContext &C,
size_t MinSize) {
221 size_t CurCapacity = Capacity-Begin;
222 size_t CurSize = size();
223 size_t NewCapacity = 2*CurCapacity;
224 if (NewCapacity < MinSize)
225 NewCapacity = MinSize;
228 T *NewElts = C.getAllocator().template Allocate<T>(NewCapacity);
232 if (std::is_class<T>::value) {
233 std::uninitialized_copy(Begin,
End, NewElts);
235 destroy_range(Begin,
End);
238 memcpy(NewElts, Begin, CurSize *
sizeof(T));
245 End = NewElts+CurSize;
246 Capacity = Begin+NewCapacity;
const_reference operator[](unsigned idx) const
reference operator[](unsigned idx)
const_iterator begin() const
const_reference back() const
const_reverse_iterator rend() const
const_iterator end() const
std::reverse_iterator< iterator > reverse_iterator
llvm::BumpPtrAllocator & getAllocator()
reverse_iterator rbegin()
BumpVector(BumpVectorContext &C, unsigned N)
BumpVectorContext(BumpVectorContext &&Other)
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
detail::InMemoryDirectory::const_iterator I
void reserve(BumpVectorContext &C, unsigned N)
const_reference front() const
ptrdiff_t difference_type
The result type of a method or function.
std::reverse_iterator< const_iterator > const_reverse_iterator
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
void push_back(const_reference Elt, BumpVectorContext &C)
detail::InMemoryDirectory::const_iterator E
BumpVectorContext(llvm::BumpPtrAllocator &A)
Construct a new BumpVectorContext that reuses an existing BumpPtrAllocator.
const_pointer data() const
data - Return a pointer to the vector's buffer, even if empty().
iterator insert(iterator I, size_t Cnt, const_reference E, BumpVectorContext &C)
insert - Insert some number of copies of element into a position.
CFGElement - Represents a top-level expression in a basic block.
size_t capacity() const
capacity - Return the total number of elements in the currently allocated buffer. ...
const_reverse_iterator rbegin() const
const T & const_reference
BumpVectorContext()
Construct a new BumpVectorContext that creates a new BumpPtrAllocator and destroys it when the BumpVe...