llvm.org GIT mirror llvm / f7c3e5f
FoldingSet: Push the hash through FoldingSetTraits::Equals, so clients can use it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154496 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
3 changed file(s) with 19 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
192192 virtual void GetNodeProfile(Node *N, FoldingSetNodeID &ID) const = 0;
193193 /// NodeEquals - Instantiations of the FoldingSet template implement
194194 /// this function to compare the given node with the given ID.
195 virtual bool NodeEquals(Node *N, const FoldingSetNodeID &ID,
195 virtual bool NodeEquals(Node *N, const FoldingSetNodeID &ID, unsigned IDHash,
196196 FoldingSetNodeID &TempID) const=0;
197 /// NodeEquals - Instantiations of the FoldingSet template implement
197 /// ComputeNodeHash - Instantiations of the FoldingSet template implement
198198 /// this function to compute a hash value for the given node.
199 virtual unsigned ComputeNodeHash(Node *N,
200 FoldingSetNodeID &TempID) const = 0;
199 virtual unsigned ComputeNodeHash(Node *N, FoldingSetNodeID &TempID) const = 0;
201200 };
202201
203202 //===----------------------------------------------------------------------===//
219218 // to compute a temporary ID if necessary. The default implementation
220219 // just calls Profile and does a regular comparison. Implementations
221220 // can override this to provide more efficient implementations.
222 static inline bool Equals(T &X, const FoldingSetNodeID &ID,
221 static inline bool Equals(T &X, const FoldingSetNodeID &ID, unsigned IDHash,
223222 FoldingSetNodeID &TempID);
224223
225224 // ComputeHash - Compute a hash value for X, using TempID to
248247 static void Profile(T &X, FoldingSetNodeID &ID, Ctx Context) {
249248 X.Profile(ID, Context);
250249 }
251 static inline bool Equals(T &X, const FoldingSetNodeID &ID,
250 static inline bool Equals(T &X, const FoldingSetNodeID &ID, unsigned IDHash,
252251 FoldingSetNodeID &TempID, Ctx Context);
253252 static inline unsigned ComputeHash(T &X, FoldingSetNodeID &TempID,
254253 Ctx Context);
343342 template
344343 inline bool
345344 DefaultFoldingSetTrait::Equals(T &X, const FoldingSetNodeID &ID,
346 FoldingSetNodeID &TempID) {
345 unsigned IDHash, FoldingSetNodeID &TempID) {
347346 FoldingSetTrait::Profile(X, TempID);
348347 return TempID == ID;
349348 }
357356 inline bool
358357 DefaultContextualFoldingSetTrait::Equals(T &X,
359358 const FoldingSetNodeID &ID,
359 unsigned IDHash,
360360 FoldingSetNodeID &TempID,
361361 Ctx Context) {
362362 ContextualFoldingSetTrait::Profile(X, TempID, Context);
386386 }
387387 /// NodeEquals - Instantiations may optionally provide a way to compare a
388388 /// node with a specified ID.
389 virtual bool NodeEquals(Node *N, const FoldingSetNodeID &ID,
389 virtual bool NodeEquals(Node *N, const FoldingSetNodeID &ID, unsigned IDHash,
390390 FoldingSetNodeID &TempID) const {
391391 T *TN = static_cast(N);
392 return FoldingSetTrait::Equals(*TN, ID, TempID);
393 }
394 /// NodeEquals - Instantiations may optionally provide a way to compute a
392 return FoldingSetTrait::Equals(*TN, ID, IDHash, TempID);
393 }
394 /// ComputeNodeHash - Instantiations may optionally provide a way to compute a
395395 /// hash value directly from a node.
396 virtual unsigned ComputeNodeHash(Node *N,
397 FoldingSetNodeID &TempID) const {
396 virtual unsigned ComputeNodeHash(Node *N, FoldingSetNodeID &TempID) const {
398397 T *TN = static_cast(N);
399398 return FoldingSetTrait::ComputeHash(*TN, TempID);
400399 }
464463 ContextualFoldingSetTrait::Profile(*TN, ID, Context);
465464 }
466465 virtual bool NodeEquals(FoldingSetImpl::Node *N,
467 const FoldingSetNodeID &ID,
466 const FoldingSetNodeID &ID, unsigned IDHash,
468467 FoldingSetNodeID &TempID) const {
469468 T *TN = static_cast(N);
470 return ContextualFoldingSetTrait::Equals(*TN, ID, TempID, Context);
469 return ContextualFoldingSetTrait::Equals(*TN, ID, IDHash, TempID,
470 Context);
471471 }
472472 virtual unsigned ComputeNodeHash(FoldingSetImpl::Node *N,
473473 FoldingSetNodeID &TempID) const {
139139 ID = X.FastID;
140140 }
141141 static bool Equals(const SCEV &X, const FoldingSetNodeID &ID,
142 FoldingSetNodeID &TempID) {
142 unsigned IDHash, FoldingSetNodeID &TempID) {
143143 return ID == X.FastID;
144144 }
145145 static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID) {
264264 FoldingSetImpl::Node
265265 *FoldingSetImpl::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
266266 void *&InsertPos) {
267
268 void **Bucket = GetBucketFor(ID.ComputeHash(), Buckets, NumBuckets);
267 unsigned IDHash = ID.ComputeHash();
268 void **Bucket = GetBucketFor(IDHash, Buckets, NumBuckets);
269269 void *Probe = *Bucket;
270270
271271 InsertPos = 0;
272272
273273 FoldingSetNodeID TempID;
274274 while (Node *NodeInBucket = GetNextPtr(Probe)) {
275 if (NodeEquals(NodeInBucket, ID, TempID))
275 if (NodeEquals(NodeInBucket, ID, IDHash, TempID))
276276 return NodeInBucket;
277277 TempID.clear();
278278