mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
[ORC] Add definition for IRLayer::setCloneToNewContextOnEmit, use it to set the
flag to true in LLJIT when running in multithreaded mode. The IRLayer::setCloneToNewContextOnEmit method sets a flag within the IRLayer that causes modules added to that layer to be moved to a new context (by serializing to/from a memory buffer) when they are emitted. This allows modules that were all loaded on the same context to be compiled in parallel. llvm-svn: 343266
This commit is contained in:
parent
61a34ded66
commit
6e429798e4
@ -40,7 +40,9 @@ public:
|
|||||||
/// compiling them to enable concurrent compilation.
|
/// compiling them to enable concurrent compilation.
|
||||||
/// Single threaded clients, or clients who load every module on a new
|
/// Single threaded clients, or clients who load every module on a new
|
||||||
/// context, need not set this.
|
/// context, need not set this.
|
||||||
void setCloneToNewContextOnEmit(bool CloneToNewContextOnEmit);
|
void setCloneToNewContextOnEmit(bool CloneToNewContextOnEmit) {
|
||||||
|
this->CloneToNewContextOnEmit = CloneToNewContextOnEmit;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the current value of the CloneToNewContextOnEmit flag.
|
/// Returns the current value of the CloneToNewContextOnEmit flag.
|
||||||
bool getCloneToNewContextOnEmit() const { return CloneToNewContextOnEmit; }
|
bool getCloneToNewContextOnEmit() const { return CloneToNewContextOnEmit; }
|
||||||
|
@ -83,34 +83,38 @@ Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD,
|
|||||||
|
|
||||||
LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES,
|
LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES,
|
||||||
std::unique_ptr<TargetMachine> TM, DataLayout DL)
|
std::unique_ptr<TargetMachine> TM, DataLayout DL)
|
||||||
: ES(std::move(ES)), Main(this->ES->getMainJITDylib()),
|
: ES(std::move(ES)), Main(this->ES->getMainJITDylib()), DL(std::move(DL)),
|
||||||
DL(std::move(DL)),
|
|
||||||
ObjLinkingLayer(*this->ES,
|
ObjLinkingLayer(*this->ES,
|
||||||
[this](VModuleKey K) { return getMemoryManager(K); }),
|
[this](VModuleKey K) { return getMemoryManager(K); }),
|
||||||
CompileLayer(*this->ES, ObjLinkingLayer, TMOwningSimpleCompiler(std::move(TM))),
|
CompileLayer(*this->ES, ObjLinkingLayer,
|
||||||
|
TMOwningSimpleCompiler(std::move(TM))),
|
||||||
CtorRunner(Main), DtorRunner(Main) {}
|
CtorRunner(Main), DtorRunner(Main) {}
|
||||||
|
|
||||||
LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES,
|
LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES, JITTargetMachineBuilder JTMB,
|
||||||
JITTargetMachineBuilder JTMB, DataLayout DL,
|
DataLayout DL, unsigned NumCompileThreads)
|
||||||
unsigned NumCompileThreads)
|
: ES(std::move(ES)), Main(this->ES->getMainJITDylib()), DL(std::move(DL)),
|
||||||
: ES(std::move(ES)), Main(this->ES->getMainJITDylib()),
|
|
||||||
DL(std::move(DL)),
|
|
||||||
ObjLinkingLayer(*this->ES,
|
ObjLinkingLayer(*this->ES,
|
||||||
[this](VModuleKey K) { return getMemoryManager(K); }),
|
[this](VModuleKey K) { return getMemoryManager(K); }),
|
||||||
CompileLayer(*this->ES, ObjLinkingLayer, MultiThreadedSimpleCompiler(std::move(JTMB))),
|
CompileLayer(*this->ES, ObjLinkingLayer,
|
||||||
|
MultiThreadedSimpleCompiler(std::move(JTMB))),
|
||||||
CtorRunner(Main), DtorRunner(Main) {
|
CtorRunner(Main), DtorRunner(Main) {
|
||||||
assert(NumCompileThreads != 0 &&
|
assert(NumCompileThreads != 0 &&
|
||||||
"Multithreaded LLJIT instance can not be created with 0 threads");
|
"Multithreaded LLJIT instance can not be created with 0 threads");
|
||||||
|
|
||||||
|
// Move modules to new contexts when they're emitted so that we can compile
|
||||||
|
// them in parallel.
|
||||||
|
CompileLayer.setCloneToNewContextOnEmit(true);
|
||||||
|
|
||||||
|
// Create a thread pool to compile on and set the execution session
|
||||||
|
// dispatcher to use the thread pool.
|
||||||
CompileThreads = llvm::make_unique<ThreadPool>(NumCompileThreads);
|
CompileThreads = llvm::make_unique<ThreadPool>(NumCompileThreads);
|
||||||
this->ES->setDispatchMaterialization([this](JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) {
|
this->ES->setDispatchMaterialization(
|
||||||
// FIXME: Switch to move capture once we have c++14.
|
[this](JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) {
|
||||||
auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU));
|
// FIXME: Switch to move capture once we have c++14.
|
||||||
auto Work = [SharedMU, &JD]() {
|
auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU));
|
||||||
SharedMU->doMaterialize(JD);
|
auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
|
||||||
};
|
CompileThreads->async(std::move(Work));
|
||||||
CompileThreads->async(std::move(Work));
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<RuntimeDyld::MemoryManager>
|
std::unique_ptr<RuntimeDyld::MemoryManager>
|
||||||
@ -206,7 +210,9 @@ LLLazyJIT::LLLazyJIT(
|
|||||||
: LLJIT(std::move(ES), std::move(JTMB), std::move(DL), NumCompileThreads),
|
: LLJIT(std::move(ES), std::move(JTMB), std::move(DL), NumCompileThreads),
|
||||||
LCTMgr(std::move(LCTMgr)), TransformLayer(*this->ES, CompileLayer),
|
LCTMgr(std::move(LCTMgr)), TransformLayer(*this->ES, CompileLayer),
|
||||||
CODLayer(*this->ES, TransformLayer, *this->LCTMgr,
|
CODLayer(*this->ES, TransformLayer, *this->LCTMgr,
|
||||||
std::move(ISMBuilder)) {}
|
std::move(ISMBuilder)) {
|
||||||
|
CODLayer.setCloneToNewContextOnEmit(true);
|
||||||
|
}
|
||||||
|
|
||||||
} // End namespace orc.
|
} // End namespace orc.
|
||||||
} // End namespace llvm.
|
} // End namespace llvm.
|
||||||
|
Loading…
Reference in New Issue
Block a user