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 | 96c96b46e962c801c610ba878751d8c0ee1359c9 (patch) | |
tree | 06d877835a0d77075144a21723110b0254d0ed4e | |
parent | d07128c906c4b8b64ddc8cb7b14db67d77128b5d (diff) | |
download | external_llvm-96c96b46e962c801c610ba878751d8c0ee1359c9.zip external_llvm-96c96b46e962c801c610ba878751d8c0ee1359c9.tar.gz external_llvm-96c96b46e962c801c610ba878751d8c0ee1359c9.tar.bz2 |
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!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66472 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/ExecutionEngine/JIT/JITMemoryManager.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp index 0dcc71f..b2bf852 100644 --- a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp +++ b/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); } |