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 virtual void anchor();
25 JITMemoryManager *JMM;
27 // FIXME: Multiple modules.
30 MCJITMemoryManager(JITMemoryManager *jmm, Module *m) : JMM(jmm), M(m) {}
31 // We own the JMM, so make sure to delete it.
32 ~MCJITMemoryManager() { delete JMM; }
34 // Allocate ActualSize bytes, or more, for the named function. Return
35 // a pointer to the allocated memory and update Size to reflect how much
36 // memory was acutally allocated.
37 uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) {
38 // FIXME: This should really reference the MCAsmInfo to get the global
40 if (Name[0] == '_') ++Name;
41 Function *F = M->getFunction(Name);
42 // Some ObjC names have a prefixed \01 in the IR. If we failed to find
43 // the symbol and it's of the ObjC conventions (starts with "-" or
44 // "+"), try prepending a \01 and see if we can find it that way.
45 if (!F && (Name[0] == '-' || Name[0] == '+'))
46 F = M->getFunction((Twine("\1") + Name).str());
47 assert(F && "No matching function in JIT IR Module!");
48 return JMM->startFunctionBody(F, Size);
51 // Mark the end of the function, including how much of the allocated
52 // memory was actually used.
53 void endFunctionBody(const char *Name, uint8_t *FunctionStart,
54 uint8_t *FunctionEnd) {
55 // FIXME: This should really reference the MCAsmInfo to get the global
57 if (Name[0] == '_') ++Name;
58 Function *F = M->getFunction(Name);
59 // Some ObjC names have a prefixed \01 in the IR. If we failed to find
60 // the symbol and it's of the ObjC conventions (starts with "-" or
61 // "+"), try prepending a \01 and see if we can find it that way.
62 if (!F && (Name[0] == '-' || Name[0] == '+'))
63 F = M->getFunction((Twine("\1") + Name).str());
64 assert(F && "No matching function in JIT IR Module!");
65 JMM->endFunctionBody(F, FunctionStart, FunctionEnd);
70 } // End llvm namespace