Skip to content

Commit 39f68f7

Browse files
[ADT][NFC] Move FoldingSetBase definition lower in the file (#172503)
This is required for #172371, where `FoldingSetBase::FindNodeOrInsertPos` needs full definition of `FoldingSetNodeID`.
1 parent 8725400 commit 39f68f7

File tree

1 file changed

+121
-121
lines changed

1 file changed

+121
-121
lines changed

llvm/include/llvm/ADT/FoldingSet.h

Lines changed: 121 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -108,127 +108,6 @@ namespace llvm {
108108
class FoldingSetNodeID;
109109
class StringRef;
110110

111-
//===----------------------------------------------------------------------===//
112-
/// FoldingSetBase - Implements the folding set functionality. The main
113-
/// structure is an array of buckets. Each bucket is indexed by the hash of
114-
/// the nodes it contains. The bucket itself points to the nodes contained
115-
/// in the bucket via a singly linked list. The last node in the list points
116-
/// back to the bucket to facilitate node removal.
117-
///
118-
class FoldingSetBase {
119-
protected:
120-
/// Buckets - Array of bucket chains.
121-
void **Buckets;
122-
123-
/// NumBuckets - Length of the Buckets array. Always a power of 2.
124-
unsigned NumBuckets;
125-
126-
/// NumNodes - Number of nodes in the folding set. Growth occurs when NumNodes
127-
/// is greater than twice the number of buckets.
128-
unsigned NumNodes;
129-
130-
LLVM_ABI explicit FoldingSetBase(unsigned Log2InitSize = 6);
131-
LLVM_ABI FoldingSetBase(FoldingSetBase &&Arg);
132-
LLVM_ABI FoldingSetBase &operator=(FoldingSetBase &&RHS);
133-
LLVM_ABI ~FoldingSetBase();
134-
135-
public:
136-
//===--------------------------------------------------------------------===//
137-
/// Node - This class is used to maintain the singly linked bucket list in
138-
/// a folding set.
139-
class Node {
140-
private:
141-
// NextInFoldingSetBucket - next link in the bucket list.
142-
void *NextInFoldingSetBucket = nullptr;
143-
144-
public:
145-
Node() = default;
146-
147-
// Accessors
148-
void *getNextInBucket() const { return NextInFoldingSetBucket; }
149-
void SetNextInBucket(void *N) { NextInFoldingSetBucket = N; }
150-
};
151-
152-
/// clear - Remove all nodes from the folding set.
153-
LLVM_ABI void clear();
154-
155-
/// size - Returns the number of nodes in the folding set.
156-
unsigned size() const { return NumNodes; }
157-
158-
/// empty - Returns true if there are no nodes in the folding set.
159-
bool empty() const { return NumNodes == 0; }
160-
161-
/// capacity - Returns the number of nodes permitted in the folding set
162-
/// before a rebucket operation is performed.
163-
unsigned capacity() {
164-
// We allow a load factor of up to 2.0,
165-
// so that means our capacity is NumBuckets * 2
166-
return NumBuckets * 2;
167-
}
168-
169-
protected:
170-
/// Functions provided by the derived class to compute folding properties.
171-
/// This is effectively a vtable for FoldingSetBase, except that we don't
172-
/// actually store a pointer to it in the object.
173-
struct FoldingSetInfo {
174-
/// GetNodeProfile - Instantiations of the FoldingSet template implement
175-
/// this function to gather data bits for the given node.
176-
void (*GetNodeProfile)(const FoldingSetBase *Self, Node *N,
177-
FoldingSetNodeID &ID);
178-
179-
/// NodeEquals - Instantiations of the FoldingSet template implement
180-
/// this function to compare the given node with the given ID.
181-
bool (*NodeEquals)(const FoldingSetBase *Self, Node *N,
182-
const FoldingSetNodeID &ID, unsigned IDHash,
183-
FoldingSetNodeID &TempID);
184-
185-
/// ComputeNodeHash - Instantiations of the FoldingSet template implement
186-
/// this function to compute a hash value for the given node.
187-
unsigned (*ComputeNodeHash)(const FoldingSetBase *Self, Node *N,
188-
FoldingSetNodeID &TempID);
189-
};
190-
191-
private:
192-
/// GrowHashTable - Double the size of the hash table and rehash everything.
193-
void GrowHashTable(const FoldingSetInfo &Info);
194-
195-
/// GrowBucketCount - resize the hash table and rehash everything.
196-
/// NewBucketCount must be a power of two, and must be greater than the old
197-
/// bucket count.
198-
void GrowBucketCount(unsigned NewBucketCount, const FoldingSetInfo &Info);
199-
200-
protected:
201-
// The below methods are protected to encourage subclasses to provide a more
202-
// type-safe API.
203-
204-
/// reserve - Increase the number of buckets such that adding the
205-
/// EltCount-th node won't cause a rebucket operation. reserve is permitted
206-
/// to allocate more space than requested by EltCount.
207-
LLVM_ABI void reserve(unsigned EltCount, const FoldingSetInfo &Info);
208-
209-
/// RemoveNode - Remove a node from the folding set, returning true if one
210-
/// was removed or false if the node was not in the folding set.
211-
LLVM_ABI bool RemoveNode(Node *N);
212-
213-
/// GetOrInsertNode - If there is an existing simple Node exactly
214-
/// equal to the specified node, return it. Otherwise, insert 'N' and return
215-
/// it instead.
216-
LLVM_ABI Node *GetOrInsertNode(Node *N, const FoldingSetInfo &Info);
217-
218-
/// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
219-
/// return it. If not, return the insertion token that will make insertion
220-
/// faster.
221-
LLVM_ABI Node *FindNodeOrInsertPos(const FoldingSetNodeID &ID,
222-
void *&InsertPos,
223-
const FoldingSetInfo &Info);
224-
225-
/// InsertNode - Insert the specified node into the folding set, knowing that
226-
/// it is not already in the folding set. InsertPos must be obtained from
227-
/// FindNodeOrInsertPos.
228-
LLVM_ABI void InsertNode(Node *N, void *InsertPos,
229-
const FoldingSetInfo &Info);
230-
};
231-
232111
//===----------------------------------------------------------------------===//
233112

234113
/// DefaultFoldingSetTrait - This class provides default implementations
@@ -404,6 +283,127 @@ class FoldingSetNodeID {
404283
LLVM_ABI FoldingSetNodeIDRef Intern(BumpPtrAllocator &Allocator) const;
405284
};
406285

286+
//===----------------------------------------------------------------------===//
287+
/// FoldingSetBase - Implements the folding set functionality. The main
288+
/// structure is an array of buckets. Each bucket is indexed by the hash of
289+
/// the nodes it contains. The bucket itself points to the nodes contained
290+
/// in the bucket via a singly linked list. The last node in the list points
291+
/// back to the bucket to facilitate node removal.
292+
///
293+
class FoldingSetBase {
294+
protected:
295+
/// Buckets - Array of bucket chains.
296+
void **Buckets;
297+
298+
/// NumBuckets - Length of the Buckets array. Always a power of 2.
299+
unsigned NumBuckets;
300+
301+
/// NumNodes - Number of nodes in the folding set. Growth occurs when NumNodes
302+
/// is greater than twice the number of buckets.
303+
unsigned NumNodes;
304+
305+
LLVM_ABI explicit FoldingSetBase(unsigned Log2InitSize = 6);
306+
LLVM_ABI FoldingSetBase(FoldingSetBase &&Arg);
307+
LLVM_ABI FoldingSetBase &operator=(FoldingSetBase &&RHS);
308+
LLVM_ABI ~FoldingSetBase();
309+
310+
public:
311+
//===--------------------------------------------------------------------===//
312+
/// Node - This class is used to maintain the singly linked bucket list in
313+
/// a folding set.
314+
class Node {
315+
private:
316+
// NextInFoldingSetBucket - next link in the bucket list.
317+
void *NextInFoldingSetBucket = nullptr;
318+
319+
public:
320+
Node() = default;
321+
322+
// Accessors
323+
void *getNextInBucket() const { return NextInFoldingSetBucket; }
324+
void SetNextInBucket(void *N) { NextInFoldingSetBucket = N; }
325+
};
326+
327+
/// clear - Remove all nodes from the folding set.
328+
LLVM_ABI void clear();
329+
330+
/// size - Returns the number of nodes in the folding set.
331+
unsigned size() const { return NumNodes; }
332+
333+
/// empty - Returns true if there are no nodes in the folding set.
334+
bool empty() const { return NumNodes == 0; }
335+
336+
/// capacity - Returns the number of nodes permitted in the folding set
337+
/// before a rebucket operation is performed.
338+
unsigned capacity() {
339+
// We allow a load factor of up to 2.0,
340+
// so that means our capacity is NumBuckets * 2
341+
return NumBuckets * 2;
342+
}
343+
344+
protected:
345+
/// Functions provided by the derived class to compute folding properties.
346+
/// This is effectively a vtable for FoldingSetBase, except that we don't
347+
/// actually store a pointer to it in the object.
348+
struct FoldingSetInfo {
349+
/// GetNodeProfile - Instantiations of the FoldingSet template implement
350+
/// this function to gather data bits for the given node.
351+
void (*GetNodeProfile)(const FoldingSetBase *Self, Node *N,
352+
FoldingSetNodeID &ID);
353+
354+
/// NodeEquals - Instantiations of the FoldingSet template implement
355+
/// this function to compare the given node with the given ID.
356+
bool (*NodeEquals)(const FoldingSetBase *Self, Node *N,
357+
const FoldingSetNodeID &ID, unsigned IDHash,
358+
FoldingSetNodeID &TempID);
359+
360+
/// ComputeNodeHash - Instantiations of the FoldingSet template implement
361+
/// this function to compute a hash value for the given node.
362+
unsigned (*ComputeNodeHash)(const FoldingSetBase *Self, Node *N,
363+
FoldingSetNodeID &TempID);
364+
};
365+
366+
private:
367+
/// GrowHashTable - Double the size of the hash table and rehash everything.
368+
void GrowHashTable(const FoldingSetInfo &Info);
369+
370+
/// GrowBucketCount - resize the hash table and rehash everything.
371+
/// NewBucketCount must be a power of two, and must be greater than the old
372+
/// bucket count.
373+
void GrowBucketCount(unsigned NewBucketCount, const FoldingSetInfo &Info);
374+
375+
protected:
376+
// The below methods are protected to encourage subclasses to provide a more
377+
// type-safe API.
378+
379+
/// reserve - Increase the number of buckets such that adding the
380+
/// EltCount-th node won't cause a rebucket operation. reserve is permitted
381+
/// to allocate more space than requested by EltCount.
382+
LLVM_ABI void reserve(unsigned EltCount, const FoldingSetInfo &Info);
383+
384+
/// RemoveNode - Remove a node from the folding set, returning true if one
385+
/// was removed or false if the node was not in the folding set.
386+
LLVM_ABI bool RemoveNode(Node *N);
387+
388+
/// GetOrInsertNode - If there is an existing simple Node exactly
389+
/// equal to the specified node, return it. Otherwise, insert 'N' and return
390+
/// it instead.
391+
LLVM_ABI Node *GetOrInsertNode(Node *N, const FoldingSetInfo &Info);
392+
393+
/// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
394+
/// return it. If not, return the insertion token that will make insertion
395+
/// faster.
396+
LLVM_ABI Node *FindNodeOrInsertPos(const FoldingSetNodeID &ID,
397+
void *&InsertPos,
398+
const FoldingSetInfo &Info);
399+
400+
/// InsertNode - Insert the specified node into the folding set, knowing that
401+
/// it is not already in the folding set. InsertPos must be obtained from
402+
/// FindNodeOrInsertPos.
403+
LLVM_ABI void InsertNode(Node *N, void *InsertPos,
404+
const FoldingSetInfo &Info);
405+
};
406+
407407
// Convenience type to hide the implementation of the folding set.
408408
using FoldingSetNode = FoldingSetBase::Node;
409409
template<class T> class FoldingSetIterator;

0 commit comments

Comments
 (0)