blob: e3c6fda63b487d68b081c2d3e30a5d3892b154dc [file] [log] [blame]
Jim Grosbachb5728302011-04-04 23:20:40 +00001//===-- MCJITMemoryManager.h - Definition for the Memory Manager ---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#ifndef LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
11#define LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
12
13#include "llvm/Module.h"
14#include "llvm/ExecutionEngine/JITMemoryManager.h"
15#include "llvm/ExecutionEngine/RuntimeDyld.h"
16#include <assert.h>
17
18namespace llvm {
19
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.
23class MCJITMemoryManager : public RTDyldMemoryManager {
24 JITMemoryManager *JMM;
25
26 // FIXME: Multiple modules.
27 Module *M;
28public:
29 MCJITMemoryManager(JITMemoryManager *jmm) : JMM(jmm) {}
30
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.
Jim Grosbachc41ab782011-04-06 01:11:05 +000034 uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) {
Jim Grosbachb0271052011-04-08 17:31:24 +000035 // FIXME: This should really reference the MCAsmInfo to get the global
36 // prefix.
37 if (Name[0] == '_') ++Name;
Jim Grosbachb5728302011-04-04 23:20:40 +000038 Function *F = M->getFunction(Name);
39 assert(F && "No matching function in JIT IR Module!");
Jim Grosbachc41ab782011-04-06 01:11:05 +000040 return JMM->startFunctionBody(F, Size);
Jim Grosbachb5728302011-04-04 23:20:40 +000041 }
42
43 // Mark the end of the function, including how much of the allocated
44 // memory was actually used.
Jim Grosbachc41ab782011-04-06 01:11:05 +000045 void endFunctionBody(const char *Name, uint8_t *FunctionStart,
46 uint8_t *FunctionEnd) {
Jim Grosbachb0271052011-04-08 17:31:24 +000047 // FIXME: This should really reference the MCAsmInfo to get the global
48 // prefix.
49 if (Name[0] == '_') ++Name;
Jim Grosbachb5728302011-04-04 23:20:40 +000050 Function *F = M->getFunction(Name);
51 assert(F && "No matching function in JIT IR Module!");
Jim Grosbachc41ab782011-04-06 01:11:05 +000052 JMM->endFunctionBody(F, FunctionStart, FunctionEnd);
Jim Grosbachb5728302011-04-04 23:20:40 +000053 }
54
55};
56
57} // End llvm namespace
58
59#endif