summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/MCJIT
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ExecutionEngine/MCJIT')
-rw-r--r--llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp71
-rw-r--r--llvm/lib/ExecutionEngine/MCJIT/MCJIT.h13
-rw-r--r--llvm/lib/ExecutionEngine/MCJIT/ObjectBuffer.h48
3 files changed, 39 insertions, 93 deletions
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 58cf4e5e6dd..da5f03799e3 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -11,6 +11,8 @@
#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"
@@ -19,7 +21,6 @@
#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"
@@ -30,8 +31,6 @@
using namespace llvm;
-void ObjectCache::anchor() {}
-
namespace {
static struct RegisterJIT {
@@ -75,7 +74,6 @@ 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() {
@@ -101,13 +99,13 @@ bool MCJIT::removeModule(Module *M) {
}
void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) {
- std::unique_ptr<RuntimeDyld::LoadedObjectInfo> L = Dyld.loadObject(*Obj);
- if (Dyld.hasError())
+ std::unique_ptr<ObjectImage> LoadedObject = Dyld.loadObject(std::move(Obj));
+ if (!LoadedObject || Dyld.hasError())
report_fatal_error(Dyld.getErrorString());
- NotifyObjectEmitted(*Obj, *L);
+ NotifyObjectEmitted(*LoadedObject);
- LoadedObjects.push_back(std::move(Obj));
+ LoadedObjects.push_back(std::move(LoadedObject));
}
void MCJIT::addObjectFile(object::OwningBinary<object::ObjectFile> Obj) {
@@ -127,7 +125,7 @@ void MCJIT::setObjectCache(ObjectCache* NewCache) {
ObjCache = NewCache;
}
-std::unique_ptr<MemoryBuffer> MCJIT::emitObject(Module *M) {
+std::unique_ptr<ObjectBufferStream> MCJIT::emitObject(Module *M) {
MutexGuard locked(lock);
// This must be a module which has already been added but not loaded to this
@@ -140,32 +138,30 @@ std::unique_ptr<MemoryBuffer> MCJIT::emitObject(Module *M) {
PM.add(new DataLayoutPass());
// The RuntimeDyld will take ownership of this shortly
- SmallVector<char, 4096> ObjBufferSV;
- raw_svector_ostream ObjStream(ObjBufferSV);
+ std::unique_ptr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
// Turn the machine code intermediate representation into bytes in memory
// that may be executed.
- if (TM->addPassesToEmitMC(PM, Ctx, ObjStream, !getVerifyModules()))
+ if (TM->addPassesToEmitMC(PM, Ctx, CompiledObject->getOStream(),
+ !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
- ObjStream.flush();
-
- std::unique_ptr<MemoryBuffer> CompiledObjBuffer(
- new ObjectMemoryBuffer(std::move(ObjBufferSV)));
+ CompiledObject->flush();
// 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 = CompiledObjBuffer->getMemBufferRef();
+ MemoryBufferRef MB = CompiledObject->getMemBuffer();
ObjCache->notifyObjectCompiled(M, MB);
}
- return CompiledObjBuffer;
+ return CompiledObject;
}
void MCJIT::generateCodeForModule(Module *M) {
@@ -180,10 +176,14 @@ void MCJIT::generateCodeForModule(Module *M) {
if (OwnedModules.hasModuleBeenLoaded(M))
return;
- std::unique_ptr<MemoryBuffer> ObjectToLoad;
+ std::unique_ptr<ObjectBuffer> ObjectToLoad;
// Try to load the pre-compiled object from cache if possible
- if (ObjCache)
- ObjectToLoad = ObjCache->getObject(M);
+ if (ObjCache) {
+ if (std::unique_ptr<MemoryBuffer> PreCompiledObject =
+ ObjCache->getObject(M))
+ ObjectToLoad =
+ llvm::make_unique<ObjectBuffer>(std::move(PreCompiledObject));
+ }
// If the cache did not contain a suitable object, compile the object
if (!ObjectToLoad) {
@@ -193,18 +193,17 @@ void MCJIT::generateCodeForModule(Module *M) {
// Load the object into the dynamic linker.
// MCJIT now owns the ObjectImage pointer (via its LoadedObjects list).
- 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())
+ std::unique_ptr<ObjectImage> LoadedObject =
+ Dyld.loadObject(std::move(ObjectToLoad));
+ if (!LoadedObject)
report_fatal_error(Dyld.getErrorString());
- NotifyObjectEmitted(*LoadedObject.get(), *L);
+ // FIXME: Make this optional, maybe even move it to a JIT event listener
+ LoadedObject->registerWithDebugger();
+
+ NotifyObjectEmitted(*LoadedObject);
- Buffers.push_back(std::move(ObjectToLoad));
- LoadedObjects.push_back(std::move(*LoadedObject));
+ LoadedObjects.push_back(std::move(LoadedObject));
OwnedModules.markModuleAsLoaded(M);
}
@@ -550,7 +549,6 @@ void MCJIT::RegisterJITEventListener(JITEventListener *L) {
MutexGuard locked(lock);
EventListeners.push_back(L);
}
-
void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
if (!L)
return;
@@ -561,17 +559,14 @@ void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
EventListeners.pop_back();
}
}
-
-void MCJIT::NotifyObjectEmitted(const object::ObjectFile& Obj,
- const RuntimeDyld::LoadedObjectInfo &L) {
+void MCJIT::NotifyObjectEmitted(const ObjectImage& Obj) {
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, L);
+ EventListeners[I]->NotifyObjectEmitted(Obj);
}
}
-
-void MCJIT::NotifyFreeingObject(const object::ObjectFile& Obj) {
+void MCJIT::NotifyFreeingObject(const ObjectImage& Obj) {
MutexGuard locked(lock);
for (JITEventListener *L : EventListeners)
L->NotifyFreeingObject(Obj);
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
index 6f92e51b64c..bc943b9b886 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
@@ -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 object::ObjectFile &Obj) override {
+ const ObjectImage *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<object::ObjectFile>, 2> LoadedObjects;
+ SmallVector<std::unique_ptr<ObjectImage>, 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,11 +341,10 @@ 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<MemoryBuffer> emitObject(Module *M);
+ std::unique_ptr<ObjectBufferStream> emitObject(Module *M);
- void NotifyObjectEmitted(const object::ObjectFile& Obj,
- const RuntimeDyld::LoadedObjectInfo &L);
- void NotifyFreeingObject(const object::ObjectFile& Obj);
+ void NotifyObjectEmitted(const ObjectImage& Obj);
+ void NotifyFreeingObject(const ObjectImage& Obj);
uint64_t getExistingSymbolAddress(const std::string &Name);
Module *findModuleForSymbol(const std::string &Name,
diff --git a/llvm/lib/ExecutionEngine/MCJIT/ObjectBuffer.h b/llvm/lib/ExecutionEngine/MCJIT/ObjectBuffer.h
deleted file mode 100644
index 92310f3eb54..00000000000
--- a/llvm/lib/ExecutionEngine/MCJIT/ObjectBuffer.h
+++ /dev/null
@@ -1,48 +0,0 @@
-//===--- 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
OpenPOWER on IntegriCloud