2011-04-04 23:20:40 +00:00
|
|
|
//===-- MCJITMemoryManager.h - Definition for the Memory Manager ---C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
|
|
|
|
#define LLVM_LIB_EXECUTIONENGINE_MCJITMEMORYMANAGER_H
|
|
|
|
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/ExecutionEngine/JITMemoryManager.h"
|
|
|
|
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
// The MCJIT memory manager is a layer between the standard JITMemoryManager
|
|
|
|
// and the RuntimeDyld interface that maps objects, by name, onto their
|
|
|
|
// matching LLVM IR counterparts in the module(s) being compiled.
|
|
|
|
class MCJITMemoryManager : public RTDyldMemoryManager {
|
|
|
|
JITMemoryManager *JMM;
|
|
|
|
|
|
|
|
// FIXME: Multiple modules.
|
|
|
|
Module *M;
|
|
|
|
public:
|
2011-05-12 18:21:23 +00:00
|
|
|
MCJITMemoryManager(JITMemoryManager *jmm, Module *m) : JMM(jmm), M(m) {}
|
2011-04-04 23:20:40 +00:00
|
|
|
|
|
|
|
// Allocate ActualSize bytes, or more, for the named function. Return
|
|
|
|
// a pointer to the allocated memory and update Size to reflect how much
|
|
|
|
// memory was acutally allocated.
|
2011-04-06 01:11:05 +00:00
|
|
|
uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) {
|
2011-04-08 17:31:24 +00:00
|
|
|
// FIXME: This should really reference the MCAsmInfo to get the global
|
|
|
|
// prefix.
|
|
|
|
if (Name[0] == '_') ++Name;
|
2011-04-04 23:20:40 +00:00
|
|
|
Function *F = M->getFunction(Name);
|
2011-05-18 23:53:21 +00:00
|
|
|
// Some ObjC names have a prefixed \01 in the IR. If we failed to find
|
|
|
|
// the symbol and it's of the ObjC conventions (starts with "-"), try
|
|
|
|
// prepending a \01 and see if we can find it that way.
|
|
|
|
if (!F && Name[0] == '-')
|
|
|
|
F = M->getFunction((Twine("\1") + Name).str());
|
2011-04-04 23:20:40 +00:00
|
|
|
assert(F && "No matching function in JIT IR Module!");
|
2011-04-06 01:11:05 +00:00
|
|
|
return JMM->startFunctionBody(F, Size);
|
2011-04-04 23:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the end of the function, including how much of the allocated
|
|
|
|
// memory was actually used.
|
2011-04-06 01:11:05 +00:00
|
|
|
void endFunctionBody(const char *Name, uint8_t *FunctionStart,
|
|
|
|
uint8_t *FunctionEnd) {
|
2011-04-08 17:31:24 +00:00
|
|
|
// FIXME: This should really reference the MCAsmInfo to get the global
|
|
|
|
// prefix.
|
|
|
|
if (Name[0] == '_') ++Name;
|
2011-04-04 23:20:40 +00:00
|
|
|
Function *F = M->getFunction(Name);
|
2011-05-18 23:53:21 +00:00
|
|
|
// Some ObjC names have a prefixed \01 in the IR. If we failed to find
|
|
|
|
// the symbol and it's of the ObjC conventions (starts with "-"), try
|
|
|
|
// prepending a \01 and see if we can find it that way.
|
|
|
|
if (!F && Name[0] == '-')
|
|
|
|
F = M->getFunction((Twine("\1") + Name).str());
|
2011-04-04 23:20:40 +00:00
|
|
|
assert(F && "No matching function in JIT IR Module!");
|
2011-04-06 01:11:05 +00:00
|
|
|
JMM->endFunctionBody(F, FunctionStart, FunctionEnd);
|
2011-04-04 23:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|