1 //===-- SectionMemoryManager.h - Memory allocator for MCJIT -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of a section-based memory manager used by
11 // the MCJIT execution engine.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H
16 #define LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ExecutionEngine/JITMemoryManager.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/Memory.h"
25 // Section-based memory manager for MCJIT
26 class SectionMemoryManager : public JITMemoryManager {
30 SectionMemoryManager() { }
31 ~SectionMemoryManager();
33 virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
36 virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
39 virtual void *getPointerToNamedFunction(const std::string &Name,
40 bool AbortOnFailure = true);
42 // Invalidate instruction cache for code sections. Some platforms with
43 // separate data cache and instruction cache require explicit cache flush,
44 // otherwise JIT code manipulations (like resolved relocations) will get to
45 // the data cache but not to the instruction cache.
46 virtual void invalidateInstructionCache();
50 SmallVector<sys::MemoryBlock, 16> AllocatedDataMem;
51 SmallVector<sys::MemoryBlock, 16> AllocatedCodeMem;
52 SmallVector<sys::MemoryBlock, 16> FreeCodeMem;
56 /// Functions below are not used by MCJIT, but must be implemented because
57 /// they are declared as pure virtuals in the base class.
60 virtual void setMemoryWritable() {
61 llvm_unreachable("Unexpected call!");
63 virtual void setMemoryExecutable() {
64 llvm_unreachable("Unexpected call!");
66 virtual void setPoisonMemory(bool poison) {
67 llvm_unreachable("Unexpected call!");
69 virtual void AllocateGOT() {
70 llvm_unreachable("Unexpected call!");
72 virtual uint8_t *getGOTBase() const {
73 llvm_unreachable("Unexpected call!");
76 virtual uint8_t *startFunctionBody(const Function *F,
77 uintptr_t &ActualSize){
78 llvm_unreachable("Unexpected call!");
81 virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
83 llvm_unreachable("Unexpected call!");
86 virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart,
87 uint8_t *FunctionEnd) {
88 llvm_unreachable("Unexpected call!");
90 virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
91 llvm_unreachable("Unexpected call!");
94 virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
95 llvm_unreachable("Unexpected call!");
98 virtual void deallocateFunctionBody(void *Body) {
99 llvm_unreachable("Unexpected call!");
101 virtual uint8_t *startExceptionTable(const Function *F,
102 uintptr_t &ActualSize) {
103 llvm_unreachable("Unexpected call!");
106 virtual void endExceptionTable(const Function *F, uint8_t *TableStart,
107 uint8_t *TableEnd, uint8_t *FrameRegister) {
108 llvm_unreachable("Unexpected call!");
110 virtual void deallocateExceptionTable(void *ET) {
111 llvm_unreachable("Unexpected call!");
117 #endif // LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H