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

John Criswell criswell at cs.uiuc.edu
Fri Nov 14 11:39:01 PST 2003


Changes in directory poolalloc/runtime/FreeListAllocator:

PoolAllocator.cpp updated: 1.22 -> 1.23

---
Log message:

Added code to allocate multiple small arrays within a single slab (assuming
the slab is a single page).  This slightly improves half of the Olden
programs from their previous settings.



---
Diffs of the changes:  (+44 -5)

Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.22 poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.23
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.22	Fri Nov 14 10:48:05 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp	Fri Nov 14 11:38:01 2003
@@ -324,6 +324,30 @@
   struct SlabHeader * Slabp = Pool->ArraySlabs;
   struct SlabHeader * Prevp = NULL;
 
+  //
+  // Check to see if we have an array slab that has extra space that we
+  // can use.
+  //
+  if ((Slabp != NULL) &&
+      ((Pool->MaxNodesPerPage - Slabp->NextFreeData) >= ArraySize))
+  {
+    //
+    // Increase the reference count for this slab.
+    //
+    Slabp->LiveNodes++;
+
+    //
+    // Return the data to the caller.
+    //
+    void * Data = (Slabp->Data + (Pool->NodeSize * Slabp->NextFreeData));
+    (Slabp->NextFreeData)++;
+    return (Data);
+  }
+
+  //
+  // Scan through all the free array slabs to see if they are large
+  // enough.
+  //
   for (; Slabp != NULL; Prevp = Slabp, Slabp=Slabp->Next)
   {
     //
@@ -345,6 +369,7 @@
         //
         Prevp->Next = Slabp->Next;
       }
+      ++(Slabp->LiveNodes);
       return (Slabp->Data);
     }
   }
@@ -352,13 +377,24 @@
   //
   // Create a new slab and mark it as an array.
   //
-  struct SlabHeader * NewSlab = createSlab (Pool, ArraySize);
-  NewSlab->IsArray = 1;
+  Slabp = createSlab (Pool, ArraySize);
+  Slabp->IsArray = 1;
+  Slabp->LiveNodes = 1;
+  Slabp->NextFreeData = ArraySize;
+
+  //
+  // If the array has some space, link it into the array "free" list.
+  //
+  if ((Slabp->IsManaged == 0) && (Slabp->NextFreeData != Pool->MaxNodesPerPage))
+  {
+    Slabp->Next = Pool->ArraySlabs;
+    Pool->ArraySlabs = Slabp;
+  }
 
   //
   // Return the list of blocks to the caller.
   //
-  return (NewSlab->Data);
+  return (Slabp->Data);
 }
 
 void
@@ -377,8 +413,11 @@
   //
   if (slabp->IsArray)
   {
-    slabp->Next = Pool->ArraySlabs;
-    Pool->ArraySlabs = slabp;
+    if ((--slabp->LiveNodes) == 0)
+    {
+      slabp->Next = Pool->ArraySlabs;
+      Pool->ArraySlabs = slabp;
+    }
     return;
   }
 





More information about the llvm-commits mailing list