llvm.org GIT mirror llvm / b3b0414
Bug fix: after reallocating the hash table, we have to re-insert each value instead of copying table entries! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7396 91177308-0d34-0410-b5e6-96231b3b80d8 Vikram S. Adve 17 years ago
1 changed file(s) with 25 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
None /*===-- tracelib.c - Runtime routines for tracing ---------------*- C++ -*-===*\
1 //
2 // Runtime routines for supporting tracing of execution for code generated by
3 // LLVM.
4 //
5 //===----------------------------------------------------------------------===*/
0 /*===-- tracelib.c - Runtime routines for tracing ---------------*- C++ -*-===*
1 *
2 * Runtime routines for supporting tracing of execution for code generated by
3 * LLVM.
4 *
5 *===----------------------------------------------------------------------===*/
66
77 #include "tracelib.h"
88 #include
99 #include
1010 #include
1111 #include
12 #ifndef sun
13 #include
14 #endif
12 #include "Support/DataTypes.h"
1513
1614 /*===---------------------------------------------------------------------=====
1715 * HASH FUNCTIONS
1816 *===---------------------------------------------------------------------===*/
1917
2018 /* use #defines until we have inlining */
21 typedef uint32_t Index; /* type of index/size for hash table */
22 typedef uint32_t Generic; /* type of values stored in table */
19 typedef uintptr_t Index; /* type of keys, size for hash table */
20 typedef uint32_t Generic; /* type of values stored in table */
2321
2422 /* Index IntegerHashFunc(const Generic value, const Index size) */
2523 #define IntegerHashFunc(value, size) \
3634 /* Index PointerRehashFunc(const void* value, const Index size) */
3735 #define PointerRehashFunc(value, size) \
3836 IntegerRehashFunc((Index) value, size)
39
4037
4138 /*===---------------------------------------------------------------------=====
4239 * POINTER-TO-GENERIC HASH TABLE.
7067
7168 extern void Delete(PtrValueHashTable* ptrTable, void* ptr);
7269
70 /* Returns NULL if the item is not found. */
71 /* void* LookupPtr(PtrValueHashTable* ptrTable, void* ptr) */
72 #define LookupPtr(ptrTable, ptr) \
73 LookupOrInsertPtr(ptrTable, ptr, FIND)
7374
7475 void
7576 InitializeTable(PtrValueHashTable* ptrTable, Index newSize)
9798 return;
9899
99100 #ifndef NDEBUG
100 printf("\n***\n*** WARNING: REALLOCATING SPACE FOR POINTER HASH TABLE.\n");
101 printf("*** oldSize = %d, oldCapacity = %d\n***\n\n",
102 ptrTable->size, ptrTable->capacity);
103 printf("*** NEW SEQUENCE NUMBER FOR A POINTER WILL PROBABLY NOT MATCH ");
104 printf(" THE OLD ONE!\n***\n\n");
101 printf("\n***\n*** REALLOCATING SPACE FOR POINTER HASH TABLE.\n");
102 printf("*** oldSize = %ld, oldCapacity = %ld\n***\n\n",
103 (long) ptrTable->size, (long) ptrTable->capacity);
105104 #endif
106105
107106 unsigned int i;
112111
113112 /* allocate the new storage and flags and re-insert the old entries */
114113 InitializeTable(ptrTable, newSize);
115 memcpy(ptrTable->table, oldTable,
116 oldCapacity * sizeof(PtrValueHashEntry));
117 memcpy(ptrTable->fullEmptyFlags, oldFlags,
118 oldCapacity * sizeof(FULLEMPTY));
119 ptrTable->size = oldSize;
114 for (i=0; i < oldCapacity; ++i)
115 if (oldFlags[i] == FULL)
116 Insert(ptrTable, oldTable[i].key, oldTable[i].value);
117
118 assert(ptrTable->size == oldSize && "Incorrect number of entries copied?");
120119
121120 #ifndef NDEBUG
122 for (i=0; i < oldCapacity; ++i) {
123 assert(ptrTable->fullEmptyFlags[i] == oldFlags[i]);
124 assert(ptrTable->table[i].key == oldTable[i].key);
125 assert(ptrTable->table[i].value == oldTable[i].value);
126 }
121 for (i=0; i < oldCapacity; ++i)
122 if (! oldFlags[i])
123 assert(LookupPtr(ptrTable, oldTable[i].key) == oldTable[i].value);
127124 #endif
128
125
129126 free(oldTable);
130127 free(oldFlags);
131128 }
215212 return (Generic) NULL;
216213 }
217214
218 /* Returns NULL if the item is not found. */
219 /* void* LookupPtr(PtrValueHashTable* ptrTable, void* ptr) */
220 #define LookupPtr(ptrTable, ptr) \
221 LookupOrInsertPtr(ptrTable, ptr, FIND)
222
223215 void
224216 Insert(PtrValueHashTable* ptrTable, void* ptr, Generic value)
225217 {