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;
57 /// Functions below are not used by MCJIT, but must be implemented because
58 /// they are declared as pure virtuals in the base class.
61 virtual void setMemoryWritable() {
62 llvm_unreachable("Unexpected call!");
64 virtual void setMemoryExecutable() {
65 llvm_unreachable("Unexpected call!");
67 virtual void setPoisonMemory(bool poison) {
68 llvm_unreachable("Unexpected call!");
70 virtual void AllocateGOT() {
71 llvm_unreachable("Unexpected call!");
73 virtual uint8_t *getGOTBase() const {
74 llvm_unreachable("Unexpected call!");
77 virtual uint8_t *startFunctionBody(const Function *F,
78 uintptr_t &ActualSize){
79 llvm_unreachable("Unexpected call!");
82 virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
84 llvm_unreachable("Unexpected call!");
87 virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart,
88 uint8_t *FunctionEnd) {
89 llvm_unreachable("Unexpected call!");
91 virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
92 llvm_unreachable("Unexpected call!");
95 virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
96 llvm_unreachable("Unexpected call!");
99 virtual void deallocateFunctionBody(void *Body) {
100 llvm_unreachable("Unexpected call!");
102 virtual uint8_t *startExceptionTable(const Function *F,
103 uintptr_t &ActualSize) {
104 llvm_unreachable("Unexpected call!");
107 virtual void endExceptionTable(const Function *F, uint8_t *TableStart,
108 uint8_t *TableEnd, uint8_t *FrameRegister) {
109 llvm_unreachable("Unexpected call!");
111 virtual void deallocateExceptionTable(void *ET) {
112 llvm_unreachable("Unexpected call!");
118 #endif // LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H