libswift: Add the StackList data structure

StackList is a very efficient data structure for worklist type things.
This is a port of the C++ utility with the same name.

Compared to Array, it does not require any memory allocations.
This commit is contained in:
Erik Eckstein
2021-04-23 20:26:42 +02:00
parent d49108da07
commit 14422cdb50
8 changed files with 235 additions and 5 deletions

View File

@@ -57,10 +57,10 @@ class Output;
namespace swift {
/// A fixed size slab of memory, which can be allocated and freed by the
/// SILModule at (basically) zero cost.
class FixedSizeSlab : public llvm::ilist_node<FixedSizeSlab>,
public SILAllocated<FixedSizeSlab> {
/// The payload for the FixedSizeSlab.
/// This is a super-class rather than a member of FixedSizeSlab to make bridging
/// with libswift easier.
class FixedSizeSlabPayload {
public:
/// The capacity of the payload.
static constexpr size_t capacity = 64 * sizeof(uintptr_t);
@@ -78,7 +78,7 @@ private:
uintptr_t overflowGuard = magicNumber;
public:
void operator=(const FixedSizeSlab &) = delete;
void operator=(const FixedSizeSlabPayload &) = delete;
void operator delete(void *Ptr, size_t) = delete;
/// Returns the payload pointing to \p T.
@@ -88,6 +88,17 @@ public:
template<typename T> const T *dataFor() const { return (const T *)(&data[0]); }
};
/// A fixed size slab of memory, which can be allocated and freed by the
/// SILModule at (basically) zero cost.
/// See SILModule::allocSlab().
class FixedSizeSlab : public llvm::ilist_node<FixedSizeSlab>,
public SILAllocated<FixedSizeSlab>,
public FixedSizeSlabPayload {
public:
void operator=(const FixedSizeSlab &) = delete;
void operator delete(void *Ptr, size_t) = delete;
};
class AnyFunctionType;
class ASTContext;
class FileUnit;