Add basic LLLazyJIT support to Halley
This commit is contained in:
parent
851595ca7d
commit
afc6873c64
|
@ -78,6 +78,7 @@ class SERENE_EXPORT SereneContext {
|
||||||
bool JITenableObjectCache = true;
|
bool JITenableObjectCache = true;
|
||||||
bool JITenableGDBNotificationListener = true;
|
bool JITenableGDBNotificationListener = true;
|
||||||
bool JITenablePerfNotificationListener = true;
|
bool JITenablePerfNotificationListener = true;
|
||||||
|
bool JITLazy = false;
|
||||||
|
|
||||||
Options() = default;
|
Options() = default;
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,6 +93,8 @@ class SERENE_EXPORT Halley {
|
||||||
|
|
||||||
std::shared_ptr<Namespace> activeNS;
|
std::shared_ptr<Namespace> activeNS;
|
||||||
|
|
||||||
|
bool isLazy = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Halley(serene::SereneContext &ctx, llvm::orc::JITTargetMachineBuilder &&jtmb,
|
Halley(serene::SereneContext &ctx, llvm::orc::JITTargetMachineBuilder &&jtmb,
|
||||||
llvm::DataLayout &&dl);
|
llvm::DataLayout &&dl);
|
||||||
|
@ -101,6 +103,7 @@ public:
|
||||||
static MaybeJIT make(serene::SereneContext &ctx,
|
static MaybeJIT make(serene::SereneContext &ctx,
|
||||||
llvm::orc::JITTargetMachineBuilder &&jtmb);
|
llvm::orc::JITTargetMachineBuilder &&jtmb);
|
||||||
|
|
||||||
|
void setEngine(std::unique_ptr<llvm::orc::LLJIT> e, bool isLazy);
|
||||||
/// Looks up a packed-argument function with the given name and returns a
|
/// Looks up a packed-argument function with the given name and returns a
|
||||||
/// pointer to it. Propagates errors in case of failure.
|
/// pointer to it. Propagates errors in case of failure.
|
||||||
// llvm::Expected<void (*)(void **)> lookup(llvm::StringRef name) const;
|
// llvm::Expected<void (*)(void **)> lookup(llvm::StringRef name) const;
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <llvm/ExecutionEngine/Orc/IRCompileLayer.h>
|
#include <llvm/ExecutionEngine/Orc/IRCompileLayer.h>
|
||||||
#include <llvm/ExecutionEngine/Orc/IRTransformLayer.h>
|
#include <llvm/ExecutionEngine/Orc/IRTransformLayer.h>
|
||||||
#include <llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h>
|
#include <llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h>
|
||||||
|
#include <llvm/ExecutionEngine/Orc/LLJIT.h>
|
||||||
#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
|
#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
|
||||||
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
|
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
|
||||||
#include <llvm/IR/Module.h>
|
#include <llvm/IR/Module.h>
|
||||||
|
@ -314,6 +315,13 @@ llvm::Optional<errors::ErrorTree> Halley::addNS(Namespace &ns,
|
||||||
return llvm::None;
|
return llvm::None;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void Halley::setEngine(std::unique_ptr<llvm::orc::LLJIT> e, bool isLazy) {
|
||||||
|
// Later on we might use different classes of JIT which might need some
|
||||||
|
// work for lazyness
|
||||||
|
engine = std::move(e);
|
||||||
|
this->isLazy = isLazy;
|
||||||
|
};
|
||||||
|
|
||||||
void Halley::dumpToObjectFile(llvm::StringRef filename) {
|
void Halley::dumpToObjectFile(llvm::StringRef filename) {
|
||||||
cache->dumpToObjectFile(filename);
|
cache->dumpToObjectFile(filename);
|
||||||
};
|
};
|
||||||
|
@ -414,13 +422,28 @@ MaybeJIT Halley::make(SereneContext &serene_ctx,
|
||||||
std::move(*targetMachine), jitEngine->cache.get());
|
std::move(*targetMachine), jitEngine->cache.get());
|
||||||
};
|
};
|
||||||
|
|
||||||
auto jit =
|
if (serene_ctx.opts.JITLazy) {
|
||||||
cantFail(llvm::orc::LLJITBuilder()
|
// Setup a LLLazyJIT instance to the times that latency is important
|
||||||
.setCompileFunctionCreator(compileFunctionCreator)
|
// for example in a REPL. This way
|
||||||
.setObjectLinkingLayerCreator(objectLinkingLayerCreator)
|
auto jit =
|
||||||
.create());
|
cantFail(llvm::orc::LLLazyJITBuilder()
|
||||||
|
.setCompileFunctionCreator(compileFunctionCreator)
|
||||||
|
.setObjectLinkingLayerCreator(objectLinkingLayerCreator)
|
||||||
|
.create());
|
||||||
|
jitEngine->setEngine(std::move(jit), true);
|
||||||
|
|
||||||
jitEngine->engine = std::move(jit);
|
} else {
|
||||||
|
// Setup a LLJIT instance for the times that performance is important
|
||||||
|
// and we want to compile everything as soon as possible. For instance
|
||||||
|
// when we run the JIT in the compiler
|
||||||
|
auto jit =
|
||||||
|
cantFail(llvm::orc::LLJITBuilder()
|
||||||
|
.setCompileFunctionCreator(compileFunctionCreator)
|
||||||
|
.setObjectLinkingLayerCreator(objectLinkingLayerCreator)
|
||||||
|
.create());
|
||||||
|
|
||||||
|
jitEngine->setEngine(std::move(jit), false);
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve symbols that are statically linked in the current process.
|
// Resolve symbols that are statically linked in the current process.
|
||||||
llvm::orc::JITDylib &mainJD = jitEngine->engine->getMainJITDylib();
|
llvm::orc::JITDylib &mainJD = jitEngine->engine->getMainJITDylib();
|
||||||
|
|
Loading…
Reference in New Issue