[llvm-commits] CVS: poolalloc/runtime/PoolAllocator/PoolAllocator.h PoolAllocatorChained.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun Oct 26 17:28:00 PST 2003


Changes in directory poolalloc/runtime/PoolAllocator:

PoolAllocator.h updated: 1.3 -> 1.4
PoolAllocatorChained.cpp updated: 1.15 -> 1.16

---
Log message:

Rename "slabs" to Ptr1, since it is supposed to be generic.
Add new Ptr2 field


---
Diffs of the changes:  (+15 -14)

Index: poolalloc/runtime/PoolAllocator/PoolAllocator.h
diff -u poolalloc/runtime/PoolAllocator/PoolAllocator.h:1.3 poolalloc/runtime/PoolAllocator/PoolAllocator.h:1.4
--- poolalloc/runtime/PoolAllocator/PoolAllocator.h:1.3	Sun Oct 26 17:09:40 2003
+++ poolalloc/runtime/PoolAllocator/PoolAllocator.h	Sun Oct 26 17:27:31 2003
@@ -16,8 +16,8 @@
 #define POOLALLOCATOR_RUNTIME_H
 
 typedef struct PoolTy {
-  // Slabs - An implementation specified data pointer.
-  void *Slabs;
+  // Ptr1, Ptr2 - Implementation specified data pointers.
+  void *Ptr1, *Ptr2;
 
   // NodeSize - Keep track of the object size tracked by this pool
   unsigned NodeSize;


Index: poolalloc/runtime/PoolAllocator/PoolAllocatorChained.cpp
diff -u poolalloc/runtime/PoolAllocator/PoolAllocatorChained.cpp:1.15 poolalloc/runtime/PoolAllocator/PoolAllocatorChained.cpp:1.16
--- poolalloc/runtime/PoolAllocator/PoolAllocatorChained.cpp:1.15	Sun Oct 26 17:09:40 2003
+++ poolalloc/runtime/PoolAllocator/PoolAllocatorChained.cpp	Sun Oct 26 17:27:31 2003
@@ -131,22 +131,23 @@
   PS->UsedEnd     = 0;    // Nothing allocated.
 
   // Add the slab to the list...
-  PS->Next = (PoolSlab*)Pool->Slabs;
-  Pool->Slabs = PS;
+  PS->Next = (PoolSlab*)Pool->Ptr1;
+  Pool->Ptr1 = PS;
   return PS;
 }
 
 void *PoolSlab::createSingleArray(PoolTy *Pool, unsigned NumNodes) {
   PoolSlab *PS = (PoolSlab*)malloc(sizeof(PoolSlab) +
                                    Pool->NodeSize*NumNodes-1);
+  assert(NumNodes > NodesPerSlab && "No need to create a single array!");
   assert(PS && "poolalloc: Could not allocate memory!");
 
   PS->isSingleArray = 1;  // Not a single array!
   PS->markNodeAllocated(0);
 
   // Add the slab to the list...
-  PS->Next = (PoolSlab*)Pool->Slabs;
-  Pool->Slabs = PS;
+  PS->Next = (PoolSlab*)Pool->Ptr1;
+  Pool->Ptr1 = PS;
   return &PS->Data[0];
 }
 
@@ -342,7 +343,7 @@
 
   // We must alway return unique pointers, even if they asked for 0 bytes
   Pool->NodeSize = NodeSize ? NodeSize : 1;
-  Pool->Slabs = 0;
+  Pool->Ptr1 = 0;
   Pool->FreeablePool = 1;
 }
 
@@ -356,7 +357,7 @@
 void pooldestroy(PoolTy *Pool) {
   assert(Pool && "Null pool pointer passed in to pooldestroy!\n");
 
-  PoolSlab *PS = (PoolSlab*)Pool->Slabs;
+  PoolSlab *PS = (PoolSlab*)Pool->Ptr1;
   while (PS) {
     PoolSlab *Next = PS->Next;
     PS->destroy();
@@ -368,7 +369,7 @@
   assert(Pool && "Null pool pointer passed in to poolalloc!\n");
 
   unsigned NodeSize = Pool->NodeSize;
-  PoolSlab *PS = (PoolSlab*)Pool->Slabs;
+  PoolSlab *PS = (PoolSlab*)Pool->Ptr1;
 
   // Fastpath for allocation in the common case.
   if (PS) {
@@ -396,8 +397,8 @@
   assert(Pool && "Null pool pointer passed in to poolfree!\n");
   unsigned NodeSize = Pool->NodeSize;
 
-  PoolSlab *PS = (PoolSlab*)Pool->Slabs;
-  PoolSlab **PPS = (PoolSlab**)&Pool->Slabs;
+  PoolSlab *PS = (PoolSlab*)Pool->Ptr1;
+  PoolSlab **PPS = (PoolSlab**)&Pool->Ptr1;
 
   // Search for the slab that contains this node...
   int Idx = PS->containsElement(Node, NodeSize);
@@ -431,7 +432,7 @@
     assert(!PS->isSingleArray);
 
     *PPS = PS->Next;   // Unlink from the list of slabs...
-    PoolSlab *FirstSlab = (PoolSlab*)Pool->Slabs;
+    PoolSlab *FirstSlab = (PoolSlab*)Pool->Ptr1;
     
     // If we can free this pool, check to see if there are any empty slabs at
     // the start of this list.  If so, delete the FirstSlab!
@@ -447,7 +448,7 @@
     // Link our slab onto the head of the list so that allocations will find it
     // efficiently.    
     PS->Next = FirstSlab;
-    Pool->Slabs = PS;
+    Pool->Ptr1 = PS;
   }
 }
 
@@ -458,7 +459,7 @@
     return PoolSlab::createSingleArray(Pool, Size);    
 
   // Loop through all of the slabs looking for one with an opening
-  PoolSlab *PS = (PoolSlab*)Pool->Slabs;
+  PoolSlab *PS = (PoolSlab*)Pool->Ptr1;
   for (; PS; PS = PS->Next) {
     int Element = PS->allocateMultiple(Size);
     if (Element != -1)





More information about the llvm-commits mailing list