LLVM: include/llvm/Support/ArrayRecycler.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_SUPPORT_ARRAYRECYCLER_H

15#define LLVM_SUPPORT_ARRAYRECYCLER_H

16

20

21namespace llvm {

22

23

24

25

26

27

28template <class T, size_t Align = alignof(T)> class ArrayRecycler {

29

30

31 struct FreeList {

32 FreeList *Next;

33 };

34

35 static_assert(Align >= alignof(FreeList), "Object underaligned");

36 static_assert(sizeof(T) >= sizeof(FreeList), "Objects are too small");

37

38

40

41

42

43 T *pop(unsigned Idx) {

44 if (Idx >= Bucket.size())

45 return nullptr;

46 FreeList *Entry = Bucket[Idx];

47 if (!Entry)

48 return nullptr;

50 Bucket[Idx] = Entry->Next;

52 return reinterpret_cast<T*>(Entry);

53 }

54

55

56 void push(unsigned Idx, T *Ptr) {

57 assert(Ptr && "Cannot recycle NULL pointer");

58 FreeList *Entry = reinterpret_cast<FreeList*>(Ptr);

59 if (Idx >= Bucket.size())

60 Bucket.resize(size_t(Idx) + 1);

61 Entry->Next = Bucket[Idx];

62 Bucket[Idx] = Entry;

64 }

65

66public:

67

68

69

70

71 class Capacity {

74

75 public:

77

78

79 static Capacity get(size_t N) {

81 }

82

83

84 size_t getSize() const { return size_t(1u) << Index; }

85

86

87 unsigned getBucket() const { return Index; }

88

89

90

91

93 };

94

96

97

98 assert(Bucket.empty() && "Non-empty ArrayRecycler deleted!");

99 }

100

101

102

103 template

105 for (; !Bucket.empty(); Bucket.pop_back())

106 while (T *Ptr = pop(Bucket.size() - 1))

108 }

109

110

111

112

113

114

116 Bucket.clear();

117 }

118

119

120

121

122

123

124 template

126

127 if (T *Ptr = pop(Cap.getBucket()))

128 return Ptr;

129

130 return static_cast<T*>(Allocator.Allocate(sizeof(T)*Cap.getSize(), Align));

131 }

132

133

134

135

136

138 push(Cap.getBucket(), Ptr);

139 }

140};

141

142}

143

144#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file defines the BumpPtrAllocator interface.

#define __asan_poison_memory_region(p, size)

#define __asan_unpoison_memory_region(p, size)

#define __msan_allocated_memory(p, size)

This file defines the SmallVector class.

static unsigned getSize(unsigned Kind)

Capacity getNext() const

Get the next larger capacity.

Definition ArrayRecycler.h:92

size_t getSize() const

Get the number of elements in an array with this capacity.

Definition ArrayRecycler.h:84

static Capacity get(size_t N)

Get the capacity of an array that can hold at least N elements.

Definition ArrayRecycler.h:79

unsigned getBucket() const

Get the bucket number for this capacity.

Definition ArrayRecycler.h:87

Capacity()

Definition ArrayRecycler.h:76

Recycle small arrays allocated from a BumpPtrAllocator.

Definition ArrayRecycler.h:28

T * allocate(Capacity Cap, AllocatorType &Allocator)

Allocate an array of at least the requested capacity.

Definition ArrayRecycler.h:125

~ArrayRecycler()

Definition ArrayRecycler.h:95

void clear(BumpPtrAllocator &)

Special case for BumpPtrAllocator which has an empty Deallocate() function.

Definition ArrayRecycler.h:115

void clear(AllocatorType &Allocator)

Release all the tracked allocations to the allocator.

Definition ArrayRecycler.h:104

void deallocate(Capacity Cap, T *Ptr)

Deallocate an array with the specified Capacity.

Definition ArrayRecycler.h:137

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

This is an optimization pass for GlobalISel generic memory operations.

unsigned Log2_64_Ceil(uint64_t Value)

Return the ceil log base 2 of the specified value, 64 if the value is zero.

FunctionAddr VTableAddr Next

BumpPtrAllocatorImpl<> BumpPtrAllocator

The standard BumpPtrAllocator which just uses the default template parameters.

This struct is a compact representation of a valid (non-zero power of two) alignment.