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