LLVM: include/llvm/ADT/AllocatorList.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_ADT_ALLOCATORLIST_H

10#define LLVM_ADT_ALLOCATORLIST_H

11

16#include

17#include

18#include

19#include <type_traits>

20#include

21

22namespace llvm {

23

24

25

26

27

28

29

30

31

32

33template <class T, class AllocatorT> class AllocatorList : AllocatorT {

35 Node(Node &&) = delete;

36 Node(const Node &) = delete;

37 Node &operator=(Node &&) = delete;

38 Node &operator=(const Node &) = delete;

39

40 Node(T &&V) : V(std::move(V)) {}

41 Node(const T &V) : V(V) {}

42 template <class... Ts> Node(Ts &&... Vs) : V(std::forward(Vs)...) {}

43 T V;

44 };

45

47

48 list_type List;

49

50 AllocatorT &getAlloc() { return *this; }

51 const AllocatorT &getAlloc() const { return *this; }

52

53 template <class... ArgTs> Node *create(ArgTs &&... Args) {

54 return new (getAlloc()) Node(std::forward(Args)...);

55 }

56

57 struct Cloner {

59

61

62 Node *operator()(const Node &N) const { return AL.create(N.V); }

63 };

64

65 struct Disposer {

67

69

70 void operator()(Node *N) const {

71 N->~Node();

72 AL.getAlloc().Deallocate(N);

73 }

74 };

75

76public:

84

85private:

86 template <class ValueT, class IteratorBase>

87 class IteratorImpl

89 IteratorBase,

90 std::bidirectional_iterator_tag, ValueT> {

91 template <class OtherValueT, class OtherIteratorBase>

92 friend class IteratorImpl;

94

95 using base_type =

97 std::bidirectional_iterator_tag, ValueT>;

98

99 public:

101 using pointer = ValueT *;

103

104 IteratorImpl() = default;

105 IteratorImpl(const IteratorImpl &) = default;

106 IteratorImpl &operator=(const IteratorImpl &) = default;

107

108 explicit IteratorImpl(const IteratorBase &I) : base_type(I) {}

109

110 template <class OtherValueT, class OtherIteratorBase>

111 IteratorImpl(const IteratorImpl<OtherValueT, OtherIteratorBase> &X,

112 std::enable_if_t<std::is_convertible<

113 OtherIteratorBase, IteratorBase>::value> * = nullptr)

114 : base_type(X.wrapped()) {}

115

116 ~IteratorImpl() = default;

117

120 };

121

122public:

123 using iterator = IteratorImpl<T, typename list_type::iterator>;

125 IteratorImpl<T, typename list_type::reverse_iterator>;

127 IteratorImpl<const T, typename list_type::const_iterator>;

129 IteratorImpl<const T, typename list_type::const_reverse_iterator>;

130

134

136 List.cloneFrom(X.List, Cloner(*this), Disposer(*this));

137 }

138

140 clear();

141 List = std::move(X.List);

142 getAlloc() = std::move(X.getAlloc());

143 return *this;

144 }

145

147 List.cloneFrom(X.List, Cloner(*this), Disposer(*this));

148 return *this;

149 }

150

152

154 List.swap(RHS.List);

156 }

157

158 [[nodiscard]] bool empty() const { return List.empty(); }

159 [[nodiscard]] size_t size() const { return List.size(); }

160

173

174 T &back() { return List.back().V; }

175 T &front() { return List.front().V; }

176 const T &back() const { return List.back().V; }

177 const T &front() const { return List.front().V; }

178

180 return iterator(List.insert(I.wrapped(), *create(std::forward(Vs)...)));

181 }

182

184 return iterator(List.insert(I.wrapped(), *create(std::move(V))));

185 }

187 return iterator(List.insert(I.wrapped(), *create(V)));

188 }

189

190 template

193 List.insert(I.wrapped(), *create(*First));

194 }

195

197 return iterator(List.eraseAndDispose(I.wrapped(), Disposer(*this)));

198 }

199

202 List.eraseAndDispose(First.wrapped(), Last.wrapped(), Disposer(*this)));

203 }

204

205 void clear() { List.clearAndDispose(Disposer(*this)); }

206 void pop_back() { List.eraseAndDispose(--List.end(), Disposer(*this)); }

207 void pop_front() { List.eraseAndDispose(List.begin(), Disposer(*this)); }

213 emplace(end(), std::forward(Vs)...);

214 }

218

219

220

221

223 assert(empty() && "Cannot reset allocator if not empty");

224 getAlloc().Reset();

225 }

226};

227

229

230}

231

232#endif

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

This file defines the BumpPtrAllocator interface.

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

A linked-list with a custom, local allocator.

Definition AllocatorList.h:33

void emplace_back(Ts &&... Vs)

Definition AllocatorList.h:212

const_iterator end() const

Definition AllocatorList.h:164

AllocatorList(AllocatorList &&X)

Definition AllocatorList.h:132

void insert(iterator I, Iterator First, Iterator Last)

Definition AllocatorList.h:191

const T & back() const

Definition AllocatorList.h:176

const_reverse_iterator rend() const

Definition AllocatorList.h:170

void push_back(T &&V)

Definition AllocatorList.h:208

~AllocatorList()

Definition AllocatorList.h:151

IteratorImpl< T, typename list_type::reverse_iterator > reverse_iterator

Definition AllocatorList.h:124

typename list_type::size_type size_type

Definition AllocatorList.h:82

iterator erase(iterator First, iterator Last)

Definition AllocatorList.h:200

const_iterator begin() const

Definition AllocatorList.h:163

AllocatorList & operator=(const AllocatorList &X)

Definition AllocatorList.h:146

void push_back(const T &V)

Definition AllocatorList.h:210

void pop_back()

Definition AllocatorList.h:206

iterator begin()

Definition AllocatorList.h:161

void emplace_front(Ts &&... Vs)

Definition AllocatorList.h:215

void pop_front()

Definition AllocatorList.h:207

iterator erase(iterator I)

Definition AllocatorList.h:196

iterator emplace(iterator I, Ts &&... Vs)

Definition AllocatorList.h:179

iterator insert(iterator I, T &&V)

Definition AllocatorList.h:183

void resetAlloc()

Definition AllocatorList.h:222

const_reverse_iterator rbegin() const

Definition AllocatorList.h:167

IteratorImpl< T, typename list_type::iterator > iterator

Definition AllocatorList.h:123

iterator end()

Definition AllocatorList.h:162

typename list_type::difference_type difference_type

Definition AllocatorList.h:83

reverse_iterator rend()

Definition AllocatorList.h:166

const T * const_pointer

Definition AllocatorList.h:80

IteratorImpl< const T, typename list_type::const_reverse_iterator > const_reverse_iterator

Definition AllocatorList.h:128

size_t size() const

Definition AllocatorList.h:159

const T & front() const

Definition AllocatorList.h:177

T & front()

Definition AllocatorList.h:175

void push_front(const T &V)

Definition AllocatorList.h:211

AllocatorList & operator=(AllocatorList &&X)

Definition AllocatorList.h:139

T & reference

Definition AllocatorList.h:79

iterator insert(iterator I, const T &V)

Definition AllocatorList.h:186

void push_front(T &&V)

Definition AllocatorList.h:209

const T & const_reference

Definition AllocatorList.h:81

T value_type

Definition AllocatorList.h:77

AllocatorList(const AllocatorList &X)

Definition AllocatorList.h:135

void swap(AllocatorList &RHS)

Definition AllocatorList.h:153

T & back()

Definition AllocatorList.h:174

bool empty() const

Definition AllocatorList.h:158

void clear()

Definition AllocatorList.h:205

reverse_iterator rbegin()

Definition AllocatorList.h:165

T * pointer

Definition AllocatorList.h:78

IteratorImpl< const T, typename list_type::const_iterator > const_iterator

Definition AllocatorList.h:126

CRTP base class for adapting an iterator to a different type.

const IteratorBase & wrapped() const

std::conditional_t< std::is_same< ValueT, typename std::iterator_traits< IteratorBase >::value_type >::value, typename std::iterator_traits< IteratorBase >::reference, ValueT & > operator*() const

PointerProxy operator->() const

A simple intrusive list implementation.

ptrdiff_t difference_type

This file defines the ilist_node class template, which is a convenient base class for creating classe...

This is an optimization pass for GlobalISel generic memory operations.

@ First

Helpers to iterate all locations in the MemoryEffectsBase class.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

AllocatorList< T, BumpPtrAllocator > BumpPtrList

Definition AllocatorList.h:228

Implement std::hash so that hash_code can be used in STL containers.

void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)

Implement std::swap in terms of BitVector swap.