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