blob: 17b827132f577077f20cd4ef0e7bab790d9dd940 [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.
Benjamin Kramer8d4dd792011-07-18 00:00:20 +000067 Bits.append(reinterpret_cast<unsigned *>(&Ptr),
68 reinterpret_cast<unsigned *>(&Ptr+1));
Jim Laskey0e5af192006-10-27 16:16:16 +000069}
Ted Kremenek0a3feca2008-01-19 04:22:50 +000070void FoldingSetNodeID::AddInteger(signed I) {
Jim Laskey0e5af192006-10-27 16:16:16 +000071 Bits.push_back(I);
72}
Ted Kremenek0a3feca2008-01-19 04:22:50 +000073void FoldingSetNodeID::AddInteger(unsigned I) {
Jim Laskey0e5af192006-10-27 16:16:16 +000074 Bits.push_back(I);
75}
Dan Gohman20cd13f2008-11-03 19:40:18 +000076void FoldingSetNodeID::AddInteger(long I) {
77 AddInteger((unsigned long)I);
Dan Gohmanf82e1e62007-09-14 20:48:42 +000078}
Dan Gohman20cd13f2008-11-03 19:40:18 +000079void FoldingSetNodeID::AddInteger(unsigned long I) {
80 if (sizeof(long) == sizeof(int))
81 AddInteger(unsigned(I));
82 else if (sizeof(long) == sizeof(long long)) {
83 AddInteger((unsigned long long)I);
84 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +000085 llvm_unreachable("unexpected sizeof(long)");
Dan Gohman20cd13f2008-11-03 19:40:18 +000086 }
87}
88void FoldingSetNodeID::AddInteger(long long I) {
89 AddInteger((unsigned long long)I);
90}
91void FoldingSetNodeID::AddInteger(unsigned long long I) {
92 AddInteger(unsigned(I));
Zhongxing Xu422b62b2011-06-03 08:29:51 +000093 if ((uint64_t)(unsigned)I != I)
Chris Lattnere4116f82007-02-04 01:48:10 +000094 Bits.push_back(unsigned(I >> 32));
Jim Laskey0e5af192006-10-27 16:16:16 +000095}
Owen Anderson72e61b82008-07-01 23:49:59 +000096
Daniel Dunbar27dba672009-09-22 03:34:53 +000097void FoldingSetNodeID::AddString(StringRef String) {
98 unsigned Size = String.size();
Owen Anderson72e61b82008-07-01 23:49:59 +000099 Bits.push_back(Size);
100 if (!Size) return;
101
102 unsigned Units = Size / 4;
103 unsigned Pos = 0;
Daniel Dunbar27dba672009-09-22 03:34:53 +0000104 const unsigned *Base = (const unsigned*) String.data();
Owen Anderson72e61b82008-07-01 23:49:59 +0000105
106 // If the string is aligned do a bulk transfer.
107 if (!((intptr_t)Base & 3)) {
108 Bits.append(Base, Base + Units);
109 Pos = (Units + 1) * 4;
110 } else {
111 // Otherwise do it the hard way.
Dale Johannesenc81c7fe2010-11-19 00:48:58 +0000112 // To be compatible with above bulk transfer, we need to take endianness
113 // into account.
114 if (sys::isBigEndianHost()) {
115 for (Pos += 4; Pos <= Size; Pos += 4) {
116 unsigned V = ((unsigned char)String[Pos - 4] << 24) |
117 ((unsigned char)String[Pos - 3] << 16) |
118 ((unsigned char)String[Pos - 2] << 8) |
119 (unsigned char)String[Pos - 1];
120 Bits.push_back(V);
121 }
122 } else {
123 assert(sys::isLittleEndianHost() && "Unexpected host endianness");
124 for (Pos += 4; Pos <= Size; Pos += 4) {
125 unsigned V = ((unsigned char)String[Pos - 1] << 24) |
126 ((unsigned char)String[Pos - 2] << 16) |
127 ((unsigned char)String[Pos - 3] << 8) |
128 (unsigned char)String[Pos - 4];
129 Bits.push_back(V);
130 }
Owen Anderson72e61b82008-07-01 23:49:59 +0000131 }
132 }
133
134 // With the leftover bits.
135 unsigned V = 0;
Dale Johannesenc81c7fe2010-11-19 00:48:58 +0000136 // Pos will have overshot size by 4 - #bytes left over.
137 // No need to take endianness into account here - this is always executed.
Owen Anderson72e61b82008-07-01 23:49:59 +0000138 switch (Pos - Size) {
139 case 1: V = (V << 8) | (unsigned char)String[Size - 3]; // Fall thru.
140 case 2: V = (V << 8) | (unsigned char)String[Size - 2]; // Fall thru.
141 case 3: V = (V << 8) | (unsigned char)String[Size - 1]; break;
142 default: return; // Nothing left.
143 }
144
145 Bits.push_back(V);
146}
147
Chris Lattnere27c3ea2011-04-25 20:58:50 +0000148// AddNodeID - Adds the Bit data of another ID to *this.
149void FoldingSetNodeID::AddNodeID(const FoldingSetNodeID &ID) {
150 Bits.append(ID.Bits.begin(), ID.Bits.end());
151}
152
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000153/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to
Jim Laskey0e5af192006-10-27 16:16:16 +0000154/// lookup the node in the FoldingSetImpl.
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000155unsigned FoldingSetNodeID::ComputeHash() const {
Dan Gohman365c53e2010-08-24 23:16:53 +0000156 return FoldingSetNodeIDRef(Bits.data(), Bits.size()).ComputeHash();
Jim Laskey0e5af192006-10-27 16:16:16 +0000157}
158
159/// operator== - Used to compare two nodes to each other.
160///
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000161bool FoldingSetNodeID::operator==(const FoldingSetNodeID &RHS)const{
Dan Gohman365c53e2010-08-24 23:16:53 +0000162 return *this == FoldingSetNodeIDRef(RHS.Bits.data(), RHS.Bits.size());
Dan Gohman30634102010-08-16 15:30:39 +0000163}
164
165/// operator== - Used to compare two nodes to each other.
166///
167bool FoldingSetNodeID::operator==(FoldingSetNodeIDRef RHS) const {
Dan Gohman365c53e2010-08-24 23:16:53 +0000168 return FoldingSetNodeIDRef(Bits.data(), Bits.size()) == RHS;
Jim Laskey0e5af192006-10-27 16:16:16 +0000169}
170
Dan Gohmanc93b4cf2010-03-18 16:16:38 +0000171/// Intern - Copy this node's data to a memory region allocated from the
172/// given allocator and return a FoldingSetNodeIDRef describing the
173/// interned data.
174FoldingSetNodeIDRef
175FoldingSetNodeID::Intern(BumpPtrAllocator &Allocator) const {
176 unsigned *New = Allocator.Allocate<unsigned>(Bits.size());
177 std::uninitialized_copy(Bits.begin(), Bits.end(), New);
178 return FoldingSetNodeIDRef(New, Bits.size());
179}
Jim Laskey0e5af192006-10-27 16:16:16 +0000180
181//===----------------------------------------------------------------------===//
Jim Laskey18529f32006-10-27 18:05:12 +0000182/// Helper functions for FoldingSetImpl.
183
184/// GetNextPtr - In order to save space, each bucket is a
185/// singly-linked-list. In order to make deletion more efficient, we make
186/// the list circular, so we can delete a node without computing its hash.
187/// The problem with this is that the start of the hash buckets are not
Chris Lattner3cab0712007-01-30 23:16:22 +0000188/// Nodes. If NextInBucketPtr is a bucket pointer, this method returns null:
189/// use GetBucketPtr when this happens.
Chris Lattner9a7288b2007-10-03 20:45:43 +0000190static FoldingSetImpl::Node *GetNextPtr(void *NextInBucketPtr) {
191 // The low bit is set if this is the pointer back to the bucket.
192 if (reinterpret_cast<intptr_t>(NextInBucketPtr) & 1)
Jim Laskey18529f32006-10-27 18:05:12 +0000193 return 0;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000194
Jim Laskey18529f32006-10-27 18:05:12 +0000195 return static_cast<FoldingSetImpl::Node*>(NextInBucketPtr);
196}
197
Ted Kremenek26e3c442008-02-04 21:11:17 +0000198
Jim Laskey18529f32006-10-27 18:05:12 +0000199/// testing.
200static void **GetBucketPtr(void *NextInBucketPtr) {
Chris Lattner9a7288b2007-10-03 20:45:43 +0000201 intptr_t Ptr = reinterpret_cast<intptr_t>(NextInBucketPtr);
Chris Lattner116c3212007-10-03 21:12:09 +0000202 assert((Ptr & 1) && "Not a bucket pointer");
Chris Lattner9a7288b2007-10-03 20:45:43 +0000203 return reinterpret_cast<void**>(Ptr & ~intptr_t(1));
Jim Laskey18529f32006-10-27 18:05:12 +0000204}
205
206/// GetBucketFor - Hash the specified node ID and return the hash bucket for
207/// the specified ID.
Dan Gohman30634102010-08-16 15:30:39 +0000208static void **GetBucketFor(unsigned Hash, void **Buckets, unsigned NumBuckets) {
Jim Laskey18529f32006-10-27 18:05:12 +0000209 // NumBuckets is always a power of 2.
Dan Gohman30634102010-08-16 15:30:39 +0000210 unsigned BucketNum = Hash & (NumBuckets-1);
Jim Laskey18529f32006-10-27 18:05:12 +0000211 return Buckets + BucketNum;
212}
213
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000214/// AllocateBuckets - Allocated initialized bucket memory.
215static void **AllocateBuckets(unsigned NumBuckets) {
216 void **Buckets = static_cast<void**>(calloc(NumBuckets+1, sizeof(void*)));
217 // Set the very last bucket to be a non-null "pointer".
218 Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
219 return Buckets;
220}
221
Jim Laskey18529f32006-10-27 18:05:12 +0000222//===----------------------------------------------------------------------===//
Jim Laskey0e5af192006-10-27 16:16:16 +0000223// FoldingSetImpl Implementation
224
Dan Gohman535de1a2008-08-23 00:42:16 +0000225FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) {
Jim Laskey1f67a992006-11-02 14:21:26 +0000226 assert(5 < Log2InitSize && Log2InitSize < 32 &&
227 "Initial hash table size out of range");
228 NumBuckets = 1 << Log2InitSize;
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000229 Buckets = AllocateBuckets(NumBuckets);
230 NumNodes = 0;
Jim Laskey0e5af192006-10-27 16:16:16 +0000231}
232FoldingSetImpl::~FoldingSetImpl() {
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000233 free(Buckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000234}
Dan Gohman535de1a2008-08-23 00:42:16 +0000235void FoldingSetImpl::clear() {
236 // Set all but the last bucket to null pointers.
237 memset(Buckets, 0, NumBuckets*sizeof(void*));
238
239 // Set the very last bucket to be a non-null "pointer".
240 Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
241
242 // Reset the node count to zero.
243 NumNodes = 0;
244}
Jim Laskey0e5af192006-10-27 16:16:16 +0000245
Jim Laskey0e5af192006-10-27 16:16:16 +0000246/// GrowHashTable - Double the size of the hash table and rehash everything.
247///
248void FoldingSetImpl::GrowHashTable() {
249 void **OldBuckets = Buckets;
250 unsigned OldNumBuckets = NumBuckets;
251 NumBuckets <<= 1;
252
Jim Laskey0e5af192006-10-27 16:16:16 +0000253 // Clear out new buckets.
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000254 Buckets = AllocateBuckets(NumBuckets);
255 NumNodes = 0;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000256
Jim Laskey0e5af192006-10-27 16:16:16 +0000257 // Walk the old buckets, rehashing nodes into their new place.
Dan Gohman30634102010-08-16 15:30:39 +0000258 FoldingSetNodeID TempID;
Jim Laskey0e5af192006-10-27 16:16:16 +0000259 for (unsigned i = 0; i != OldNumBuckets; ++i) {
260 void *Probe = OldBuckets[i];
261 if (!Probe) continue;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000262 while (Node *NodeInBucket = GetNextPtr(Probe)) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000263 // Figure out the next link, remove NodeInBucket from the old link.
264 Probe = NodeInBucket->getNextInBucket();
265 NodeInBucket->SetNextInBucket(0);
266
267 // Insert the node into the new bucket, after recomputing the hash.
Dan Gohman30634102010-08-16 15:30:39 +0000268 InsertNode(NodeInBucket,
269 GetBucketFor(ComputeNodeHash(NodeInBucket, TempID),
270 Buckets, NumBuckets));
271 TempID.clear();
Jim Laskey0e5af192006-10-27 16:16:16 +0000272 }
273 }
274
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000275 free(OldBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000276}
277
278/// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
279/// return it. If not, return the insertion token that will make insertion
280/// faster.
Ted Kremenek27a8e0d2008-02-04 17:14:20 +0000281FoldingSetImpl::Node
282*FoldingSetImpl::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
283 void *&InsertPos) {
284
Dan Gohman30634102010-08-16 15:30:39 +0000285 void **Bucket = GetBucketFor(ID.ComputeHash(), Buckets, NumBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000286 void *Probe = *Bucket;
287
288 InsertPos = 0;
289
Dan Gohman30634102010-08-16 15:30:39 +0000290 FoldingSetNodeID TempID;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000291 while (Node *NodeInBucket = GetNextPtr(Probe)) {
Dan Gohman30634102010-08-16 15:30:39 +0000292 if (NodeEquals(NodeInBucket, ID, TempID))
Jim Laskey0e5af192006-10-27 16:16:16 +0000293 return NodeInBucket;
Dan Gohman30634102010-08-16 15:30:39 +0000294 TempID.clear();
Jim Laskey0e5af192006-10-27 16:16:16 +0000295
296 Probe = NodeInBucket->getNextInBucket();
297 }
298
299 // Didn't find the node, return null with the bucket as the InsertPos.
300 InsertPos = Bucket;
301 return 0;
302}
303
304/// InsertNode - Insert the specified node into the folding set, knowing that it
305/// is not already in the map. InsertPos must be obtained from
306/// FindNodeOrInsertPos.
307void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
Chris Lattner0de44392007-02-01 05:33:21 +0000308 assert(N->getNextInBucket() == 0);
Jim Laskey0e5af192006-10-27 16:16:16 +0000309 // Do we need to grow the hashtable?
Chris Lattnerb85210f2007-01-31 06:04:41 +0000310 if (NumNodes+1 > NumBuckets*2) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000311 GrowHashTable();
Dan Gohman30634102010-08-16 15:30:39 +0000312 FoldingSetNodeID TempID;
313 InsertPos = GetBucketFor(ComputeNodeHash(N, TempID), Buckets, NumBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000314 }
Chris Lattnerb85210f2007-01-31 06:04:41 +0000315
316 ++NumNodes;
Jim Laskey0e5af192006-10-27 16:16:16 +0000317
318 /// The insert position is actually a bucket pointer.
319 void **Bucket = static_cast<void**>(InsertPos);
320
321 void *Next = *Bucket;
322
323 // If this is the first insertion into this bucket, its next pointer will be
Chris Lattner9a7288b2007-10-03 20:45:43 +0000324 // null. Pretend as if it pointed to itself, setting the low bit to indicate
325 // that it is a pointer to the bucket.
Jim Laskey0e5af192006-10-27 16:16:16 +0000326 if (Next == 0)
Chris Lattner9a7288b2007-10-03 20:45:43 +0000327 Next = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(Bucket)|1);
Jim Laskey0e5af192006-10-27 16:16:16 +0000328
Chris Lattnerb85210f2007-01-31 06:04:41 +0000329 // Set the node's next pointer, and make the bucket point to the node.
Jim Laskey0e5af192006-10-27 16:16:16 +0000330 N->SetNextInBucket(Next);
331 *Bucket = N;
332}
333
334/// RemoveNode - Remove a node from the folding set, returning true if one was
335/// removed or false if the node was not in the folding set.
336bool FoldingSetImpl::RemoveNode(Node *N) {
337 // Because each bucket is a circular list, we don't need to compute N's hash
Chris Lattner0de44392007-02-01 05:33:21 +0000338 // to remove it.
Jim Laskey0e5af192006-10-27 16:16:16 +0000339 void *Ptr = N->getNextInBucket();
340 if (Ptr == 0) return false; // Not in folding set.
341
342 --NumNodes;
Jim Laskey0e5af192006-10-27 16:16:16 +0000343 N->SetNextInBucket(0);
Chris Lattner0de44392007-02-01 05:33:21 +0000344
345 // Remember what N originally pointed to, either a bucket or another node.
346 void *NodeNextPtr = Ptr;
347
348 // Chase around the list until we find the node (or bucket) which points to N.
Jim Laskey0e5af192006-10-27 16:16:16 +0000349 while (true) {
Chris Lattner9a7288b2007-10-03 20:45:43 +0000350 if (Node *NodeInBucket = GetNextPtr(Ptr)) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000351 // Advance pointer.
352 Ptr = NodeInBucket->getNextInBucket();
353
354 // We found a node that points to N, change it to point to N's next node,
355 // removing N from the list.
356 if (Ptr == N) {
357 NodeInBucket->SetNextInBucket(NodeNextPtr);
358 return true;
359 }
360 } else {
361 void **Bucket = GetBucketPtr(Ptr);
362 Ptr = *Bucket;
363
364 // If we found that the bucket points to N, update the bucket to point to
365 // whatever is next.
366 if (Ptr == N) {
367 *Bucket = NodeNextPtr;
368 return true;
369 }
370 }
371 }
372}
373
374/// GetOrInsertNode - If there is an existing simple Node exactly
375/// equal to the specified node, return it. Otherwise, insert 'N' and it
376/// instead.
377FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) {
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000378 FoldingSetNodeID ID;
Dan Gohman6616f7e2010-08-16 14:53:42 +0000379 GetNodeProfile(N, ID);
Jim Laskey0e5af192006-10-27 16:16:16 +0000380 void *IP;
381 if (Node *E = FindNodeOrInsertPos(ID, IP))
382 return E;
383 InsertNode(N, IP);
384 return N;
385}
Chris Lattner116c3212007-10-03 21:12:09 +0000386
387//===----------------------------------------------------------------------===//
388// FoldingSetIteratorImpl Implementation
389
390FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) {
391 // Skip to the first non-null non-self-cycle bucket.
Ted Kremeneke3e09572008-02-15 21:12:46 +0000392 while (*Bucket != reinterpret_cast<void*>(-1) &&
393 (*Bucket == 0 || GetNextPtr(*Bucket) == 0))
Chris Lattner116c3212007-10-03 21:12:09 +0000394 ++Bucket;
395
396 NodePtr = static_cast<FoldingSetNode*>(*Bucket);
397}
398
399void FoldingSetIteratorImpl::advance() {
400 // If there is another link within this bucket, go to it.
401 void *Probe = NodePtr->getNextInBucket();
402
403 if (FoldingSetNode *NextNodeInBucket = GetNextPtr(Probe))
404 NodePtr = NextNodeInBucket;
405 else {
406 // Otherwise, this is the last link in this bucket.
407 void **Bucket = GetBucketPtr(Probe);
408
409 // Skip to the next non-null non-self-cycle bucket.
410 do {
411 ++Bucket;
Ted Kremeneke3e09572008-02-15 21:12:46 +0000412 } while (*Bucket != reinterpret_cast<void*>(-1) &&
413 (*Bucket == 0 || GetNextPtr(*Bucket) == 0));
Chris Lattner116c3212007-10-03 21:12:09 +0000414
415 NodePtr = static_cast<FoldingSetNode*>(*Bucket);
416 }
417}
418
Ted Kremenek26e3c442008-02-04 21:11:17 +0000419//===----------------------------------------------------------------------===//
420// FoldingSetBucketIteratorImpl Implementation
421
422FoldingSetBucketIteratorImpl::FoldingSetBucketIteratorImpl(void **Bucket) {
423 Ptr = (*Bucket == 0 || GetNextPtr(*Bucket) == 0) ? (void*) Bucket : *Bucket;
424}