mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-19 01:34:32 +00:00
61425c0a7f
Move to a by-section allocation and relocation scheme. This allows better support for sections which do not contain externally visible symbols. Flesh out the relocation address vs. local storage address separation a bit more as well. Remote process JITs use this to tell the relocation resolution code where the code will live when it executes. The startFunctionBody/endFunctionBody interfaces to the JIT and the memory manager are deprecated. They'll stick around for as long as the old JIT does, but the MCJIT doesn't use them anymore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148258 91177308-0d34-0410-b5e6-96231b3b80d8
83 lines
3.2 KiB
C++
83 lines
3.2 KiB
C++
//===-- 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 {
|
|
virtual void anchor();
|
|
JITMemoryManager *JMM;
|
|
|
|
// FIXME: Multiple modules.
|
|
Module *M;
|
|
public:
|
|
MCJITMemoryManager(JITMemoryManager *jmm, Module *m) : JMM(jmm), M(m) {}
|
|
// We own the JMM, so make sure to delete it.
|
|
~MCJITMemoryManager() { delete JMM; }
|
|
|
|
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
|
|
unsigned SectionID) {
|
|
return JMM->allocateDataSection(Size, Alignment, SectionID);
|
|
}
|
|
|
|
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
|
|
unsigned SectionID) {
|
|
return JMM->allocateCodeSection(Size, Alignment, SectionID);
|
|
}
|
|
|
|
// 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.
|
|
uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) {
|
|
// FIXME: This should really reference the MCAsmInfo to get the global
|
|
// prefix.
|
|
if (Name[0] == '_') ++Name;
|
|
Function *F = M->getFunction(Name);
|
|
// 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 "-" or
|
|
// "+"), try prepending a \01 and see if we can find it that way.
|
|
if (!F && (Name[0] == '-' || Name[0] == '+'))
|
|
F = M->getFunction((Twine("\1") + Name).str());
|
|
assert(F && "No matching function in JIT IR Module!");
|
|
return JMM->startFunctionBody(F, Size);
|
|
}
|
|
|
|
// Mark the end of the function, including how much of the allocated
|
|
// memory was actually used.
|
|
void endFunctionBody(const char *Name, uint8_t *FunctionStart,
|
|
uint8_t *FunctionEnd) {
|
|
// FIXME: This should really reference the MCAsmInfo to get the global
|
|
// prefix.
|
|
if (Name[0] == '_') ++Name;
|
|
Function *F = M->getFunction(Name);
|
|
// 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 "-" or
|
|
// "+"), try prepending a \01 and see if we can find it that way.
|
|
if (!F && (Name[0] == '-' || Name[0] == '+'))
|
|
F = M->getFunction((Twine("\1") + Name).str());
|
|
assert(F && "No matching function in JIT IR Module!");
|
|
JMM->endFunctionBody(F, FunctionStart, FunctionEnd);
|
|
}
|
|
|
|
};
|
|
|
|
} // End llvm namespace
|
|
|
|
#endif
|