9#ifndef LLVM_LIB_DWARFLINKERPARALLEL_ARRAYLIST_H
10#define LLVM_LIB_DWARFLINKERPARALLEL_ARRAYLIST_H
16namespace dwarflinker_parallel {
22template <
typename T,
size_t ItemsGroupSize = 512>
class ArrayList {
41 CurItemsCount = CurGroup->
ItemsCount.fetch_add(1);
44 if (CurItemsCount < ItemsGroupSize)
55 CurGroup->
Items[CurItemsCount] = Item;
56 return CurGroup->
Items[CurItemsCount];
64 CurGroup = CurGroup->Next) {
65 for (
T &Item : *CurGroup)
83 if (SortedItems.
size()) {
84 std::sort(SortedItems.
begin(), SortedItems.
end(), Comparator);
86 size_t SortedItemIdx = 0;
87 forEach([&](
T &Item) { Item = SortedItems[SortedItemIdx++]; });
96 CurGroup = CurGroup->Next)
97 Result += CurGroup->getItemsCount();
104 using ArrayTy = std::array<T, ItemsGroupSize>;
110 std::atomic<ItemsGroup *>
Next =
nullptr;
119 return std::min(
ItemsCount.load(), ItemsGroupSize);
136 NewGroup->
Next =
nullptr;
139 if (AtomicGroup.compare_exchange_weak(CurGroup, NewGroup))
147 if (CurGroup->
Next.compare_exchange_weak(NextGroup, NewGroup))
151 CurGroup = NextGroup;
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class is a simple list of T structures.
bool allocateNewGroup(std::atomic< ItemsGroup * > &AtomicGroup)
T & add(const T &Item)
Add specified Item to the list.
parallel::PerThreadBumpPtrAllocator * Allocator
void forEach(ItemHandlerTy Handler)
Enumerate all items and apply specified Handler to each.
std::atomic< ItemsGroup * > GroupsHead
bool empty()
Check whether list is empty.
ArrayList(parallel::PerThreadBumpPtrAllocator *Allocator)
void sort(function_ref< bool(const T &LHS, const T &RHS)> Comparator)
std::atomic< ItemsGroup * > LastGroup
An efficient, type-erasing, non-owning reference to a callable.
PerThreadAllocator< BumpPtrAllocator > PerThreadBumpPtrAllocator
This is an optimization pass for GlobalISel generic memory operations.
size_t getItemsCount() const
std::array< T, ItemsGroupSize > ArrayTy
std::atomic< size_t > ItemsCount
ArrayTy::iterator begin()
std::atomic< ItemsGroup * > Next