summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2003-07-29 20:01:01 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2003-07-29 20:01:01 +0000
commitb3b0414c8788a82a6dbbbe0d9b71cb1a356dca1b (patch)
tree05007ed30b60b0174d973dba603886b6c2a7097d /runtime
parente6124d3b7c44e9ce0fb2e5656cef3c0b0d376ee3 (diff)
downloadllvm-b3b0414c8788a82a6dbbbe0d9b71cb1a356dca1b.tar.gz
llvm-b3b0414c8788a82a6dbbbe0d9b71cb1a356dca1b.tar.bz2
llvm-b3b0414c8788a82a6dbbbe0d9b71cb1a356dca1b.tar.xz
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
Diffstat (limited to 'runtime')
-rw-r--r--runtime/libtrace/tracelib.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/runtime/libtrace/tracelib.c b/runtime/libtrace/tracelib.c
index 73190244bf..ba20ff3ce3 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 <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#ifndef sun
-#include <stdint.h>
-#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)
{