[llvm-commits] [llvm] r66472 - /llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
Chris Lattner
sabre at nondot.org
Mon Mar 9 14:34:11 PDT 2009
Author: lattner
Date: Mon Mar 9 16:34:10 2009
New Revision: 66472
URL: http://llvm.org/viewvc/llvm-project?rev=66472&view=rev
Log:
Fix PR3724 by searching for the largest free block when
allocating memory in the JIT. This is insanely inefficient, but
hey, most people implement their own memory managers anyway.
Patch by Eric Yew!
Modified:
llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp?rev=66472&r1=66471&r2=66472&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Mon Mar 9 16:34:10 2009
@@ -278,10 +278,27 @@
/// startFunctionBody - When a function starts, allocate a block of free
/// executable memory, returning a pointer to it and its actual size.
unsigned char *startFunctionBody(const Function *F, uintptr_t &ActualSize) {
- CurBlock = FreeMemoryList;
+ FreeRangeHeader* candidateBlock = FreeMemoryList;
+ FreeRangeHeader* head = FreeMemoryList;
+ FreeRangeHeader* iter = head->Next;
+
+ uintptr_t largest = candidateBlock->BlockSize;
+
+ // Search for the largest free block
+ while (iter != head) {
+ if (iter->BlockSize > largest) {
+ largest = iter->BlockSize;
+ candidateBlock = iter;
+ }
+ iter = iter->Next;
+ }
+
+ // Select this candidate block for allocation
+ CurBlock = candidateBlock;
+
// Allocate the entire memory block.
- FreeMemoryList = FreeMemoryList->AllocateBlock();
+ FreeMemoryList = candidateBlock->AllocateBlock();
ActualSize = CurBlock->BlockSize-sizeof(MemoryRangeHeader);
return (unsigned char *)(CurBlock+1);
}
More information about the llvm-commits
mailing list