1 //===-- JITMemoryManager.h - Interface JIT uses to Allocate Mem -*- 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 defines the JITMemoryManagerInterface
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_EXECUTION_ENGINE_JIT_MEMMANAGER_H
15 #define LLVM_EXECUTION_ENGINE_JIT_MEMMANAGER_H
17 #include "llvm/Support/DataTypes.h"
22 /// JITMemoryManager - This interface is used by the JIT to allocate and manage
23 /// memory for the code generated by the JIT. This can be reimplemented by
24 /// clients that have a strong desire to control how the layout of JIT'd memory
26 class JITMemoryManager {
30 JITMemoryManager() : HasGOT(false) {}
31 virtual ~JITMemoryManager();
33 /// CreateDefaultMemManager - This is used to create the default
34 /// JIT Memory Manager if the client does not provide one to the JIT.
35 static JITMemoryManager *CreateDefaultMemManager();
37 //===--------------------------------------------------------------------===//
38 // Global Offset Table Management
39 //===--------------------------------------------------------------------===//
41 /// AllocateGOT - If the current table requires a Global Offset Table, this
42 /// method is invoked to allocate it. This method is required to set HasGOT
44 virtual void AllocateGOT() = 0;
46 /// isManagingGOT - Return true if the AllocateGOT method is called.
48 bool isManagingGOT() const {
52 /// getGOTBase - If this is managing a Global Offset Table, this method should
53 /// return a pointer to its base.
54 virtual unsigned char *getGOTBase() const = 0;
56 //===--------------------------------------------------------------------===//
57 // Main Allocation Functions
58 //===--------------------------------------------------------------------===//
60 /// startFunctionBody - When we start JITing a function, the JIT calls this
61 /// method to allocate a block of free RWX memory, which returns a pointer to
62 /// it. The JIT doesn't know ahead of time how much space it will need to
63 /// emit the function, so it doesn't pass in the size. Instead, this method
64 /// is required to pass back a "valid size". The JIT will be careful to not
65 /// write more than the returned ActualSize bytes of memory.
66 virtual unsigned char *startFunctionBody(const Function *F,
67 uintptr_t &ActualSize) = 0;
69 /// allocateStub - This method is called by the JIT to allocate space for a
70 /// function stub (used to handle limited branch displacements) while it is
71 /// JIT compiling a function. For example, if foo calls bar, and if bar
72 /// either needs to be lazily compiled or is a native function that exists too
73 /// far away from the call site to work, this method will be used to make a
74 /// thunk for it. The stub should be "close" to the current function body,
75 /// but should not be included in the 'actualsize' returned by
76 /// startFunctionBody.
77 virtual unsigned char *allocateStub(unsigned StubSize, unsigned Alignment) =0;
80 /// endFunctionBody - This method is called when the JIT is done codegen'ing
81 /// the specified function. At this point we know the size of the JIT
82 /// compiled function. This passes in FunctionStart (which was returned by
83 /// the startFunctionBody method) and FunctionEnd which is a pointer to the
84 /// actual end of the function. This method should mark the space allocated
85 /// and remember where it is in case the client wants to deallocate it.
86 virtual void endFunctionBody(const Function *F, unsigned char *FunctionStart,
87 unsigned char *FunctionEnd) = 0;
89 /// deallocateMemForFunction - Free JIT memory for the specified function.
90 /// This is never called when the JIT is currently emitting a function.
91 virtual void deallocateMemForFunction(const Function *F) = 0;
93 /// startExceptionTable - When we finished JITing the function, if exception
94 /// handling is set, we emit the exception table.
95 virtual unsigned char* startExceptionTable(const Function* F,
96 uintptr_t &ActualSize) = 0;
98 /// endExceptionTable - This method is called when the JIT is done emitting
99 /// the exception table.
100 virtual void endExceptionTable(const Function *F, unsigned char *TableStart,
101 unsigned char *TableEnd,
102 unsigned char* FrameRegister) = 0;
105 } // end namespace llvm.