mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
[MCJIT] Reapply r222828 and r222810-r222812 with fix for MSVC move-op issues.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222840 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
#include "llvm/ExecutionEngine/GenericValue.h"
|
||||
#include "llvm/ExecutionEngine/JITEventListener.h"
|
||||
#include "llvm/ExecutionEngine/MCJIT.h"
|
||||
#include "llvm/ExecutionEngine/ObjectBuffer.h"
|
||||
#include "llvm/ExecutionEngine/ObjectImage.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
@@ -21,6 +19,7 @@
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/Object/Archive.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
#include "llvm/PassManager.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
@@ -31,6 +30,8 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
void ObjectCache::anchor() {}
|
||||
|
||||
namespace {
|
||||
|
||||
static struct RegisterJIT {
|
||||
@@ -74,6 +75,7 @@ MCJIT::MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> tm,
|
||||
|
||||
OwnedModules.addModule(std::move(First));
|
||||
setDataLayout(TM->getSubtargetImpl()->getDataLayout());
|
||||
RegisterJITEventListener(JITEventListener::createGDBRegistrationListener());
|
||||
}
|
||||
|
||||
MCJIT::~MCJIT() {
|
||||
@@ -99,13 +101,13 @@ bool MCJIT::removeModule(Module *M) {
|
||||
}
|
||||
|
||||
void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) {
|
||||
std::unique_ptr<ObjectImage> LoadedObject = Dyld.loadObject(std::move(Obj));
|
||||
if (!LoadedObject || Dyld.hasError())
|
||||
std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L = Dyld.loadObject(*Obj);
|
||||
if (Dyld.hasError())
|
||||
report_fatal_error(Dyld.getErrorString());
|
||||
|
||||
NotifyObjectEmitted(*LoadedObject);
|
||||
NotifyObjectEmitted(*Obj, *L);
|
||||
|
||||
LoadedObjects.push_back(std::move(LoadedObject));
|
||||
LoadedObjects.push_back(std::move(Obj));
|
||||
}
|
||||
|
||||
void MCJIT::addObjectFile(object::OwningBinary<object::ObjectFile> Obj) {
|
||||
@@ -125,7 +127,7 @@ void MCJIT::setObjectCache(ObjectCache* NewCache) {
|
||||
ObjCache = NewCache;
|
||||
}
|
||||
|
||||
std::unique_ptr<ObjectBufferStream> MCJIT::emitObject(Module *M) {
|
||||
std::unique_ptr<MemoryBuffer> MCJIT::emitObject(Module *M) {
|
||||
MutexGuard locked(lock);
|
||||
|
||||
// This must be a module which has already been added but not loaded to this
|
||||
@@ -138,30 +140,32 @@ std::unique_ptr<ObjectBufferStream> MCJIT::emitObject(Module *M) {
|
||||
PM.add(new DataLayoutPass());
|
||||
|
||||
// The RuntimeDyld will take ownership of this shortly
|
||||
std::unique_ptr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
|
||||
SmallVector<char, 4096> ObjBufferSV;
|
||||
raw_svector_ostream ObjStream(ObjBufferSV);
|
||||
|
||||
// Turn the machine code intermediate representation into bytes in memory
|
||||
// that may be executed.
|
||||
if (TM->addPassesToEmitMC(PM, Ctx, CompiledObject->getOStream(),
|
||||
!getVerifyModules())) {
|
||||
if (TM->addPassesToEmitMC(PM, Ctx, ObjStream, !getVerifyModules()))
|
||||
report_fatal_error("Target does not support MC emission!");
|
||||
}
|
||||
|
||||
// Initialize passes.
|
||||
PM.run(*M);
|
||||
// Flush the output buffer to get the generated code into memory
|
||||
CompiledObject->flush();
|
||||
ObjStream.flush();
|
||||
|
||||
std::unique_ptr<MemoryBuffer> CompiledObjBuffer(
|
||||
new ObjectMemoryBuffer(std::move(ObjBufferSV)));
|
||||
|
||||
// If we have an object cache, tell it about the new object.
|
||||
// Note that we're using the compiled image, not the loaded image (as below).
|
||||
if (ObjCache) {
|
||||
// MemoryBuffer is a thin wrapper around the actual memory, so it's OK
|
||||
// to create a temporary object here and delete it after the call.
|
||||
MemoryBufferRef MB = CompiledObject->getMemBuffer();
|
||||
MemoryBufferRef MB = CompiledObjBuffer->getMemBufferRef();
|
||||
ObjCache->notifyObjectCompiled(M, MB);
|
||||
}
|
||||
|
||||
return CompiledObject;
|
||||
return CompiledObjBuffer;
|
||||
}
|
||||
|
||||
void MCJIT::generateCodeForModule(Module *M) {
|
||||
@@ -176,14 +180,10 @@ void MCJIT::generateCodeForModule(Module *M) {
|
||||
if (OwnedModules.hasModuleBeenLoaded(M))
|
||||
return;
|
||||
|
||||
std::unique_ptr<ObjectBuffer> ObjectToLoad;
|
||||
std::unique_ptr<MemoryBuffer> ObjectToLoad;
|
||||
// Try to load the pre-compiled object from cache if possible
|
||||
if (ObjCache) {
|
||||
if (std::unique_ptr<MemoryBuffer> PreCompiledObject =
|
||||
ObjCache->getObject(M))
|
||||
ObjectToLoad =
|
||||
llvm::make_unique<ObjectBuffer>(std::move(PreCompiledObject));
|
||||
}
|
||||
if (ObjCache)
|
||||
ObjectToLoad = ObjCache->getObject(M);
|
||||
|
||||
// If the cache did not contain a suitable object, compile the object
|
||||
if (!ObjectToLoad) {
|
||||
@@ -193,17 +193,18 @@ void MCJIT::generateCodeForModule(Module *M) {
|
||||
|
||||
// Load the object into the dynamic linker.
|
||||
// MCJIT now owns the ObjectImage pointer (via its LoadedObjects list).
|
||||
std::unique_ptr<ObjectImage> LoadedObject =
|
||||
Dyld.loadObject(std::move(ObjectToLoad));
|
||||
if (!LoadedObject)
|
||||
ErrorOr<std::unique_ptr<object::ObjectFile>> LoadedObject =
|
||||
object::ObjectFile::createObjectFile(ObjectToLoad->getMemBufferRef());
|
||||
std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L =
|
||||
Dyld.loadObject(*LoadedObject.get());
|
||||
|
||||
if (Dyld.hasError())
|
||||
report_fatal_error(Dyld.getErrorString());
|
||||
|
||||
// FIXME: Make this optional, maybe even move it to a JIT event listener
|
||||
LoadedObject->registerWithDebugger();
|
||||
NotifyObjectEmitted(*LoadedObject.get(), *L);
|
||||
|
||||
NotifyObjectEmitted(*LoadedObject);
|
||||
|
||||
LoadedObjects.push_back(std::move(LoadedObject));
|
||||
Buffers.push_back(std::move(ObjectToLoad));
|
||||
LoadedObjects.push_back(std::move(*LoadedObject));
|
||||
|
||||
OwnedModules.markModuleAsLoaded(M);
|
||||
}
|
||||
@@ -549,6 +550,7 @@ void MCJIT::RegisterJITEventListener(JITEventListener *L) {
|
||||
MutexGuard locked(lock);
|
||||
EventListeners.push_back(L);
|
||||
}
|
||||
|
||||
void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
|
||||
if (!L)
|
||||
return;
|
||||
@@ -559,14 +561,17 @@ void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
|
||||
EventListeners.pop_back();
|
||||
}
|
||||
}
|
||||
void MCJIT::NotifyObjectEmitted(const ObjectImage& Obj) {
|
||||
|
||||
void MCJIT::NotifyObjectEmitted(const object::ObjectFile& Obj,
|
||||
const RuntimeDyld::LoadedObjectInfo &L) {
|
||||
MutexGuard locked(lock);
|
||||
MemMgr.notifyObjectLoaded(this, &Obj);
|
||||
MemMgr.notifyObjectLoaded(this, Obj);
|
||||
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
|
||||
EventListeners[I]->NotifyObjectEmitted(Obj);
|
||||
EventListeners[I]->NotifyObjectEmitted(Obj, L);
|
||||
}
|
||||
}
|
||||
void MCJIT::NotifyFreeingObject(const ObjectImage& Obj) {
|
||||
|
||||
void MCJIT::NotifyFreeingObject(const object::ObjectFile& Obj) {
|
||||
MutexGuard locked(lock);
|
||||
for (JITEventListener *L : EventListeners)
|
||||
L->NotifyFreeingObject(Obj);
|
||||
|
@@ -10,12 +10,12 @@
|
||||
#ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H
|
||||
#define LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H
|
||||
|
||||
#include "ObjectBuffer.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
||||
#include "llvm/ExecutionEngine/ObjectCache.h"
|
||||
#include "llvm/ExecutionEngine/ObjectImage.h"
|
||||
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
}
|
||||
|
||||
void notifyObjectLoaded(ExecutionEngine *EE,
|
||||
const ObjectImage *Obj) override {
|
||||
const object::ObjectFile &Obj) override {
|
||||
ClientMM->notifyObjectLoaded(EE, Obj);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ class MCJIT : public ExecutionEngine {
|
||||
SmallVector<object::OwningBinary<object::Archive>, 2> Archives;
|
||||
SmallVector<std::unique_ptr<MemoryBuffer>, 2> Buffers;
|
||||
|
||||
SmallVector<std::unique_ptr<ObjectImage>, 2> LoadedObjects;
|
||||
SmallVector<std::unique_ptr<object::ObjectFile>, 2> LoadedObjects;
|
||||
|
||||
// An optional ObjectCache to be notified of compiled objects and used to
|
||||
// perform lookup of pre-compiled code to avoid re-compilation.
|
||||
@@ -341,10 +341,11 @@ protected:
|
||||
/// this function call is expected to be the contained module. The module
|
||||
/// is passed as a parameter here to prepare for multiple module support in
|
||||
/// the future.
|
||||
std::unique_ptr<ObjectBufferStream> emitObject(Module *M);
|
||||
std::unique_ptr<MemoryBuffer> emitObject(Module *M);
|
||||
|
||||
void NotifyObjectEmitted(const ObjectImage& Obj);
|
||||
void NotifyFreeingObject(const ObjectImage& Obj);
|
||||
void NotifyObjectEmitted(const object::ObjectFile& Obj,
|
||||
const RuntimeDyld::LoadedObjectInfo &L);
|
||||
void NotifyFreeingObject(const object::ObjectFile& Obj);
|
||||
|
||||
uint64_t getExistingSymbolAddress(const std::string &Name);
|
||||
Module *findModuleForSymbol(const std::string &Name,
|
||||
|
48
lib/ExecutionEngine/MCJIT/ObjectBuffer.h
Normal file
48
lib/ExecutionEngine/MCJIT/ObjectBuffer.h
Normal file
@@ -0,0 +1,48 @@
|
||||
//===--- ObjectBuffer.h - Utility class to wrap object memory ---*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file declares a wrapper class to hold the memory into which an
|
||||
// object will be generated.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_OBJECTBUFFER_H
|
||||
#define LLVM_EXECUTIONENGINE_OBJECTBUFFER_H
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class ObjectMemoryBuffer : public MemoryBuffer {
|
||||
public:
|
||||
template <unsigned N>
|
||||
ObjectMemoryBuffer(SmallVector<char, N> SV)
|
||||
: SV(SV), BufferName("<in-memory object>") {
|
||||
init(this->SV.begin(), this->SV.end(), false);
|
||||
}
|
||||
|
||||
template <unsigned N>
|
||||
ObjectMemoryBuffer(SmallVector<char, N> SV, StringRef Name)
|
||||
: SV(SV), BufferName(Name) {
|
||||
init(this->SV.begin(), this->SV.end(), false);
|
||||
}
|
||||
const char* getBufferIdentifier() const override { return BufferName.c_str(); }
|
||||
|
||||
BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
|
||||
|
||||
private:
|
||||
SmallVector<char, 4096> SV;
|
||||
std::string BufferName;
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user