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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30#ifndef LLVM_ADT_SCOPEDHASHTABLE_H

31#define LLVM_ADT_SCOPEDHASHTABLE_H

32

36#include

37#include

38

39namespace llvm {

40

41template <typename K, typename V, typename KInfo = DenseMapInfo,

42 typename AllocatorTy = MallocAllocator>

43class ScopedHashTable;

44

45template <typename K, typename V>

49 K Key;

50 V Val;

51

52 ScopedHashTableVal(const K &key, const V &val) : Key(key), Val(val) {}

53

54public:

55 const K &getKey() const { return Key; }

56 const V &getValue() const { return Val; }

58

62

63 template

66 const K &key, const V &val,

69

71 New->NextInScope = nextInScope;

72 New->NextForKey = nextForKey;

73 return New;

74 }

75

76 template void Destroy(AllocatorTy &Allocator) {

77

80 }

81};

82

83template <typename K, typename V, typename KInfo = DenseMapInfo,

84 typename AllocatorTy = MallocAllocator>

86

88

89

91

92

93

95

96public:

101

104

105private:

107

109 return LastValInScope;

110 }

111

112 void setLastValInScope(ScopedHashTableVal<K, V> *Val) {

113 LastValInScope = Val;

114 }

115};

116

117template <typename K, typename V, typename KInfo = DenseMapInfo>

120

121public:

123

126 return Node->getValue();

127 }

129 return &Node->getValue();

130 }

131

134 }

137 }

138

140 assert(Node && "incrementing past end()");

141 Node = Node->getNextForKey();

142 return *this;

143 }

146 }

147};

148

149template <typename K, typename V, typename KInfo, typename AllocatorTy>

152

153public:

154

155

158

159private:

161

163

165 ScopeTy *CurScope = nullptr;

166

167public:

172

174 assert(!CurScope && TopLevelMap.empty() && "Scope imbalance!");

175 }

176

177

179

180

182 return TopLevelMap.count(Key);

183 }

184

186 auto I = TopLevelMap.find(Key);

187 if (I != TopLevelMap.end())

188 return I->second->getValue();

189

190 return V();

191 }

192

193 void insert(const K &Key, const V &Val) {

195 }

196

198

200

203 TopLevelMap.find(Key);

204 if (I == TopLevelMap.end()) return end();

206 }

207

210

211

212

213

214

216 assert(S && "No scope active!");

218 KeyEntry = ValTy::Create(S->getLastValInScope(), KeyEntry, Key, Val,

220 S->setLastValInScope(KeyEntry);

221 }

222};

223

224

225

226template <typename K, typename V, typename KInfo, typename Allocator>

229 PrevScope = HT.CurScope;

230 HT.CurScope = this;

231 LastValInScope = nullptr;

232}

233

234template <typename K, typename V, typename KInfo, typename Allocator>

236 assert(HT.CurScope == this && "Scope imbalance!");

237 HT.CurScope = PrevScope;

238

239

241

242 if (!ThisEntry->getNextForKey()) {

243 assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&

244 "Scope imbalance!");

245 HT.TopLevelMap.erase(ThisEntry->getKey());

246 } else {

248 assert(KeyEntry == ThisEntry && "Scope imbalance!");

250 }

251

252

254

255

256 ThisEntry->Destroy(HT.getAllocator());

257 }

258}

259

260}

261

262#endif

This file defines MallocAllocator.

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

This file defines DenseMapInfo traits for DenseMap.

This file defines the DenseMap class.

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

iterator find(const_arg_type_t< KeyT > Val)

size_type count(const_arg_type_t< KeyT > Val) const

Return 1 if the specified key is in the map, 0 otherwise.

ScopedHashTableIterator(ScopedHashTableVal< K, V > *node)

bool operator==(const ScopedHashTableIterator &RHS) const

ScopedHashTableIterator & operator++()

bool operator!=(const ScopedHashTableIterator &RHS) const

ScopedHashTableIterator operator++(int)

ScopedHashTableScope & operator=(ScopedHashTableScope &)=delete

ScopedHashTableScope(ScopedHashTableScope &)=delete

const ScopedHashTableScope * getParentScope() const

ScopedHashTableScope * getParentScope()

ScopedHashTableScope(ScopedHashTable< K, V, KInfo, AllocatorTy > &HT)

ScopedHashTableVal * getNextInScope()

ScopedHashTableVal * getNextForKey()

static ScopedHashTableVal * Create(ScopedHashTableVal *nextInScope, ScopedHashTableVal *nextForKey, const K &key, const V &val, AllocatorTy &Allocator)

const ScopedHashTableVal * getNextForKey() const

const V & getValue() const

void Destroy(AllocatorTy &Allocator)

iterator begin(const K &Key)

ScopedHashTable(AllocatorTy A)

ScopedHashTable()=default

void insertIntoScope(ScopeTy *S, const K &Key, const V &Val)

insertIntoScope - This inserts the specified key/value at the specified (possibly not the current) sc...

size_type count(const K &Key) const

Return 1 if the specified key is in the table, 0 otherwise.

const ScopeTy * getCurScope() const

void insert(const K &Key, const V &Val)

V lookup(const K &Key) const

ScopedHashTable(const ScopedHashTable &)=delete

ScopedHashTable & operator=(const ScopedHashTable &)=delete

ScopedHashTableIterator< K, V, KInfo > iterator

AllocatorTy & getAllocator()

This is an optimization pass for GlobalISel generic memory operations.