9#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_ARRAYLIST_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_ARRAYLIST_H
16namespace dwarf_linker {
23template <
typename T,
size_t ItemsGroupSize = 512>
class ArrayList {
42 CurItemsCount = CurGroup->
ItemsCount.fetch_add(1);
45 if (CurItemsCount < ItemsGroupSize)
56 CurGroup->
Items[CurItemsCount] = Item;
57 return CurGroup->
Items[CurItemsCount];
65 CurGroup = CurGroup->Next) {
66 for (
T &Item : *CurGroup)
84 if (SortedItems.
size()) {
85 std::sort(SortedItems.
begin(), SortedItems.
end(), Comparator);
87 size_t SortedItemIdx = 0;
88 forEach([&](
T &Item) { Item = SortedItems[SortedItemIdx++]; });
97 CurGroup = CurGroup->Next)
98 Result += CurGroup->getItemsCount();
105 using ArrayTy = std::array<T, ItemsGroupSize>;
111 std::atomic<ItemsGroup *>
Next =
nullptr;
120 return std::min(
ItemsCount.load(), ItemsGroupSize);
137 NewGroup->
Next =
nullptr;
140 if (AtomicGroup.compare_exchange_weak(CurGroup, NewGroup))
148 if (CurGroup->
Next.compare_exchange_weak(NextGroup, NewGroup))
152 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.
T & add(const T &Item)
Add specified Item to the list.
std::atomic< ItemsGroup * > LastGroup
bool empty()
Check whether list is empty.
llvm::parallel::PerThreadBumpPtrAllocator * Allocator
bool allocateNewGroup(std::atomic< ItemsGroup * > &AtomicGroup)
void forEach(ItemHandlerTy Handler)
Enumerate all items and apply specified Handler to each.
std::atomic< ItemsGroup * > GroupsHead
void sort(function_ref< bool(const T &LHS, const T &RHS)> Comparator)
ArrayList(llvm::parallel::PerThreadBumpPtrAllocator *Allocator)
An efficient, type-erasing, non-owning reference to a callable.
PerThreadAllocator< BumpPtrAllocator > PerThreadBumpPtrAllocator
This is an optimization pass for GlobalISel generic memory operations.
std::array< T, ItemsGroupSize > ArrayTy
std::atomic< size_t > ItemsCount
std::atomic< ItemsGroup * > Next
ArrayTy::iterator begin()
size_t getItemsCount() const