summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2012-01-16 22:26:39 +0000
committerJim Grosbach <grosbach@apple.com>2012-01-16 22:26:39 +0000
commit61425c0a7f4e3608a85f7bbf254cd052a15b7446 (patch)
tree54cde5d3f935fec86f9d6bd60ce2ccbea3376cf7 /lib/ExecutionEngine/JIT/JITMemoryManager.cpp
parent27bf56056bed53d55d7ef0fd67d1851fa860b4f2 (diff)
downloadllvm-61425c0a7f4e3608a85f7bbf254cd052a15b7446.tar.gz
llvm-61425c0a7f4e3608a85f7bbf254cd052a15b7446.tar.bz2
llvm-61425c0a7f4e3608a85f7bbf254cd052a15b7446.tar.xz
MCJIT support for non-function sections.
Move to a by-section allocation and relocation scheme. This allows better support for sections which do not contain externally visible symbols. Flesh out the relocation address vs. local storage address separation a bit more as well. Remote process JITs use this to tell the relocation resolution code where the code will live when it executes. The startFunctionBody/endFunctionBody interfaces to the JIT and the memory manager are deprecated. They'll stick around for as long as the old JIT does, but the MCJIT doesn't use them anymore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/JIT/JITMemoryManager.cpp')
-rw-r--r--lib/ExecutionEngine/JIT/JITMemoryManager.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
index eec23cec0a..efd570d7c5 100644
--- a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
+++ b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
@@ -441,6 +441,50 @@ namespace {
return (uint8_t*)DataAllocator.Allocate(Size, Alignment);
}
+ /// allocateCodeSection - Allocate memory for a code section.
+ uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
+ unsigned SectionID) {
+ // FIXME: Alignement handling.
+ 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;
+ }
+
+ largest = largest - sizeof(MemoryRangeHeader);
+
+ // If this block isn't big enough for the allocation desired, allocate
+ // another block of memory and add it to the free list.
+ if (largest < Size || largest <= FreeRangeHeader::getMinBlockSize()) {
+ DEBUG(dbgs() << "JIT: Allocating another slab of memory for function.");
+ candidateBlock = allocateNewCodeSlab((size_t)Size);
+ }
+
+ // Select this candidate block for allocation
+ CurBlock = candidateBlock;
+
+ // Allocate the entire memory block.
+ FreeMemoryList = candidateBlock->AllocateBlock();
+ // Release the memory at the end of this block that isn't needed.
+ FreeMemoryList = CurBlock->TrimAllocationToSize(FreeMemoryList, Size);
+ return (uint8_t *)(CurBlock + 1);
+ }
+
+ /// allocateDataSection - Allocate memory for a data section.
+ uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
+ unsigned SectionID) {
+ return (uint8_t*)DataAllocator.Allocate(Size, Alignment);
+ }
+
/// startExceptionTable - Use startFunctionBody to allocate memory for the
/// function's exception table.
uint8_t* startExceptionTable(const Function* F, uintptr_t &ActualSize) {