1 //===-- MCJITMemoryManager.h - Definition for the Memory Manager ---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 #ifndef LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
11 #define LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
13 #include "llvm/Module.h"
14 #include "llvm/ExecutionEngine/JITMemoryManager.h"
15 #include "llvm/ExecutionEngine/RuntimeDyld.h"
20 // The MCJIT memory manager is a layer between the standard JITMemoryManager
21 // and the RuntimeDyld interface that maps objects, by name, onto their
22 // matching LLVM IR counterparts in the module(s) being compiled.
23 class MCJITMemoryManager : public RTDyldMemoryManager {
24 JITMemoryManager *JMM;
26 // FIXME: Multiple modules.
29 MCJITMemoryManager(JITMemoryManager *jmm, Module *m) : JMM(jmm), M(m) {}
31 // Allocate ActualSize bytes, or more, for the named function. Return
32 // a pointer to the allocated memory and update Size to reflect how much
33 // memory was acutally allocated.
34 uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) {
35 // FIXME: This should really reference the MCAsmInfo to get the global
37 if (Name[0] == '_') ++Name;
38 Function *F = M->getFunction(Name);
39 assert(F && "No matching function in JIT IR Module!");
40 return JMM->startFunctionBody(F, Size);
43 // Mark the end of the function, including how much of the allocated
44 // memory was actually used.
45 void endFunctionBody(const char *Name, uint8_t *FunctionStart,
46 uint8_t *FunctionEnd) {
47 // FIXME: This should really reference the MCAsmInfo to get the global
49 if (Name[0] == '_') ++Name;
50 Function *F = M->getFunction(Name);
51 assert(F && "No matching function in JIT IR Module!");
52 JMM->endFunctionBody(F, FunctionStart, FunctionEnd);
57 } // End llvm namespace