From b3b0414c8788a82a6dbbbe0d9b71cb1a356dca1b Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Tue, 29 Jul 2003 20:01:01 +0000 Subject: [PATCH] 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 --- runtime/libtrace/tracelib.c | 58 ++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/runtime/libtrace/tracelib.c b/runtime/libtrace/tracelib.c index 73190244bfd..ba20ff3ce3e 100644 --- a/runtime/libtrace/tracelib.c +++ b/runtime/libtrace/tracelib.c @@ -1,26 +1,24 @@ -/*===-- tracelib.c - Runtime routines for tracing ---------------*- C++ -*-===*\ -// -// Runtime routines for supporting tracing of execution for code generated by -// LLVM. -// -//===----------------------------------------------------------------------===*/ +/*===-- tracelib.c - Runtime routines for tracing ---------------*- C++ -*-===* + * + * Runtime routines for supporting tracing of execution for code generated by + * LLVM. + * + *===----------------------------------------------------------------------===*/ #include "tracelib.h" #include #include #include #include -#ifndef sun -#include -#endif +#include "Support/DataTypes.h" /*===---------------------------------------------------------------------===== * HASH FUNCTIONS *===---------------------------------------------------------------------===*/ /* use #defines until we have inlining */ -typedef uint32_t Index; /* type of index/size for hash table */ -typedef uint32_t Generic; /* type of values stored in table */ +typedef uintptr_t Index; /* type of keys, size for hash table */ +typedef uint32_t Generic; /* type of values stored in table */ /* Index IntegerHashFunc(const Generic value, const Index size) */ #define IntegerHashFunc(value, size) \ @@ -38,7 +36,6 @@ typedef uint32_t Generic; /* type of values stored in table */ #define PointerRehashFunc(value, size) \ IntegerRehashFunc((Index) value, size) - /*===---------------------------------------------------------------------===== * POINTER-TO-GENERIC HASH TABLE. * These should be moved to a separate location: HashTable.[ch] @@ -71,6 +68,10 @@ extern void Insert(PtrValueHashTable* ptrTable, void* ptr, Generic value); extern void Delete(PtrValueHashTable* ptrTable, void* ptr); +/* Returns NULL if the item is not found. */ +/* void* LookupPtr(PtrValueHashTable* ptrTable, void* ptr) */ +#define LookupPtr(ptrTable, ptr) \ + LookupOrInsertPtr(ptrTable, ptr, FIND) void InitializeTable(PtrValueHashTable* ptrTable, Index newSize) @@ -98,11 +99,9 @@ ReallocTable(PtrValueHashTable* ptrTable, Index newSize) return; #ifndef NDEBUG - printf("\n***\n*** WARNING: REALLOCATING SPACE FOR POINTER HASH TABLE.\n"); - printf("*** oldSize = %d, oldCapacity = %d\n***\n\n", - ptrTable->size, ptrTable->capacity); - printf("*** NEW SEQUENCE NUMBER FOR A POINTER WILL PROBABLY NOT MATCH "); - printf(" THE OLD ONE!\n***\n\n"); + printf("\n***\n*** REALLOCATING SPACE FOR POINTER HASH TABLE.\n"); + printf("*** oldSize = %ld, oldCapacity = %ld\n***\n\n", + (long) ptrTable->size, (long) ptrTable->capacity); #endif unsigned int i; @@ -113,20 +112,18 @@ ReallocTable(PtrValueHashTable* ptrTable, Index newSize) /* allocate the new storage and flags and re-insert the old entries */ InitializeTable(ptrTable, newSize); - memcpy(ptrTable->table, oldTable, - oldCapacity * sizeof(PtrValueHashEntry)); - memcpy(ptrTable->fullEmptyFlags, oldFlags, - oldCapacity * sizeof(FULLEMPTY)); - ptrTable->size = oldSize; + for (i=0; i < oldCapacity; ++i) + if (oldFlags[i] == FULL) + Insert(ptrTable, oldTable[i].key, oldTable[i].value); + + assert(ptrTable->size == oldSize && "Incorrect number of entries copied?"); #ifndef NDEBUG - for (i=0; i < oldCapacity; ++i) { - assert(ptrTable->fullEmptyFlags[i] == oldFlags[i]); - assert(ptrTable->table[i].key == oldTable[i].key); - assert(ptrTable->table[i].value == oldTable[i].value); - } + for (i=0; i < oldCapacity; ++i) + if (! oldFlags[i]) + assert(LookupPtr(ptrTable, oldTable[i].key) == oldTable[i].value); #endif - + free(oldTable); free(oldFlags); } @@ -216,11 +213,6 @@ LookupOrInsertPtr(PtrValueHashTable* ptrTable, void* ptr, ACTION action) return (Generic) NULL; } -/* Returns NULL if the item is not found. */ -/* void* LookupPtr(PtrValueHashTable* ptrTable, void* ptr) */ -#define LookupPtr(ptrTable, ptr) \ - LookupOrInsertPtr(ptrTable, ptr, FIND) - void Insert(PtrValueHashTable* ptrTable, void* ptr, Generic value) {