add a new code
[oota-llvm.git] / lib / Support / FoldingSet.cpp
index 1d04abf4e46f9bb528d5f776c36d2987e9165ef8..6f7f5ea4cbf3cc09d910579ba03b1191f8d2e445 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG_TYPE "foldingset"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Debug.h"
 #include <cassert>
 using namespace llvm;
 
@@ -44,7 +42,10 @@ void FoldingSetImpl::NodeID::AddInteger(unsigned I) {
 }
 void FoldingSetImpl::NodeID::AddInteger(uint64_t I) {
   Bits.push_back(unsigned(I));
-  Bits.push_back(unsigned(I >> 32));
+  
+  // If the integer is small, encode it just as 32-bits.
+  if ((uint64_t)(int)I != I)
+    Bits.push_back(unsigned(I >> 32));
 }
 void FoldingSetImpl::NodeID::AddFloat(float F) {
   Bits.push_back(FloatToBits(F));
@@ -226,8 +227,8 @@ FoldingSetImpl::Node *FoldingSetImpl::FindNodeOrInsertPos(const NodeID &ID,
 /// is not already in the map.  InsertPos must be obtained from 
 /// FindNodeOrInsertPos.
 void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
+  assert(N->getNextInBucket() == 0);
   // Do we need to grow the hashtable?
-  DEBUG(DOUT << "INSERT: " << N << '\n');
   if (NumNodes+1 > NumBuckets*2) {
     GrowHashTable();
     NodeID ID;
@@ -256,16 +257,17 @@ void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
 /// removed or false if the node was not in the folding set.
 bool FoldingSetImpl::RemoveNode(Node *N) {
   // Because each bucket is a circular list, we don't need to compute N's hash
-  // to remove it.  Chase around the list until we find the node (or bucket)
-  // which points to N.
-  DEBUG(DOUT << "REMOVE: " << N << '\n');
+  // to remove it.
   void *Ptr = N->getNextInBucket();
   if (Ptr == 0) return false;  // Not in folding set.
 
   --NumNodes;
+  N->SetNextInBucket(0);
 
+  // Remember what N originally pointed to, either a bucket or another node.
   void *NodeNextPtr = Ptr;
-  N->SetNextInBucket(0);
+  
+  // Chase around the list until we find the node (or bucket) which points to N.
   while (true) {
     if (Node *NodeInBucket = GetNextPtr(Ptr, Buckets, NumBuckets)) {
       // Advance pointer.