Skip to content

Commit

Permalink
Revert "Adding object caching support to MCJIT"
Browse files Browse the repository at this point in the history
This reverts commit 07f0392.

Looks like it broke the valgrind bot:

http://lab.llvm.org:8011/builders/llvm-x86_64-linux-vg_leak/builds/649

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180249 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Apr 25, 2013
1 parent 7467e5e commit 06fd5bf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 367 deletions.
7 changes: 0 additions & 7 deletions include/llvm/ExecutionEngine/ExecutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class JITMemoryManager;
class MachineCodeInfo;
class Module;
class MutexGuard;
class ObjectCache;
class DataLayout;
class Triple;
class Type;
Expand Down Expand Up @@ -374,12 +373,6 @@ class ExecutionEngine {
virtual void RegisterJITEventListener(JITEventListener *) {}
virtual void UnregisterJITEventListener(JITEventListener *) {}

/// Sets the pre-compiled object cache. The ownership of the ObjectCache is
/// not changed. Supported by MCJIT but not JIT.
virtual void setObjectCache(ObjectCache *) {
llvm_unreachable("No support for an object cache");
}

/// DisableLazyCompilation - When lazy compilation is off (the default), the
/// JIT will eagerly compile every function reachable from the argument to
/// getPointerToFunction. If lazy compilation is turned on, the JIT will only
Expand Down
54 changes: 0 additions & 54 deletions include/llvm/ExecutionEngine/ObjectCache.h

This file was deleted.

69 changes: 16 additions & 53 deletions lib/ExecutionEngine/MCJIT/MCJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ExecutionEngine *MCJIT::createJIT(Module *M,
MCJIT::MCJIT(Module *m, TargetMachine *tm, RTDyldMemoryManager *MM,
bool AllocateGVsWithCode)
: ExecutionEngine(m), TM(tm), Ctx(0), MemMgr(MM), Dyld(MM),
IsLoaded(false), M(m), ObjCache(0) {
isCompiled(false), M(m) {

setDataLayout(TM->getDataLayout());
}
Expand All @@ -64,11 +64,7 @@ MCJIT::~MCJIT() {
delete TM;
}

void MCJIT::setObjectCache(ObjectCache* NewCache) {
ObjCache = NewCache;
}

ObjectBufferStream* MCJIT::emitObject(Module *m) {
void MCJIT::emitObject(Module *m) {
/// Currently, MCJIT only supports a single module and the module passed to
/// 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
Expand All @@ -81,63 +77,30 @@ ObjectBufferStream* MCJIT::emitObject(Module *m) {
// FIXME: Track compilation state on a per-module basis when multiple modules
// are supported.
// Re-compilation is not supported
assert(!IsLoaded);
if (isCompiled)
return;

PassManager PM;

PM.add(new DataLayout(*TM->getDataLayout()));

// The RuntimeDyld will take ownership of this shortly
OwningPtr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
OwningPtr<ObjectBufferStream> Buffer(new ObjectBufferStream());

// Turn the machine code intermediate representation into bytes in memory
// that may be executed.
if (TM->addPassesToEmitMC(PM, Ctx, CompiledObject->getOStream(), false)) {
if (TM->addPassesToEmitMC(PM, Ctx, Buffer->getOStream(), false)) {
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();

// 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) {
ObjCache->notifyObjectCompiled(m, CompiledObject->getMemBuffer());
}

return CompiledObject.take();
}

void MCJIT::loadObject(Module *M) {

// Get a thread lock to make sure we aren't trying to load multiple times
MutexGuard locked(lock);

// FIXME: Track compilation state on a per-module basis when multiple modules
// are supported.
// Re-compilation is not supported
if (IsLoaded)
return;

OwningPtr<ObjectBuffer> ObjectToLoad;
// Try to load the pre-compiled object from cache if possible
if (0 != ObjCache) {
OwningPtr<MemoryBuffer> PreCompiledObject(ObjCache->getObjectCopy(M));
if (0 != PreCompiledObject.get())
ObjectToLoad.reset(new ObjectBuffer(PreCompiledObject.take()));
}

// If the cache did not contain a suitable object, compile the object
if (!ObjectToLoad) {
ObjectToLoad.reset(emitObject(M));
assert(ObjectToLoad.get() && "Compilation did not produce an object.");
}
Buffer->flush();

// Load the object into the dynamic linker.
// handing off ownership of the buffer
LoadedObject.reset(Dyld.loadObject(ObjectToLoad.take()));
LoadedObject.reset(Dyld.loadObject(Buffer.take()));
if (!LoadedObject)
report_fatal_error(Dyld.getErrorString());

Expand All @@ -150,7 +113,7 @@ void MCJIT::loadObject(Module *M) {
NotifyObjectEmitted(*LoadedObject);

// FIXME: Add support for per-module compilation state
IsLoaded = true;
isCompiled = true;
}

// FIXME: Add a parameter to identify which object is being finalized when
Expand All @@ -159,10 +122,10 @@ void MCJIT::loadObject(Module *M) {
// protection in the interface.
void MCJIT::finalizeObject() {
// If the module hasn't been compiled, just do that.
if (!IsLoaded) {
// If the call to Dyld.resolveRelocations() is removed from loadObject()
if (!isCompiled) {
// If the call to Dyld.resolveRelocations() is removed from emitObject()
// we'll need to do that here.
loadObject(M);
emitObject(M);

// Set page permissions.
MemMgr->applyPermissions();
Expand All @@ -188,8 +151,8 @@ void *MCJIT::getPointerToFunction(Function *F) {
// dies.

// FIXME: Add support for per-module compilation state
if (!IsLoaded)
loadObject(M);
if (!isCompiled)
emitObject(M);

if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
bool AbortOnFailure = !F->hasExternalWeakLinkage();
Expand Down Expand Up @@ -321,8 +284,8 @@ GenericValue MCJIT::runFunction(Function *F,
void *MCJIT::getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure) {
// FIXME: Add support for per-module compilation state
if (!IsLoaded)
loadObject(M);
if (!isCompiled)
emitObject(M);

if (!isSymbolSearchingDisabled() && MemMgr) {
void *ptr = MemMgr->getPointerToNamedFunction(Name, false);
Expand Down
14 changes: 2 additions & 12 deletions lib/ExecutionEngine/MCJIT/MCJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "llvm/ADT/SmallVector.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/PassManager.h"

Expand All @@ -35,23 +34,16 @@ class MCJIT : public ExecutionEngine {
SmallVector<JITEventListener*, 2> EventListeners;

// FIXME: Add support for multiple modules
bool IsLoaded;
bool isCompiled;
Module *M;
OwningPtr<ObjectImage> LoadedObject;

// An optional ObjectCache to be notified of compiled objects and used to
// perform lookup of pre-compiled code to avoid re-compilation.
ObjectCache *ObjCache;

public:
~MCJIT();

/// @name ExecutionEngine interface implementation
/// @{

/// Sets the object manager that MCJIT should use to avoid compilation.
virtual void setObjectCache(ObjectCache *manager);

virtual void finalizeObject();

virtual void *getPointerToBasicBlock(BasicBlock *BB);
Expand Down Expand Up @@ -110,9 +102,7 @@ class MCJIT : public ExecutionEngine {
/// 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.
ObjectBufferStream* emitObject(Module *M);

void loadObject(Module *M);
void emitObject(Module *M);

void NotifyObjectEmitted(const ObjectImage& Obj);
void NotifyFreeingObject(const ObjectImage& Obj);
Expand Down
1 change: 0 additions & 1 deletion unittests/ExecutionEngine/MCJIT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(LLVM_LINK_COMPONENTS
set(MCJITTestsSources
MCJITTest.cpp
MCJITMemoryManagerTest.cpp
MCJITObjectCacheTest.cpp
)

if(MSVC)
Expand Down
Loading

0 comments on commit 06fd5bf

Please sign in to comment.