blob: e029970b5865f5dddaef198262e94b6b396b60ca [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"
Chandler Carruthabe24cf2012-03-01 23:18:44 +000018#include "llvm/ADT/Hashing.h"
Dan Gohmanc93b4cf2010-03-18 16:16:38 +000019#include "llvm/Support/Allocator.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000020#include "llvm/Support/ErrorHandling.h"
Bill Wendling160db5d2006-10-27 18:47:29 +000021#include "llvm/Support/MathExtras.h"
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000022#include "llvm/Support/Host.h"
Rafael Espindola39c6d3a2006-11-03 01:38:14 +000023#include <cassert>
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000024#include <cstring>
Jim Laskey0e5af192006-10-27 16:16:16 +000025using namespace llvm;
26
27//===----------------------------------------------------------------------===//
Dan Gohman30634102010-08-16 15:30:39 +000028// FoldingSetNodeIDRef Implementation
29
30/// ComputeHash - Compute a strong hash value for this FoldingSetNodeIDRef,
31/// used to lookup the node in the FoldingSetImpl.
32unsigned FoldingSetNodeIDRef::ComputeHash() const {
Chandler Carruthabe24cf2012-03-01 23:18:44 +000033 return static_cast<unsigned>(hash_combine_range(Data, Data+Size));
Dan Gohman30634102010-08-16 15:30:39 +000034}
35
36bool FoldingSetNodeIDRef::operator==(FoldingSetNodeIDRef RHS) const {
37 if (Size != RHS.Size) return false;
38 return memcmp(Data, RHS.Data, Size*sizeof(*Data)) == 0;
39}
40
41//===----------------------------------------------------------------------===//
Ted Kremenek0a3feca2008-01-19 04:22:50 +000042// FoldingSetNodeID Implementation
Jim Laskey0e5af192006-10-27 16:16:16 +000043
44/// Add* - Add various data types to Bit data.
45///
Ted Kremenek0a3feca2008-01-19 04:22:50 +000046void FoldingSetNodeID::AddPointer(const void *Ptr) {
Jim Laskey0e5af192006-10-27 16:16:16 +000047 // Note: this adds pointers to the hash using sizes and endianness that
48 // depend on the host. It doesn't matter however, because hashing on
49 // pointer values in inherently unstable. Nothing should depend on the
50 // ordering of nodes in the folding set.
Benjamin Kramer8d4dd792011-07-18 00:00:20 +000051 Bits.append(reinterpret_cast<unsigned *>(&Ptr),
52 reinterpret_cast<unsigned *>(&Ptr+1));
Jim Laskey0e5af192006-10-27 16:16:16 +000053}
Ted Kremenek0a3feca2008-01-19 04:22:50 +000054void FoldingSetNodeID::AddInteger(signed I) {
Jim Laskey0e5af192006-10-27 16:16:16 +000055 Bits.push_back(I);
56}
Ted Kremenek0a3feca2008-01-19 04:22:50 +000057void FoldingSetNodeID::AddInteger(unsigned I) {
Jim Laskey0e5af192006-10-27 16:16:16 +000058 Bits.push_back(I);
59}
Dan Gohman20cd13f2008-11-03 19:40:18 +000060void FoldingSetNodeID::AddInteger(long I) {
61 AddInteger((unsigned long)I);
Dan Gohmanf82e1e62007-09-14 20:48:42 +000062}
Dan Gohman20cd13f2008-11-03 19:40:18 +000063void FoldingSetNodeID::AddInteger(unsigned long I) {
64 if (sizeof(long) == sizeof(int))
65 AddInteger(unsigned(I));
66 else if (sizeof(long) == sizeof(long long)) {
67 AddInteger((unsigned long long)I);
68 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +000069 llvm_unreachable("unexpected sizeof(long)");
Dan Gohman20cd13f2008-11-03 19:40:18 +000070 }
71}
72void FoldingSetNodeID::AddInteger(long long I) {
73 AddInteger((unsigned long long)I);
74}
75void FoldingSetNodeID::AddInteger(unsigned long long I) {
76 AddInteger(unsigned(I));
Zhongxing Xu422b62b2011-06-03 08:29:51 +000077 if ((uint64_t)(unsigned)I != I)
Chris Lattnere4116f82007-02-04 01:48:10 +000078 Bits.push_back(unsigned(I >> 32));
Jim Laskey0e5af192006-10-27 16:16:16 +000079}
Owen Anderson72e61b82008-07-01 23:49:59 +000080
Daniel Dunbar27dba672009-09-22 03:34:53 +000081void FoldingSetNodeID::AddString(StringRef String) {
82 unsigned Size = String.size();
Owen Anderson72e61b82008-07-01 23:49:59 +000083 Bits.push_back(Size);
84 if (!Size) return;
85
86 unsigned Units = Size / 4;
87 unsigned Pos = 0;
Daniel Dunbar27dba672009-09-22 03:34:53 +000088 const unsigned *Base = (const unsigned*) String.data();
Owen Anderson72e61b82008-07-01 23:49:59 +000089
90 // If the string is aligned do a bulk transfer.
91 if (!((intptr_t)Base & 3)) {
92 Bits.append(Base, Base + Units);
93 Pos = (Units + 1) * 4;
94 } else {
95 // Otherwise do it the hard way.
Dale Johannesenc81c7fe2010-11-19 00:48:58 +000096 // To be compatible with above bulk transfer, we need to take endianness
97 // into account.
98 if (sys::isBigEndianHost()) {
99 for (Pos += 4; Pos <= Size; Pos += 4) {
100 unsigned V = ((unsigned char)String[Pos - 4] << 24) |
101 ((unsigned char)String[Pos - 3] << 16) |
102 ((unsigned char)String[Pos - 2] << 8) |
103 (unsigned char)String[Pos - 1];
104 Bits.push_back(V);
105 }
106 } else {
107 assert(sys::isLittleEndianHost() && "Unexpected host endianness");
108 for (Pos += 4; Pos <= Size; Pos += 4) {
109 unsigned V = ((unsigned char)String[Pos - 1] << 24) |
110 ((unsigned char)String[Pos - 2] << 16) |
111 ((unsigned char)String[Pos - 3] << 8) |
112 (unsigned char)String[Pos - 4];
113 Bits.push_back(V);
114 }
Owen Anderson72e61b82008-07-01 23:49:59 +0000115 }
116 }
117
118 // With the leftover bits.
119 unsigned V = 0;
Dale Johannesenc81c7fe2010-11-19 00:48:58 +0000120 // Pos will have overshot size by 4 - #bytes left over.
121 // No need to take endianness into account here - this is always executed.
Owen Anderson72e61b82008-07-01 23:49:59 +0000122 switch (Pos - Size) {
123 case 1: V = (V << 8) | (unsigned char)String[Size - 3]; // Fall thru.
124 case 2: V = (V << 8) | (unsigned char)String[Size - 2]; // Fall thru.
125 case 3: V = (V << 8) | (unsigned char)String[Size - 1]; break;
126 default: return; // Nothing left.
127 }
128
129 Bits.push_back(V);
130}
131
Chris Lattnere27c3ea2011-04-25 20:58:50 +0000132// AddNodeID - Adds the Bit data of another ID to *this.
133void FoldingSetNodeID::AddNodeID(const FoldingSetNodeID &ID) {
134 Bits.append(ID.Bits.begin(), ID.Bits.end());
135}
136
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000137/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to
Jim Laskey0e5af192006-10-27 16:16:16 +0000138/// lookup the node in the FoldingSetImpl.
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000139unsigned FoldingSetNodeID::ComputeHash() const {
Dan Gohman365c53e2010-08-24 23:16:53 +0000140 return FoldingSetNodeIDRef(Bits.data(), Bits.size()).ComputeHash();
Jim Laskey0e5af192006-10-27 16:16:16 +0000141}
142
143/// operator== - Used to compare two nodes to each other.
144///
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000145bool FoldingSetNodeID::operator==(const FoldingSetNodeID &RHS)const{
Dan Gohman365c53e2010-08-24 23:16:53 +0000146 return *this == FoldingSetNodeIDRef(RHS.Bits.data(), RHS.Bits.size());
Dan Gohman30634102010-08-16 15:30:39 +0000147}
148
149/// operator== - Used to compare two nodes to each other.
150///
151bool FoldingSetNodeID::operator==(FoldingSetNodeIDRef RHS) const {
Dan Gohman365c53e2010-08-24 23:16:53 +0000152 return FoldingSetNodeIDRef(Bits.data(), Bits.size()) == RHS;
Jim Laskey0e5af192006-10-27 16:16:16 +0000153}
154
Dan Gohmanc93b4cf2010-03-18 16:16:38 +0000155/// Intern - Copy this node's data to a memory region allocated from the
156/// given allocator and return a FoldingSetNodeIDRef describing the
157/// interned data.
158FoldingSetNodeIDRef
159FoldingSetNodeID::Intern(BumpPtrAllocator &Allocator) const {
160 unsigned *New = Allocator.Allocate<unsigned>(Bits.size());
161 std::uninitialized_copy(Bits.begin(), Bits.end(), New);
162 return FoldingSetNodeIDRef(New, Bits.size());
163}
Jim Laskey0e5af192006-10-27 16:16:16 +0000164
165//===----------------------------------------------------------------------===//
Jim Laskey18529f32006-10-27 18:05:12 +0000166/// Helper functions for FoldingSetImpl.
167
168/// GetNextPtr - In order to save space, each bucket is a
169/// singly-linked-list. In order to make deletion more efficient, we make
170/// the list circular, so we can delete a node without computing its hash.
171/// The problem with this is that the start of the hash buckets are not
Chris Lattner3cab0712007-01-30 23:16:22 +0000172/// Nodes. If NextInBucketPtr is a bucket pointer, this method returns null:
173/// use GetBucketPtr when this happens.
Chris Lattner9a7288b2007-10-03 20:45:43 +0000174static FoldingSetImpl::Node *GetNextPtr(void *NextInBucketPtr) {
175 // The low bit is set if this is the pointer back to the bucket.
176 if (reinterpret_cast<intptr_t>(NextInBucketPtr) & 1)
Jim Laskey18529f32006-10-27 18:05:12 +0000177 return 0;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000178
Jim Laskey18529f32006-10-27 18:05:12 +0000179 return static_cast<FoldingSetImpl::Node*>(NextInBucketPtr);
180}
181
Ted Kremenek26e3c442008-02-04 21:11:17 +0000182
Jim Laskey18529f32006-10-27 18:05:12 +0000183/// testing.
184static void **GetBucketPtr(void *NextInBucketPtr) {
Chris Lattner9a7288b2007-10-03 20:45:43 +0000185 intptr_t Ptr = reinterpret_cast<intptr_t>(NextInBucketPtr);
Chris Lattner116c3212007-10-03 21:12:09 +0000186 assert((Ptr & 1) && "Not a bucket pointer");
Chris Lattner9a7288b2007-10-03 20:45:43 +0000187 return reinterpret_cast<void**>(Ptr & ~intptr_t(1));
Jim Laskey18529f32006-10-27 18:05:12 +0000188}
189
190/// GetBucketFor - Hash the specified node ID and return the hash bucket for
191/// the specified ID.
Dan Gohman30634102010-08-16 15:30:39 +0000192static void **GetBucketFor(unsigned Hash, void **Buckets, unsigned NumBuckets) {
Jim Laskey18529f32006-10-27 18:05:12 +0000193 // NumBuckets is always a power of 2.
Dan Gohman30634102010-08-16 15:30:39 +0000194 unsigned BucketNum = Hash & (NumBuckets-1);
Jim Laskey18529f32006-10-27 18:05:12 +0000195 return Buckets + BucketNum;
196}
197
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000198/// AllocateBuckets - Allocated initialized bucket memory.
199static void **AllocateBuckets(unsigned NumBuckets) {
200 void **Buckets = static_cast<void**>(calloc(NumBuckets+1, sizeof(void*)));
201 // Set the very last bucket to be a non-null "pointer".
202 Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
203 return Buckets;
204}
205
Jim Laskey18529f32006-10-27 18:05:12 +0000206//===----------------------------------------------------------------------===//
Jim Laskey0e5af192006-10-27 16:16:16 +0000207// FoldingSetImpl Implementation
208
Dan Gohman535de1a2008-08-23 00:42:16 +0000209FoldingSetImpl::FoldingSetImpl(unsigned Log2InitSize) {
Jim Laskey1f67a992006-11-02 14:21:26 +0000210 assert(5 < Log2InitSize && Log2InitSize < 32 &&
211 "Initial hash table size out of range");
212 NumBuckets = 1 << Log2InitSize;
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000213 Buckets = AllocateBuckets(NumBuckets);
214 NumNodes = 0;
Jim Laskey0e5af192006-10-27 16:16:16 +0000215}
216FoldingSetImpl::~FoldingSetImpl() {
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000217 free(Buckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000218}
Dan Gohman535de1a2008-08-23 00:42:16 +0000219void FoldingSetImpl::clear() {
220 // Set all but the last bucket to null pointers.
221 memset(Buckets, 0, NumBuckets*sizeof(void*));
222
223 // Set the very last bucket to be a non-null "pointer".
224 Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
225
226 // Reset the node count to zero.
227 NumNodes = 0;
228}
Jim Laskey0e5af192006-10-27 16:16:16 +0000229
Jim Laskey0e5af192006-10-27 16:16:16 +0000230/// GrowHashTable - Double the size of the hash table and rehash everything.
231///
232void FoldingSetImpl::GrowHashTable() {
233 void **OldBuckets = Buckets;
234 unsigned OldNumBuckets = NumBuckets;
235 NumBuckets <<= 1;
236
Jim Laskey0e5af192006-10-27 16:16:16 +0000237 // Clear out new buckets.
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000238 Buckets = AllocateBuckets(NumBuckets);
239 NumNodes = 0;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000240
Jim Laskey0e5af192006-10-27 16:16:16 +0000241 // Walk the old buckets, rehashing nodes into their new place.
Dan Gohman30634102010-08-16 15:30:39 +0000242 FoldingSetNodeID TempID;
Jim Laskey0e5af192006-10-27 16:16:16 +0000243 for (unsigned i = 0; i != OldNumBuckets; ++i) {
244 void *Probe = OldBuckets[i];
245 if (!Probe) continue;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000246 while (Node *NodeInBucket = GetNextPtr(Probe)) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000247 // Figure out the next link, remove NodeInBucket from the old link.
248 Probe = NodeInBucket->getNextInBucket();
249 NodeInBucket->SetNextInBucket(0);
250
251 // Insert the node into the new bucket, after recomputing the hash.
Dan Gohman30634102010-08-16 15:30:39 +0000252 InsertNode(NodeInBucket,
253 GetBucketFor(ComputeNodeHash(NodeInBucket, TempID),
254 Buckets, NumBuckets));
255 TempID.clear();
Jim Laskey0e5af192006-10-27 16:16:16 +0000256 }
257 }
258
Benjamin Kramer6118efa2010-06-19 17:00:31 +0000259 free(OldBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000260}
261
262/// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
263/// return it. If not, return the insertion token that will make insertion
264/// faster.
Ted Kremenek27a8e0d2008-02-04 17:14:20 +0000265FoldingSetImpl::Node
266*FoldingSetImpl::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
267 void *&InsertPos) {
268
Dan Gohman30634102010-08-16 15:30:39 +0000269 void **Bucket = GetBucketFor(ID.ComputeHash(), Buckets, NumBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000270 void *Probe = *Bucket;
271
272 InsertPos = 0;
273
Dan Gohman30634102010-08-16 15:30:39 +0000274 FoldingSetNodeID TempID;
Chris Lattner9a7288b2007-10-03 20:45:43 +0000275 while (Node *NodeInBucket = GetNextPtr(Probe)) {
Dan Gohman30634102010-08-16 15:30:39 +0000276 if (NodeEquals(NodeInBucket, ID, TempID))
Jim Laskey0e5af192006-10-27 16:16:16 +0000277 return NodeInBucket;
Dan Gohman30634102010-08-16 15:30:39 +0000278 TempID.clear();
Jim Laskey0e5af192006-10-27 16:16:16 +0000279
280 Probe = NodeInBucket->getNextInBucket();
281 }
282
283 // Didn't find the node, return null with the bucket as the InsertPos.
284 InsertPos = Bucket;
285 return 0;
286}
287
288/// InsertNode - Insert the specified node into the folding set, knowing that it
289/// is not already in the map. InsertPos must be obtained from
290/// FindNodeOrInsertPos.
291void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
Chris Lattner0de44392007-02-01 05:33:21 +0000292 assert(N->getNextInBucket() == 0);
Jim Laskey0e5af192006-10-27 16:16:16 +0000293 // Do we need to grow the hashtable?
Chris Lattnerb85210f2007-01-31 06:04:41 +0000294 if (NumNodes+1 > NumBuckets*2) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000295 GrowHashTable();
Dan Gohman30634102010-08-16 15:30:39 +0000296 FoldingSetNodeID TempID;
297 InsertPos = GetBucketFor(ComputeNodeHash(N, TempID), Buckets, NumBuckets);
Jim Laskey0e5af192006-10-27 16:16:16 +0000298 }
Chris Lattnerb85210f2007-01-31 06:04:41 +0000299
300 ++NumNodes;
Jim Laskey0e5af192006-10-27 16:16:16 +0000301
302 /// The insert position is actually a bucket pointer.
303 void **Bucket = static_cast<void**>(InsertPos);
304
305 void *Next = *Bucket;
306
307 // If this is the first insertion into this bucket, its next pointer will be
Chris Lattner9a7288b2007-10-03 20:45:43 +0000308 // null. Pretend as if it pointed to itself, setting the low bit to indicate
309 // that it is a pointer to the bucket.
Jim Laskey0e5af192006-10-27 16:16:16 +0000310 if (Next == 0)
Chris Lattner9a7288b2007-10-03 20:45:43 +0000311 Next = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(Bucket)|1);
Jim Laskey0e5af192006-10-27 16:16:16 +0000312
Chris Lattnerb85210f2007-01-31 06:04:41 +0000313 // Set the node's next pointer, and make the bucket point to the node.
Jim Laskey0e5af192006-10-27 16:16:16 +0000314 N->SetNextInBucket(Next);
315 *Bucket = N;
316}
317
318/// RemoveNode - Remove a node from the folding set, returning true if one was
319/// removed or false if the node was not in the folding set.
320bool FoldingSetImpl::RemoveNode(Node *N) {
321 // Because each bucket is a circular list, we don't need to compute N's hash
Chris Lattner0de44392007-02-01 05:33:21 +0000322 // to remove it.
Jim Laskey0e5af192006-10-27 16:16:16 +0000323 void *Ptr = N->getNextInBucket();
324 if (Ptr == 0) return false; // Not in folding set.
325
326 --NumNodes;
Jim Laskey0e5af192006-10-27 16:16:16 +0000327 N->SetNextInBucket(0);
Chris Lattner0de44392007-02-01 05:33:21 +0000328
329 // Remember what N originally pointed to, either a bucket or another node.
330 void *NodeNextPtr = Ptr;
331
332 // Chase around the list until we find the node (or bucket) which points to N.
Jim Laskey0e5af192006-10-27 16:16:16 +0000333 while (true) {
Chris Lattner9a7288b2007-10-03 20:45:43 +0000334 if (Node *NodeInBucket = GetNextPtr(Ptr)) {
Jim Laskey0e5af192006-10-27 16:16:16 +0000335 // Advance pointer.
336 Ptr = NodeInBucket->getNextInBucket();
337
338 // We found a node that points to N, change it to point to N's next node,
339 // removing N from the list.
340 if (Ptr == N) {
341 NodeInBucket->SetNextInBucket(NodeNextPtr);
342 return true;
343 }
344 } else {
345 void **Bucket = GetBucketPtr(Ptr);
346 Ptr = *Bucket;
347
348 // If we found that the bucket points to N, update the bucket to point to
349 // whatever is next.
350 if (Ptr == N) {
351 *Bucket = NodeNextPtr;
352 return true;
353 }
354 }
355 }
356}
357
358/// GetOrInsertNode - If there is an existing simple Node exactly
359/// equal to the specified node, return it. Otherwise, insert 'N' and it
360/// instead.
361FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) {
Ted Kremenek0a3feca2008-01-19 04:22:50 +0000362 FoldingSetNodeID ID;
Dan Gohman6616f7e2010-08-16 14:53:42 +0000363 GetNodeProfile(N, ID);
Jim Laskey0e5af192006-10-27 16:16:16 +0000364 void *IP;
365 if (Node *E = FindNodeOrInsertPos(ID, IP))
366 return E;
367 InsertNode(N, IP);
368 return N;
369}
Chris Lattner116c3212007-10-03 21:12:09 +0000370
371//===----------------------------------------------------------------------===//
372// FoldingSetIteratorImpl Implementation
373
374FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) {
375 // Skip to the first non-null non-self-cycle bucket.
Ted Kremeneke3e09572008-02-15 21:12:46 +0000376 while (*Bucket != reinterpret_cast<void*>(-1) &&
377 (*Bucket == 0 || GetNextPtr(*Bucket) == 0))
Chris Lattner116c3212007-10-03 21:12:09 +0000378 ++Bucket;
379
380 NodePtr = static_cast<FoldingSetNode*>(*Bucket);
381}
382
383void FoldingSetIteratorImpl::advance() {
384 // If there is another link within this bucket, go to it.
385 void *Probe = NodePtr->getNextInBucket();
386
387 if (FoldingSetNode *NextNodeInBucket = GetNextPtr(Probe))
388 NodePtr = NextNodeInBucket;
389 else {
390 // Otherwise, this is the last link in this bucket.
391 void **Bucket = GetBucketPtr(Probe);
392
393 // Skip to the next non-null non-self-cycle bucket.
394 do {
395 ++Bucket;
Ted Kremeneke3e09572008-02-15 21:12:46 +0000396 } while (*Bucket != reinterpret_cast<void*>(-1) &&
397 (*Bucket == 0 || GetNextPtr(*Bucket) == 0));
Chris Lattner116c3212007-10-03 21:12:09 +0000398
399 NodePtr = static_cast<FoldingSetNode*>(*Bucket);
400 }
401}
402
Ted Kremenek26e3c442008-02-04 21:11:17 +0000403//===----------------------------------------------------------------------===//
404// FoldingSetBucketIteratorImpl Implementation
405
406FoldingSetBucketIteratorImpl::FoldingSetBucketIteratorImpl(void **Bucket) {
407 Ptr = (*Bucket == 0 || GetNextPtr(*Bucket) == 0) ? (void*) Bucket : *Bucket;
408}