Adding MCJIT and MemoryBuffer unit tests
[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   /// Functions below are not used by MCJIT, but must be implemented because
57   /// they are declared as pure virtuals in the base class.
58   ///
59
60   virtual void setMemoryWritable() {
61     llvm_unreachable("Unexpected call!");
62   }
63   virtual void setMemoryExecutable() {
64     llvm_unreachable("Unexpected call!");
65   }
66   virtual void setPoisonMemory(bool poison) {
67     llvm_unreachable("Unexpected call!");
68   }
69   virtual void AllocateGOT() {
70     llvm_unreachable("Unexpected call!");
71   }
72   virtual uint8_t *getGOTBase() const {
73     llvm_unreachable("Unexpected call!");
74     return 0;
75   }
76   virtual uint8_t *startFunctionBody(const Function *F,
77                                      uintptr_t &ActualSize){
78     llvm_unreachable("Unexpected call!");
79     return 0;
80   }
81   virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
82                                 unsigned Alignment) {
83     llvm_unreachable("Unexpected call!");
84     return 0;
85   }
86   virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart,
87                                uint8_t *FunctionEnd) {
88     llvm_unreachable("Unexpected call!");
89   }
90   virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
91     llvm_unreachable("Unexpected call!");
92     return 0;
93   }
94   virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
95     llvm_unreachable("Unexpected call!");
96     return 0;
97   }
98   virtual void deallocateFunctionBody(void *Body) {
99     llvm_unreachable("Unexpected call!");
100   }
101   virtual uint8_t *startExceptionTable(const Function *F,
102                                        uintptr_t &ActualSize) {
103     llvm_unreachable("Unexpected call!");
104     return 0;
105   }
106   virtual void endExceptionTable(const Function *F, uint8_t *TableStart,
107                                  uint8_t *TableEnd, uint8_t *FrameRegister) {
108     llvm_unreachable("Unexpected call!");
109   }
110   virtual void deallocateExceptionTable(void *ET) {
111     llvm_unreachable("Unexpected call!");
112   }
113 };
114
115 }
116
117 #endif // LLVM_EXECUTION_ENGINE_SECTION_MEMORY_MANAGER_H