summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2019-07-10 17:24:24 +0000
committerLang Hames <lhames@gmail.com>2019-07-10 17:24:24 +0000
commit843f198a83d8161dc580562cbe11643ed2b0e54f (patch)
tree2b99b9f9be4b4f695930150cb6575e71c7d34402 /llvm/lib/ExecutionEngine
parent5a6d40be1f3c2bf5c232877969f0efbe49d370a6 (diff)
downloadbcm5719-llvm-843f198a83d8161dc580562cbe11643ed2b0e54f.tar.gz
bcm5719-llvm-843f198a83d8161dc580562cbe11643ed2b0e54f.zip
[ORC] Add custom IR compiler configuration to LLJITBuilder to enable obj caches.
LLJITBuilder now has a setCompileFunctionCreator method which can be used to construct a CompileFunction for the LLJIT instance being created. The motivating use-case for this is supporting ObjectCaches, which can now be set up at compile-function construction time. To demonstrate this an example project, LLJITWithObjectCache, is included. llvm-svn: 365671
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r--llvm/lib/ExecutionEngine/Orc/LLJIT.cpp79
1 files changed, 35 insertions, 44 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index ae8a66f6144..b120691faf0 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -12,21 +12,6 @@
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/Mangler.h"
-namespace {
-
- // A SimpleCompiler that owns its TargetMachine.
- class TMOwningSimpleCompiler : public llvm::orc::SimpleCompiler {
- public:
- TMOwningSimpleCompiler(std::unique_ptr<llvm::TargetMachine> TM)
- : llvm::orc::SimpleCompiler(*TM), TM(std::move(TM)) {}
- private:
- // FIXME: shared because std::functions (and thus
- // IRCompileLayer::CompileFunction) are not moveable.
- std::shared_ptr<llvm::TargetMachine> TM;
- };
-
-} // end anonymous namespace
-
namespace llvm {
namespace orc {
@@ -86,6 +71,26 @@ LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES) {
return llvm::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
}
+Expected<IRCompileLayer::CompileFunction>
+LLJIT::createCompileFunction(LLJITBuilderState &S,
+ JITTargetMachineBuilder JTMB) {
+
+ /// If there is a custom compile function creator set then use it.
+ if (S.CreateCompileFunction)
+ return S.CreateCompileFunction(std::move(JTMB));
+
+ // Otherwise default to creating a SimpleCompiler, or ConcurrentIRCompiler,
+ // depending on the number of threads requested.
+ if (S.NumCompileThreads > 0)
+ return ConcurrentIRCompiler(std::move(JTMB));
+
+ auto TM = JTMB.createTargetMachine();
+ if (!TM)
+ return TM.takeError();
+
+ return TMOwningSimpleCompiler(std::move(*TM));
+}
+
LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
: ES(S.ES ? std::move(S.ES) : llvm::make_unique<ExecutionSession>()),
Main(this->ES->getMainJITDylib()), DL(""), CtorRunner(Main),
@@ -95,25 +100,25 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
ObjLinkingLayer = createObjectLinkingLayer(S, *ES);
- if (S.NumCompileThreads > 0) {
-
- // Configure multi-threaded.
+ if (auto DLOrErr = S.JTMB->getDefaultDataLayoutForTarget())
+ DL = std::move(*DLOrErr);
+ else {
+ Err = DLOrErr.takeError();
+ return;
+ }
- if (auto DLOrErr = S.JTMB->getDefaultDataLayoutForTarget())
- DL = std::move(*DLOrErr);
- else {
- Err = DLOrErr.takeError();
+ {
+ auto CompileFunction = createCompileFunction(S, std::move(*S.JTMB));
+ if (!CompileFunction) {
+ Err = CompileFunction.takeError();
return;
}
+ CompileLayer = llvm::make_unique<IRCompileLayer>(
+ *ES, *ObjLinkingLayer, std::move(*CompileFunction));
+ }
- {
- auto TmpCompileLayer = llvm::make_unique<IRCompileLayer>(
- *ES, *ObjLinkingLayer, ConcurrentIRCompiler(std::move(*S.JTMB)));
-
- TmpCompileLayer->setCloneToNewContextOnEmit(true);
- CompileLayer = std::move(TmpCompileLayer);
- }
-
+ if (S.NumCompileThreads > 0) {
+ CompileLayer->setCloneToNewContextOnEmit(true);
CompileThreads = llvm::make_unique<ThreadPool>(S.NumCompileThreads);
ES->setDispatchMaterialization(
[this](JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) {
@@ -122,20 +127,6 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
CompileThreads->async(std::move(Work));
});
- } else {
-
- // Configure single-threaded.
-
- auto TM = S.JTMB->createTargetMachine();
- if (!TM) {
- Err = TM.takeError();
- return;
- }
-
- DL = (*TM)->createDataLayout();
-
- CompileLayer = llvm::make_unique<IRCompileLayer>(
- *ES, *ObjLinkingLayer, TMOwningSimpleCompiler(std::move(*TM)));
}
}
OpenPOWER on IntegriCloud