1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
//===-- SectionMemoryManager.h - Memory allocator for MCJIT -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains the declaration of a section-based memory manager used by
// the MCJIT execution engine.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H
#define LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ExecutionEngine/JITMemoryManager.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Memory.h"
namespace llvm {
// Section-based memory manager for MCJIT
class SectionMemoryManager : public JITMemoryManager {
public:
SectionMemoryManager() { }
~SectionMemoryManager();
virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID);
virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID);
virtual void *getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure = true);
// Invalidate instruction cache for code sections. Some platforms with
// separate data cache and instruction cache require explicit cache flush,
// otherwise JIT code manipulations (like resolved relocations) will get to
// the data cache but not to the instruction cache.
virtual void invalidateInstructionCache();
private:
SmallVector<sys::MemoryBlock, 16> AllocatedDataMem;
SmallVector<sys::MemoryBlock, 16> AllocatedCodeMem;
SmallVector<sys::MemoryBlock, 16> FreeCodeMem;
public:
///
/// Functions below are not used by MCJIT, but must be implemented because
/// they are declared as pure virtuals in the base class.
///
virtual void setMemoryWritable() {
llvm_unreachable("Unexpected call!");
}
virtual void setMemoryExecutable() {
llvm_unreachable("Unexpected call!");
}
virtual void setPoisonMemory(bool poison) {
llvm_unreachable("Unexpected call!");
}
virtual void AllocateGOT() {
llvm_unreachable("Unexpected call!");
}
virtual uint8_t *getGOTBase() const {
llvm_unreachable("Unexpected call!");
return 0;
}
virtual uint8_t *startFunctionBody(const Function *F,
uintptr_t &ActualSize){
llvm_unreachable("Unexpected call!");
return 0;
}
virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
unsigned Alignment) {
llvm_unreachable("Unexpected call!");
return 0;
}
virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart,
uint8_t *FunctionEnd) {
llvm_unreachable("Unexpected call!");
}
virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
llvm_unreachable("Unexpected call!");
return 0;
}
virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
llvm_unreachable("Unexpected call!");
return 0;
}
virtual void deallocateFunctionBody(void *Body) {
llvm_unreachable("Unexpected call!");
}
virtual uint8_t *startExceptionTable(const Function *F,
uintptr_t &ActualSize) {
llvm_unreachable("Unexpected call!");
return 0;
}
virtual void endExceptionTable(const Function *F, uint8_t *TableStart,
uint8_t *TableEnd, uint8_t *FrameRegister) {
llvm_unreachable("Unexpected call!");
}
virtual void deallocateExceptionTable(void *ET) {
llvm_unreachable("Unexpected call!");
}
};
}
#endif // LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H
|