13#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYUTIL_H
14#define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYUTIL_H
18#include "llvm/ADT/StringRef.h"
19#include "llvm/ADT/iterator_range.h"
20#include "llvm/Support/Allocator.h"
33namespace threadSafety {
52 return Allocator->Allocate(Sz,
alignof(AlignmentType));
55 template <
typename T>
T *
allocateT() {
return Allocator->Allocate<
T>(); }
58 return Allocator->Allocate<
T>(NumElems);
62 llvm::BumpPtrAllocator *Allocator =
nullptr;
70inline void *
operator new(
size_t Sz,
72 return R.allocate(Sz);
76namespace threadSafety {
88 : Data(Dat), Size(Sz), Capacity(Cp) {}
90 : Data(Cp == 0 ? nullptr : A.allocateT<
T>(Cp)), Capacity(Cp) {}
94 : Data(A.Data), Size(A.Size), Capacity(A.Capacity) {
104 Capacity = RHS.Capacity;
107 RHS.Size = RHS.Capacity = 0;
119 memcpy(Data, Odata,
sizeof(
T) * Size);
125 reserve(u_max(InitialCapacity, N), A);
126 else if (Size + N < Capacity)
127 reserve(u_max(Size + N, Capacity * 2), A);
135 size_t size()
const {
return Size; }
139 assert(i < Size &&
"Array index out of bounds.");
144 assert(i < Size &&
"Array index out of bounds.");
149 assert(Size &&
"No elements in the array.");
150 return Data[Size - 1];
154 assert(Size &&
"No elements in the array.");
155 return Data[Size - 1];
179 assert(Size < Capacity);
190 assert(Sz <= Capacity);
192 for (
unsigned i = 0; i < Sz; ++i) {
200 for (; J < Capacity && I !=
E; ++J, ++I)
206 llvm::iterator_range<reverse_iterator>
reverse() {
207 return llvm::reverse(*
this);
210 llvm::iterator_range<const_reverse_iterator>
reverse()
const {
211 return llvm::reverse(*
this);
217 size_t u_max(
size_t i,
size_t j) {
return (i < j) ? j : i; }
219 static const size_t InitialCapacity = 4;
238 unsigned NumRefs = 1;
241 VectorData() =
default;
242 VectorData(
const VectorData &VD) : Vect(VD.Vect) {}
246 VectorData &operator=(
const VectorData &) =
delete;
270 bool writable()
const {
return Data && Data->NumRefs == 1; }
275 Data =
new VectorData();
283 if (Data->NumRefs <= 1)
293 Data =
new VectorData();
296 if (Data->NumRefs == 1)
299 Data =
new VectorData(*Data);
307 const std::vector<T> &
elements()
const {
return Data->Vect; }
321 assert(
writable() &&
"Vector is not writable!");
327 assert(
writable() &&
"Vector is not writable!");
328 Data->Vect.push_back(Elem);
334 assert(
writable() &&
"Vector is not writable!");
335 return Data->Vect[i];
340 assert(
writable() &&
"Vector is not writable!");
341 Data->Vect.erase(Data->Vect.begin() + i, Data->Vect.end());
351 VectorData *Data =
nullptr;
354inline std::ostream&
operator<<(std::ostream& ss,
const StringRef str) {
355 return ss.write(str.data(), str.size());
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
const std::vector< T > & elements() const
void push_back(const T &Elem)
const_iterator end() const
bool sameAs(const CopyOnWriteVector &V) const
void downsize(unsigned i)
CopyOnWriteVector & operator=(CopyOnWriteVector &&V)
typename std::vector< T >::const_iterator const_iterator
CopyOnWriteVector(const CopyOnWriteVector &)=delete
CopyOnWriteVector & operator=(const CopyOnWriteVector &)=delete
const_iterator begin() const
const T & operator[](unsigned i) const
CopyOnWriteVector clone()
CopyOnWriteVector()=default
CopyOnWriteVector(CopyOnWriteVector &&V)
T * allocateT(size_t NumElems)
MemRegionRef(llvm::BumpPtrAllocator *A)
void * allocate(size_t Sz)
reverse_iterator rbegin()
SimpleArray(SimpleArray< T > &&A)
unsigned append(Iter I, Iter E)
const_iterator begin() const
void setValues(unsigned Sz, const T &C)
std::reverse_iterator< iterator > reverse_iterator
const_reverse_iterator rend() const
SimpleArray(T *Dat, size_t Cp, size_t Sz=0)
void reserve(size_t Ncp, MemRegionRef A)
llvm::iterator_range< reverse_iterator > reverse()
llvm::iterator_range< const_reverse_iterator > reverse() const
const_iterator cend() const
void push_back(const T &Elem)
std::reverse_iterator< const_iterator > const_reverse_iterator
SimpleArray(MemRegionRef A, size_t Cp)
const_iterator end() const
const_iterator cbegin() const
const_reverse_iterator rbegin() const
SimpleArray & operator=(SimpleArray &&RHS)
const T & operator[](unsigned i) const
SimpleArray(const SimpleArray< T > &A)=delete
T & operator[](unsigned i)
void reserveCheck(size_t N, MemRegionRef A)
std::ostream & operator<<(std::ostream &ss, const StringRef str)
std::string getSourceLiteralString(const Expr *CE)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T