blob: d2e35b8eb676d264cbf8b17d59d754ca73127c8e [file] [log] [blame]
Jim Laskey0e5af192006-10-27 16:16:16 +00001//===-- Support/FoldingSet.cpp - Uniquing Hash Set --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey0e5af192006-10-27 16:16:16 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements a hash set that can be used to remove duplication of
11// nodes in a graph. This code was originally created by Chris Lattner for use
12// with SelectionDAGCSEMap, but was isolated to provide use across the llvm code
13// set.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/ADT/FoldingSet.h"
Dan Gohmanc93b4cf2010-03-18 16:16:38 +000018#include "llvm/Support/Allocator.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000019#include "llvm/Support/ErrorHandling.h"
Bill Wendling160db5d2006-10-27 18:47:29 +000020#include "llvm/Support/MathExtras.h"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000021#include "llvm/Support/Host.h"
Rafael Espindola39c6d3a2006-11-03 01:38:14 +000022#include <cassert>
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000023#include <cstring>
Jim Laskey0e5af192006-10-27 16:16:16 +000024using namespace llvm;
25
26//===----------------------------------------------------------------------===//
Dan Gohman30634102010-08-16 15:30:39 +000027// FoldingSetNodeIDRef Implementation
28
29/// ComputeHash - Compute a strong hash value for this FoldingSetNodeIDRef,
30/// used to lookup the node in the FoldingSetImpl.
31unsigned FoldingSetNodeIDRef::ComputeHash() const {
32 // This is adapted from SuperFastHash by Paul Hsieh.
33 unsigned Hash = static_cast<unsigned>(Size);
34 for (const unsigned *BP = Data, *E = BP+Size; BP != E; ++BP) {
35 unsigned Data = *BP;
36 Hash += Data & 0xFFFF;
37 unsigned Tmp = ((Data >> 16) << 11) ^ Hash;
38 Hash = (Hash << 16) ^ Tmp;
39 Hash += Hash >> 11;
40 }
41
42 // Force "avalanching" of final 127 bits.
43 Hash ^= Hash << 3;
44 Hash += Hash >> 5;
45 Hash ^= Hash << 4;
46 Hash += Hash >> 17;
47 Hash ^= Hash << 25;
48 Hash += Hash >> 6;
49 return Hash;
50}
51
52bool FoldingSetNodeIDRef::operator==(FoldingSetNodeIDRef RHS) const {
53 if (Size != RHS.Size) return false;
54 return memcmp(Data, RHS.Data, Size*sizeof(*Data)) == 0;
55}
56
57//===----------------------------------------------------------------------===//
Ted Kremenek0a3feca2008-01-19 04:22:50 +000058// FoldingSetNodeID Implementation
Jim Laskey0e5af192006-10-27 16:16:16 +000059
60/// Add* - Add various data types to Bit data.
61///
Ted Kremenek0a3feca2008-01-19 04:22:50 +000062void FoldingSetNodeID::AddPointer(const void *Ptr) {
Jim Laskey0e5af192006-10-27 16:16:16 +000063 // Note: this adds pointers to the hash using sizes and endianness that
64 // depend on the host. It doesn't matter however, because hashing on
65 // pointer values in inherently unstable. Nothing should depend on the
66 // ordering of nodes in the folding set.
67 intptr_t PtrI = (intptr_t)Ptr;
68 Bits.push_back(unsigned(PtrI));
69 if (sizeof(intptr_t) > sizeof(unsigned))
70 Bits.push_back(unsigned(uint64_t(PtrI) >> 32));
71}
Ted Kremenek0a3feca2008-01-19 04:22:50 +000072void FoldingSetNodeID::AddInteger(signed I) {
Jim Laskey0e5af192006-10-27 16:16:16 +000073 Bits.push_back(I);
74}
Ted Kremenek0a3feca2008-01-19 04:22:50 +000075void FoldingSetNodeID::AddInteger(unsigned I) {
Jim Laskey0e5af192006-10-27 16:16:16 +000076 Bits.push_back(I);
77}
Dan Gohman20cd13f2008-11-03 19:40:18 +000078void FoldingSetNodeID::AddInteger(long I) {
79 AddInteger((unsigned long)I);
Dan Gohmanf82e1e62007-09-14 20:48:42 +000080}
Dan Gohman20cd13f2008-11-03 19:40:18 +000081void FoldingSetNodeID::AddInteger(unsigned long I) {
82 if (sizeof(long) == sizeof(int))
83 AddInteger(unsigned(I));
84 else if (sizeof(long) == sizeof(long long)) {
85 AddInteger((unsigned long long)I);
86 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +000087 llvm_unreachable("unexpected sizeof(long)");
Dan Gohman20cd13f2008-11-03 19:40:18 +000088 }
89}
90void FoldingSetNodeID::AddInteger(long long I) {
91 AddInteger((unsigned long long)I);
92}
93void FoldingSetNodeID::AddInteger(unsigned long long I) {
94 AddInteger(unsigned(I));
Chris Lattnere4116f82007-02-04 01:48:10 +000095 if ((uint64_t)(int)I != I)
96 Bits.push_back(unsigned(I >> 32));
Jim Laskey0e5af192006-10-27 16:16:16 +000097}
Owen Anderson72e61b82008-07-01 23:49:59 +000098
Daniel Dunbar27dba672009-09-22 03:34:53 +000099void FoldingSetNodeID::AddString(StringRef String) {
100 unsigned Size = String.size();
Owen Anderson72e61b82008-07-01 23:49:59 +0000101 Bits.push_back(Size);
102 if (!Size) return;
103
104 unsigned Units = Size / 4;
105 unsigned Pos = 0;
Daniel Dunbar27dba672009-09-22 03:34:53 +0000106 const unsigned *Base = (const unsigned*) String.data();
Owen Anderson72e61b82008-07-01 23:49:59 +0000107
108 // If the string is aligned do a bulk transfer.
109 if (!((intptr_t)Base & 3)) {
110 Bits.append(Base, Base + Units);
111 Pos = (Units + 1) * 4;
112 } else {
113 // Otherwise do it the hard way.
Dale Johannesenc81c7fe2010-11-19 00:48:58 +0000114 // To be compatible with above bulk transfer, we need to take endianness
115 // into account.
116 if (sys::isBigEndianHost()) {
117 for (Pos += 4; Pos <= Size; Pos += 4) {
118 unsigned V = ((unsigned char)String[Pos - 4] << 24) |
119 ((unsigned char)String[Pos - 3] << 16) |
120 ((unsigned char)String[Pos - 2] << 8) |
121 (unsigned char)String[Pos - 1];
122 Bits.push_back(V);
123 }
124 } else {
125 assert(sys::isLittleEndianHost() && "Unexpected host endianness");
126 for (Pos += 4; Pos <= Size; Pos += 4) {
127 unsigned V = ((unsigned char)String[Pos - 1] << 24) |
128 ((unsigned char)String[Pos - 2] << 16) |
129 ((unsigned char)String[Pos - 3] << 8) |
130 (unsigned char)String[Pos - 4];
131 Bits.push_back(V);
132 }
Owen Anderson72e61b82008-07-01 23:49:59 +0000133 }
134 }
135
136 // With the leftover bits.
137 unsigned V = 0;
Dale Johannesenc81c7fe2010-11-19 00:48:58 +0000138 // Pos will have overshot size by 4 - #bytes left over.
139 // No need to take endianness into account here - this is always executed.
Owen Anderson72e61b82008-07-01 23:49:59 +0000140 switch (Pos - Size) {
141 case 1: V = (V << 8) | (unsigned char)String[Size - 3]; // Fall thru.
142 case 2: V = (V << 8) | (unsigned char)String[Size - 2]; // Fall thru.
143 case 3: V = (V << 8) | (unsigned char)String[Size - 1]; break;
144 default: return; // Nothing left.
145 }
146
147 Bits.push_back(V);
148}
149
Chris Lattnere27c3ea2011-04-25 20:58:50 +0000150// AddNodeID - Adds the Bit data of another ID to *this.
151void FoldingSetNodeID::AddNodeID(const FoldingSetNodeID &ID) {
152 Bits.append(ID.Bits.begin(), ID.Bits.end());
153}
154
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000155/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to
Jim Laskey0e5af192006-10-27 16:16:16 +0000156/// lookup the node in the FoldingSetImpl.
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000157unsigned FoldingSetNodeID::ComputeHash() const {
Dan Gohman365c53e2010-08-24 23:16:53 +0000158 return FoldingSetNodeIDRef(Bits.data(), Bits.size()).ComputeHash();
Jim Laskey0e5af192006-10-27 16:16:16 +0000159}
160
161/// operator== - Used to compare two nodes to each other.
162///
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000163bool FoldingSetNodeID::operator==(const FoldingSetNodeID &RHS)const{
Dan Gohman365c53e2010-08-24 23:16:53 +0000164 return *this == FoldingSetNodeIDRef(RHS.Bits.data(), RHS.Bits.size());
Dan Gohman30634102010-08-16 15:30:39 +0000165}
166
167/// operator== - Used to compare two nodes to each other.
168///
169bool FoldingSetNodeID::operator==(FoldingSetNodeIDRef RHS) const {
Dan Gohman365c53e2010-08-24 23:16:53 +0000170 return FoldingSetNodeIDRef(Bits.data(), Bits.size()) == RHS;
Jim Laskey0e5af192006-10-27 16:16:16 +0000171}
172
Dan Gohmanc93b4cf2010-03-18 16:16:38 +0000173/// Intern - Copy this node's data to a memory region allocated from the
174/// given allocator and return a FoldingSetNodeIDRef describing the
175/// interned data.
176FoldingSetNodeIDRef
177FoldingSetNodeID::Intern(BumpPtrAllocator &Allocator) const {
178 unsigned *New = Allocator.Allocate<unsigned>(Bits.size());
179 std::uninitialized_copy(Bits.begin(), Bits.end(), New);
180 return FoldingSetNodeIDRef(New, Bits.size());
181}
Jim Laskey0e5af192006-10-27 16:16:16 +0000182
183//===----------------------------------------------------------------------===//
Jim Laskey18529f32006-10-27 18:05:12 +0000184/// Helper functions for FoldingSetImpl.
185
186/// GetNextPtr - In order to save space, each bucket is a
187/// singly-linked-list. In order to make deletion more efficient, we make
188/// the list circular, so we can delete a node without computing its hash.
189/// The problem with this is that the start of the hash buckets are not
Chris Lattner3cab0712007-01-30 23:16:22 +0000190/// Nodes. If NextInBucketPtr is a bucket pointer, this method returns null:
191/// use GetBucketPtr when this happens.
Chris Lattner9a7288b2007-10-03 20:45:43 +0000192static FoldingSetImpl::Node *GetNextPtr(void *NextInBucketPtr) {
193 // The low bit is set if this is the pointer back to the bucket.
194 if (reinterpret_cast<intptr_t>(NextInBucketPtr) & 1)
Jim Laskey18529f32006-10-27 18:05:12 +0000195 return 0;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000196
Jim Laskey18529f32006-10-27 18:05:12 +0000197 return static_cast<FoldingSetImpl::Node*>(NextInBucketPtr);
198}
199
Ted Kremenek26e3c442008-02-04 21:11:17 +0000200
Jim Laskey18529f32006-10-27 18:05:12 +0000201/// testing.
202static void **GetBucketPtr(void *NextInBucketPtr) {
Chris Lattner9a7288b2007-10-03 20:45:43 +0000203 intptr_t Ptr = reinterpret_cast<intptr_t>(NextInBucketPtr);
Chris Lattner116c3212007-10-03 21:12:09 +0000204 assert((Ptr & 1) && "Not a bucket pointer");
Chris Lattner9a7288b2007-10-03 20:45:43 +0000205 return reinterpret_cast<void**>(Ptr & ~intptr_t(1));
Jim Laskey18529f32006-10-27 18:05:12 +0000206}
207
208/// GetBucketFor - Hash the specified node ID and return the hash bucket for
209/// the specified ID.
Dan Gohman30634102010-08-16 15:30:39 +0000210static void **GetBucketFor(unsigned Hash, void **Buckets, unsigned NumBuckets) {
Jim Laskey18529f32006-10-27 18:05:12 +0000211 // NumBuckets is always a power of 2.
Dan Gohman30634102010-08-16 15:30:39 +0000212 unsigned BucketNum = Hash & (NumBuckets-1);
Jim Laskey18529f32006-10-27 18:05:12 +0000213 return Buckets + BucketNum;
214}
215
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000216/// AllocateBuckets - Allocated initialized bucket memory.
217static void **AllocateBuckets(unsigned NumBuckets) {
218 void **Buckets = static_cast<void**>(calloc(NumBuckets+1, sizeof(void*)));
219 // Set the very last bucket to be a non-null "pointer".
220 Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
221 return Buckets;
222}
223
Jim Laskey18529f32006-10-27 18:05:12 +0000224//===----------------------------------------------------------------------===//
Jim Laskey0e5af192006-10-27 16:16:16 +0000225// FoldingSetImpl Implementation
226
Dan Gohman535de1a2008-08-23 00:42:16 +0000227FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) {
Jim Laskey1f67a992006-11-02 14:21:26 +0000228 assert(5 < Log2InitSize && Log2InitSize < 32 &&
229 "Initial hash table size out of range");
230 NumBuckets = 1 << Log2InitSize;
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000231 Buckets = AllocateBuckets(NumBuckets);
232 NumNodes = 0;
Jim Laskey0e5af192006-10-27 16:16:16 +0000233}
234FoldingSetImpl::~FoldingSetImpl() {
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000235 free(Buckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000236}
Dan Gohman535de1a2008-08-23 00:42:16 +0000237void FoldingSetImpl::clear() {
238 // Set all but the last bucket to null pointers.
239 memset(Buckets, 0, NumBuckets*sizeof(void*));
240
241 // Set the very last bucket to be a non-null "pointer".
242 Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
243
244 // Reset the node count to zero.
245 NumNodes = 0;
246}
Jim Laskey0e5af192006-10-27 16:16:16 +0000247
Jim Laskey0e5af192006-10-27 16:16:16 +0000248/// GrowHashTable - Double the size of the hash table and rehash everything.
249///
250void FoldingSetImpl::GrowHashTable() {
251 void **OldBuckets = Buckets;
252 unsigned OldNumBuckets = NumBuckets;
253 NumBuckets <<= 1;
254
Jim Laskey0e5af192006-10-27 16:16:16 +0000255 // Clear out new buckets.
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000256 Buckets = AllocateBuckets(NumBuckets);
257 NumNodes = 0;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000258
Jim Laskey0e5af192006-10-27 16:16:16 +0000259 // Walk the old buckets, rehashing nodes into their new place.
Dan Gohman30634102010-08-16 15:30:39 +0000260 FoldingSetNodeID TempID;
Jim Laskey0e5af192006-10-27 16:16:16 +0000261 for (unsigned i = 0; i != OldNumBuckets; ++i) {
262 void *Probe = OldBuckets[i];
263 if (!Probe) continue;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000264 while (Node *NodeInBucket = GetNextPtr(Probe)) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000265 // Figure out the next link, remove NodeInBucket from the old link.
266 Probe = NodeInBucket->getNextInBucket();
267 NodeInBucket->SetNextInBucket(0);
268
269 // Insert the node into the new bucket, after recomputing the hash.
Dan Gohman30634102010-08-16 15:30:39 +0000270 InsertNode(NodeInBucket,
271 GetBucketFor(ComputeNodeHash(NodeInBucket, TempID),
272 Buckets, NumBuckets));
273 TempID.clear();
Jim Laskey0e5af192006-10-27 16:16:16 +0000274 }
275 }
276
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000277 free(OldBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000278}
279
280/// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
281/// return it. If not, return the insertion token that will make insertion
282/// faster.
Ted Kremenek27a8e0d2008-02-04 17:14:20 +0000283FoldingSetImpl::Node
284*FoldingSetImpl::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
285 void *&InsertPos) {
286
Dan Gohman30634102010-08-16 15:30:39 +0000287 void **Bucket = GetBucketFor(ID.ComputeHash(), Buckets, NumBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000288 void *Probe = *Bucket;
289
290 InsertPos = 0;
291
Dan Gohman30634102010-08-16 15:30:39 +0000292 FoldingSetNodeID TempID;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000293 while (Node *NodeInBucket = GetNextPtr(Probe)) {
Dan Gohman30634102010-08-16 15:30:39 +0000294 if (NodeEquals(NodeInBucket, ID, TempID))
Jim Laskey0e5af192006-10-27 16:16:16 +0000295 return NodeInBucket;
Dan Gohman30634102010-08-16 15:30:39 +0000296 TempID.clear();
Jim Laskey0e5af192006-10-27 16:16:16 +0000297
298 Probe = NodeInBucket->getNextInBucket();
299 }
300
301 // Didn't find the node, return null with the bucket as the InsertPos.
302 InsertPos = Bucket;
303 return 0;
304}
305
306/// InsertNode - Insert the specified node into the folding set, knowing that it
307/// is not already in the map. InsertPos must be obtained from
308/// FindNodeOrInsertPos.
309void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
Chris Lattner0de44392007-02-01 05:33:21 +0000310 assert(N->getNextInBucket() == 0);
Jim Laskey0e5af192006-10-27 16:16:16 +0000311 // Do we need to grow the hashtable?
Chris Lattnerb85210f2007-01-31 06:04:41 +0000312 if (NumNodes+1 > NumBuckets*2) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000313 GrowHashTable();
Dan Gohman30634102010-08-16 15:30:39 +0000314 FoldingSetNodeID TempID;
315 InsertPos = GetBucketFor(ComputeNodeHash(N, TempID), Buckets, NumBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000316 }
Chris Lattnerb85210f2007-01-31 06:04:41 +0000317
318 ++NumNodes;
Jim Laskey0e5af192006-10-27 16:16:16 +0000319
320 /// The insert position is actually a bucket pointer.
321 void **Bucket = static_cast<void**>(InsertPos);
322
323 void *Next = *Bucket;
324
325 // If this is the first insertion into this bucket, its next pointer will be
Chris Lattner9a7288b2007-10-03 20:45:43 +0000326 // null. Pretend as if it pointed to itself, setting the low bit to indicate
327 // that it is a pointer to the bucket.
Jim Laskey0e5af192006-10-27 16:16:16 +0000328 if (Next == 0)
Chris Lattner9a7288b2007-10-03 20:45:43 +0000329 Next = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(Bucket)|1);
Jim Laskey0e5af192006-10-27 16:16:16 +0000330
Chris Lattnerb85210f2007-01-31 06:04:41 +0000331 // Set the node's next pointer, and make the bucket point to the node.
Jim Laskey0e5af192006-10-27 16:16:16 +0000332 N->SetNextInBucket(Next);
333 *Bucket = N;
334}
335
336/// RemoveNode - Remove a node from the folding set, returning true if one was
337/// removed or false if the node was not in the folding set.
338bool FoldingSetImpl::RemoveNode(Node *N) {
339 // Because each bucket is a circular list, we don't need to compute N's hash
Chris Lattner0de44392007-02-01 05:33:21 +0000340 // to remove it.
Jim Laskey0e5af192006-10-27 16:16:16 +0000341 void *Ptr = N->getNextInBucket();
342 if (Ptr == 0) return false; // Not in folding set.
343
344 --NumNodes;
Jim Laskey0e5af192006-10-27 16:16:16 +0000345 N->SetNextInBucket(0);
Chris Lattner0de44392007-02-01 05:33:21 +0000346
347 // Remember what N originally pointed to, either a bucket or another node.
348 void *NodeNextPtr = Ptr;
349
350 // Chase around the list until we find the node (or bucket) which points to N.
Jim Laskey0e5af192006-10-27 16:16:16 +0000351 while (true) {
Chris Lattner9a7288b2007-10-03 20:45:43 +0000352 if (Node *NodeInBucket = GetNextPtr(Ptr)) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000353 // Advance pointer.
354 Ptr = NodeInBucket->getNextInBucket();
355
356 // We found a node that points to N, change it to point to N's next node,
357 // removing N from the list.
358 if (Ptr == N) {
359 NodeInBucket->SetNextInBucket(NodeNextPtr);
360 return true;
361 }
362 } else {
363 void **Bucket = GetBucketPtr(Ptr);
364 Ptr = *Bucket;
365
366 // If we found that the bucket points to N, update the bucket to point to
367 // whatever is next.
368 if (Ptr == N) {
369 *Bucket = NodeNextPtr;
370 return true;
371 }
372 }
373 }
374}
375
376/// GetOrInsertNode - If there is an existing simple Node exactly
377/// equal to the specified node, return it. Otherwise, insert 'N' and it
378/// instead.
379FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) {
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000380 FoldingSetNodeID ID;
Dan Gohman6616f7e2010-08-16 14:53:42 +0000381 GetNodeProfile(N, ID);
Jim Laskey0e5af192006-10-27 16:16:16 +0000382 void *IP;
383 if (Node *E = FindNodeOrInsertPos(ID, IP))
384 return E;
385 InsertNode(N, IP);
386 return N;
387}
Chris Lattner116c3212007-10-03 21:12:09 +0000388
389//===----------------------------------------------------------------------===//
390// FoldingSetIteratorImpl Implementation
391
392FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) {
393 // Skip to the first non-null non-self-cycle bucket.
Ted Kremeneke3e09572008-02-15 21:12:46 +0000394 while (*Bucket != reinterpret_cast<void*>(-1) &&
395 (*Bucket == 0 || GetNextPtr(*Bucket) == 0))
Chris Lattner116c3212007-10-03 21:12:09 +0000396 ++Bucket;
397
398 NodePtr = static_cast<FoldingSetNode*>(*Bucket);
399}
400
401void FoldingSetIteratorImpl::advance() {
402 // If there is another link within this bucket, go to it.
403 void *Probe = NodePtr->getNextInBucket();
404
405 if (FoldingSetNode *NextNodeInBucket = GetNextPtr(Probe))
406 NodePtr = NextNodeInBucket;
407 else {
408 // Otherwise, this is the last link in this bucket.
409 void **Bucket = GetBucketPtr(Probe);
410
411 // Skip to the next non-null non-self-cycle bucket.
412 do {
413 ++Bucket;
Ted Kremeneke3e09572008-02-15 21:12:46 +0000414 } while (*Bucket != reinterpret_cast<void*>(-1) &&
415 (*Bucket == 0 || GetNextPtr(*Bucket) == 0));
Chris Lattner116c3212007-10-03 21:12:09 +0000416
417 NodePtr = static_cast<FoldingSetNode*>(*Bucket);
418 }
419}
420
Ted Kremenek26e3c442008-02-04 21:11:17 +0000421//===----------------------------------------------------------------------===//
422// FoldingSetBucketIteratorImpl Implementation
423
424FoldingSetBucketIteratorImpl::FoldingSetBucketIteratorImpl(void **Bucket) {
425 Ptr = (*Bucket == 0 || GetNextPtr(*Bucket) == 0) ? (void*) Bucket : *Bucket;
426}