diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-03-09 21:34:10 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-03-09 21:34:10 +0000 |
| commit | 26161cdc6c59a9d6ebf777bd8d29363316a1a6c4 (patch) | |
| tree | e9e24650f7acb42adb4d52aa44c6e5ef1922c82d /llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp | |
| parent | 4a1b0776b3b46481acdb76e1e5ea32eef41ceca4 (diff) | |
| download | bcm5719-llvm-26161cdc6c59a9d6ebf777bd8d29363316a1a6c4.tar.gz bcm5719-llvm-26161cdc6c59a9d6ebf777bd8d29363316a1a6c4.zip | |
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!
llvm-svn: 66472
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp')
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp index 0dcc71f837c..b2bf8529d45 100644 --- a/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JITMemoryManager.cpp @@ -278,10 +278,27 @@ namespace { /// 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); } |

