[llvm-commits] CVS: poolalloc/runtime/PoolAllocator/PoolAllocator.h PoolAllocatorBitMask.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Nov 8 16:46:01 PST 2003
Changes in directory poolalloc/runtime/PoolAllocator:
PoolAllocator.h updated: 1.4 -> 1.5
PoolAllocatorBitMask.cpp updated: 1.27 -> 1.28
---
Log message:
Change interface to the pool allocator to take the number of bytes allocated,
not the number of nodes. Also eliminate poolallocarray from the public
pool allocator itf
---
Diffs of the changes: (+45 -38)
Index: poolalloc/runtime/PoolAllocator/PoolAllocator.h
diff -u poolalloc/runtime/PoolAllocator/PoolAllocator.h:1.4 poolalloc/runtime/PoolAllocator/PoolAllocator.h:1.5
--- poolalloc/runtime/PoolAllocator/PoolAllocator.h:1.4 Sun Oct 26 17:27:31 2003
+++ poolalloc/runtime/PoolAllocator/PoolAllocator.h Sat Nov 8 16:44:59 2003
@@ -32,9 +32,8 @@
void poolinit(PoolTy *Pool, unsigned NodeSize);
void poolmakeunfreeable(PoolTy *Pool);
void pooldestroy(PoolTy *Pool);
- void *poolalloc(PoolTy *Pool);
+ void *poolalloc(PoolTy *Pool, unsigned NumBytes);
void poolfree(PoolTy *Pool, void *Node);
- void* poolallocarray(PoolTy* Pool, unsigned Size);
}
#endif
Index: poolalloc/runtime/PoolAllocator/PoolAllocatorBitMask.cpp
diff -u poolalloc/runtime/PoolAllocator/PoolAllocatorBitMask.cpp:1.27 poolalloc/runtime/PoolAllocator/PoolAllocatorBitMask.cpp:1.28
--- poolalloc/runtime/PoolAllocator/PoolAllocatorBitMask.cpp:1.27 Sat Nov 8 01:22:19 2003
+++ poolalloc/runtime/PoolAllocator/PoolAllocatorBitMask.cpp Sat Nov 8 16:44:59 2003
@@ -161,7 +161,7 @@
int containsElement(void *Ptr, unsigned ElementSize) const;
// freeElement - Free the single node, small array, or entire array indicated.
- void freeElement(unsigned ElementIdx);
+ void freeElement(unsigned short ElementIdx);
// lastNodeAllocated - Return one past the last node in the pool which is
// before ScanIdx, that is allocated. If there are no allocated nodes in this
@@ -345,7 +345,7 @@
// freeElement - Free the single node, small array, or entire array indicated.
-void PoolSlab::freeElement(unsigned ElementIdx) {
+void PoolSlab::freeElement(unsigned short ElementIdx) {
assert(isNodeAllocated(ElementIdx) &&
"poolfree: Attempt to free node that is already freed\n");
@@ -369,10 +369,10 @@
markNodeFree(ElementIdx);
// Free all nodes if this was a small array allocation.
- unsigned ElementEndIdx = ElementIdx + 1;
+ unsigned short ElementEndIdx = ElementIdx + 1;
// FIXME: This should use manual strength reduction to produce decent code.
- unsigned UE = UsedEnd;
+ unsigned short UE = UsedEnd;
while (ElementEndIdx != UE &&
!isStartOfAllocation(ElementEndIdx) &&
isNodeAllocated(ElementEndIdx)) {
@@ -514,9 +514,46 @@
}
}
-void *poolalloc(PoolTy *Pool) {
+
+// poolallocarray - a helper function used to implement poolalloc, when the
+// number of nodes to allocate is not 1.
+static void *poolallocarray(PoolTy* Pool, unsigned Size) {
+ assert(Pool && "Null pool pointer passed into poolallocarray!\n");
+ if (Size > PoolSlab::getSlabSize(Pool))
+ return PoolSlab::createSingleArray(Pool, Size);
+
+ PoolSlab *PS = (PoolSlab*)Pool->Ptr1;
+
+ // Loop through all of the slabs looking for one with an opening
+ for (; PS; PS = PS->Next) {
+ int Element = PS->allocateMultiple(Size);
+ if (Element != -1) {
+ // We allocated an element. Check to see if this slab has been completely
+ // filled up. If so, move it to the Ptr2 list.
+ if (PS->isFull()) {
+ PS->unlinkFromList();
+ PS->addToList((PoolSlab**)&Pool->Ptr2);
+ }
+ return PS->getElementAddress(Element, Pool->NodeSize);
+ }
+ }
+
+ PoolSlab *New = PoolSlab::create(Pool);
+ int Idx = New->allocateMultiple(Size);
+ assert(Idx == 0 && "New allocation didn't return zero'th node?");
+ return New->getElementAddress(0, 0);
+}
+
+void *poolalloc(PoolTy *Pool, unsigned NumBytes) {
assert(Pool && "Null pool pointer passed in to poolalloc!\n");
+ unsigned NodeSize = Pool->NodeSize;
+ unsigned NodesToAllocate = (NumBytes+NodeSize-1)/NodeSize;
+ if (NodesToAllocate > 1)
+ return poolallocarray(Pool, NodesToAllocate);
+
+ // Special case the most common situation, where a single node is being
+ // allocated.
PoolSlab *PS = (PoolSlab*)Pool->Ptr1;
if (__builtin_expect(PS != 0, 1)) {
@@ -529,7 +566,7 @@
PS->addToList((PoolSlab**)&Pool->Ptr2);
}
- return PS->getElementAddress(Element, Pool->NodeSize);
+ return PS->getElementAddress(Element, NodeSize);
}
// Loop through all of the slabs looking for one with an opening
@@ -543,7 +580,7 @@
PS->addToList((PoolSlab**)&Pool->Ptr2);
}
- return PS->getElementAddress(Element, Pool->NodeSize);
+ return PS->getElementAddress(Element, NodeSize);
}
}
}
@@ -555,36 +592,7 @@
return New->getElementAddress(0, 0);
}
-void *poolallocarray(PoolTy* Pool, unsigned Size) {
- assert(Pool && "Null pool pointer passed into poolallocarray!\n");
-
- // Special case size=1, because poolalloc is much faster than this function.
- if (Size == 1 || Size == 0)
- return poolalloc(Pool);
- if (Size > PoolSlab::getSlabSize(Pool))
- return PoolSlab::createSingleArray(Pool, Size);
-
- PoolSlab *PS = (PoolSlab*)Pool->Ptr1;
- // Loop through all of the slabs looking for one with an opening
- for (; PS; PS = PS->Next) {
- int Element = PS->allocateMultiple(Size);
- if (Element != -1) {
- // We allocated an element. Check to see if this slab has been completely
- // filled up. If so, move it to the Ptr2 list.
- if (PS->isFull()) {
- PS->unlinkFromList();
- PS->addToList((PoolSlab**)&Pool->Ptr2);
- }
- return PS->getElementAddress(Element, Pool->NodeSize);
- }
- }
-
- PoolSlab *New = PoolSlab::create(Pool);
- int Idx = New->allocateMultiple(Size);
- assert(Idx == 0 && "New allocation didn't return zero'th node?");
- return New->getElementAddress(0, 0);
-}
// SearchForContainingSlab - Do a brute force search through the list of
// allocated slabs for the node in question.
More information about the llvm-commits
mailing list