mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[ORC] Remove the automagic Main JITDylib fram ExecutionSession.
This patch removes the magic "main" JITDylib from ExecutionEngine. The main JITDylib was created automatically at ExecutionSession construction time, and all subsequently created JITDylibs were added to the main JITDylib's links-against list by default. This saves a couple of lines of boilerplate for simple JIT setups, but this isn't worth introducing magical behavior for. ORCv2 clients should now construct their own main JITDylib using ExecutionSession::createJITDylib and set up its linkages manually using JITDylib::setSearchOrder (or related methods in JITDylib).
This commit is contained in:
parent
63adb49233
commit
8c3d4519e1
@ -39,14 +39,17 @@ private:
|
|||||||
MangleAndInterner Mangle;
|
MangleAndInterner Mangle;
|
||||||
ThreadSafeContext Ctx;
|
ThreadSafeContext Ctx;
|
||||||
|
|
||||||
|
JITDylib &MainJD;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
|
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
|
||||||
: ObjectLayer(ES,
|
: ObjectLayer(ES,
|
||||||
[]() { return std::make_unique<SectionMemoryManager>(); }),
|
[]() { return std::make_unique<SectionMemoryManager>(); }),
|
||||||
CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))),
|
CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))),
|
||||||
DL(std::move(DL)), Mangle(ES, this->DL),
|
DL(std::move(DL)), Mangle(ES, this->DL),
|
||||||
Ctx(std::make_unique<LLVMContext>()) {
|
Ctx(std::make_unique<LLVMContext>()),
|
||||||
ES.getMainJITDylib().addGenerator(
|
MainJD(ES.createJITDylib("<main>")) {
|
||||||
|
MainJD.addGenerator(
|
||||||
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
|
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
|
||||||
DL.getGlobalPrefix())));
|
DL.getGlobalPrefix())));
|
||||||
}
|
}
|
||||||
@ -69,12 +72,11 @@ public:
|
|||||||
LLVMContext &getContext() { return *Ctx.getContext(); }
|
LLVMContext &getContext() { return *Ctx.getContext(); }
|
||||||
|
|
||||||
Error addModule(std::unique_ptr<Module> M) {
|
Error addModule(std::unique_ptr<Module> M) {
|
||||||
return CompileLayer.add(ES.getMainJITDylib(),
|
return CompileLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx));
|
||||||
ThreadSafeModule(std::move(M), Ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
|
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
|
||||||
return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name.str()));
|
return ES.lookup({&MainJD}, Mangle(Name.str()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,15 +45,17 @@ private:
|
|||||||
MangleAndInterner Mangle;
|
MangleAndInterner Mangle;
|
||||||
ThreadSafeContext Ctx;
|
ThreadSafeContext Ctx;
|
||||||
|
|
||||||
|
JITDylib &MainJD;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
|
KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL)
|
||||||
: ObjectLayer(ES,
|
: ObjectLayer(ES,
|
||||||
[]() { return std::make_unique<SectionMemoryManager>(); }),
|
[]() { return std::make_unique<SectionMemoryManager>(); }),
|
||||||
CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))),
|
CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))),
|
||||||
OptimizeLayer(ES, CompileLayer, optimizeModule),
|
OptimizeLayer(ES, CompileLayer, optimizeModule), DL(std::move(DL)),
|
||||||
DL(std::move(DL)), Mangle(ES, this->DL),
|
Mangle(ES, this->DL), Ctx(std::make_unique<LLVMContext>()),
|
||||||
Ctx(std::make_unique<LLVMContext>()) {
|
MainJD(ES.createJITDylib("<main>")) {
|
||||||
ES.getMainJITDylib().addGenerator(
|
MainJD.addGenerator(
|
||||||
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
|
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
|
||||||
DL.getGlobalPrefix())));
|
DL.getGlobalPrefix())));
|
||||||
}
|
}
|
||||||
@ -76,12 +78,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error addModule(std::unique_ptr<Module> M) {
|
Error addModule(std::unique_ptr<Module> M) {
|
||||||
return OptimizeLayer.add(ES.getMainJITDylib(),
|
return OptimizeLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx));
|
||||||
ThreadSafeModule(std::move(M), Ctx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
|
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
|
||||||
return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name.str()));
|
return ES.lookup({&MainJD}, Mangle(Name.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -76,12 +76,12 @@ public:
|
|||||||
|
|
||||||
ExecutionSession &getES() { return *ES; }
|
ExecutionSession &getES() { return *ES; }
|
||||||
|
|
||||||
Error addModule(JITDylib &JD, ThreadSafeModule TSM) {
|
Error addModule(ThreadSafeModule TSM) {
|
||||||
return CODLayer.add(JD, std::move(TSM));
|
return CODLayer.add(MainJD, std::move(TSM));
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<JITEvaluatedSymbol> lookup(StringRef UnmangledName) {
|
Expected<JITEvaluatedSymbol> lookup(StringRef UnmangledName) {
|
||||||
return ES->lookup({&ES->getMainJITDylib()}, Mangle(UnmangledName));
|
return ES->lookup({&MainJD}, Mangle(UnmangledName));
|
||||||
}
|
}
|
||||||
|
|
||||||
~SpeculativeJIT() { CompileThreads.wait(); }
|
~SpeculativeJIT() { CompileThreads.wait(); }
|
||||||
@ -101,15 +101,15 @@ private:
|
|||||||
std::unique_ptr<LazyCallThroughManager> LCTMgr,
|
std::unique_ptr<LazyCallThroughManager> LCTMgr,
|
||||||
IndirectStubsManagerBuilderFunction ISMBuilder,
|
IndirectStubsManagerBuilderFunction ISMBuilder,
|
||||||
std::unique_ptr<DynamicLibrarySearchGenerator> ProcessSymbolsGenerator)
|
std::unique_ptr<DynamicLibrarySearchGenerator> ProcessSymbolsGenerator)
|
||||||
: ES(std::move(ES)), DL(std::move(DL)), LCTMgr(std::move(LCTMgr)),
|
: ES(std::move(ES)), DL(std::move(DL)),
|
||||||
|
MainJD(this->ES->createJITDylib("<main>")), LCTMgr(std::move(LCTMgr)),
|
||||||
CompileLayer(*this->ES, ObjLayer,
|
CompileLayer(*this->ES, ObjLayer,
|
||||||
ConcurrentIRCompiler(std::move(JTMB))),
|
ConcurrentIRCompiler(std::move(JTMB))),
|
||||||
S(Imps, *this->ES),
|
S(Imps, *this->ES),
|
||||||
SpeculateLayer(*this->ES, CompileLayer, S, Mangle, BlockFreqQuery()),
|
SpeculateLayer(*this->ES, CompileLayer, S, Mangle, BlockFreqQuery()),
|
||||||
CODLayer(*this->ES, SpeculateLayer, *this->LCTMgr,
|
CODLayer(*this->ES, SpeculateLayer, *this->LCTMgr,
|
||||||
std::move(ISMBuilder)) {
|
std::move(ISMBuilder)) {
|
||||||
this->ES->getMainJITDylib().addGenerator(
|
MainJD.addGenerator(std::move(ProcessSymbolsGenerator));
|
||||||
std::move(ProcessSymbolsGenerator));
|
|
||||||
this->CODLayer.setImplMap(&Imps);
|
this->CODLayer.setImplMap(&Imps);
|
||||||
this->ES->setDispatchMaterialization(
|
this->ES->setDispatchMaterialization(
|
||||||
|
|
||||||
@ -119,9 +119,9 @@ private:
|
|||||||
auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
|
auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
|
||||||
CompileThreads.async(std::move(Work));
|
CompileThreads.async(std::move(Work));
|
||||||
});
|
});
|
||||||
ExitOnErr(S.addSpeculationRuntime(this->ES->getMainJITDylib(), Mangle));
|
ExitOnErr(S.addSpeculationRuntime(MainJD, Mangle));
|
||||||
LocalCXXRuntimeOverrides CXXRuntimeoverrides;
|
LocalCXXRuntimeOverrides CXXRuntimeoverrides;
|
||||||
ExitOnErr(CXXRuntimeoverrides.enable(this->ES->getMainJITDylib(), Mangle));
|
ExitOnErr(CXXRuntimeoverrides.enable(MainJD, Mangle));
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<SectionMemoryManager> createMemMgr() {
|
static std::unique_ptr<SectionMemoryManager> createMemMgr() {
|
||||||
@ -133,6 +133,8 @@ private:
|
|||||||
MangleAndInterner Mangle{*ES, DL};
|
MangleAndInterner Mangle{*ES, DL};
|
||||||
ThreadPool CompileThreads{NumThreads};
|
ThreadPool CompileThreads{NumThreads};
|
||||||
|
|
||||||
|
JITDylib &MainJD;
|
||||||
|
|
||||||
Triple TT;
|
Triple TT;
|
||||||
std::unique_ptr<LazyCallThroughManager> LCTMgr;
|
std::unique_ptr<LazyCallThroughManager> LCTMgr;
|
||||||
IRCompileLayer CompileLayer;
|
IRCompileLayer CompileLayer;
|
||||||
@ -172,8 +174,7 @@ int main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExitOnErr(SJ->addModule(SJ->getES().getMainJITDylib(),
|
ExitOnErr(SJ->addModule(ThreadSafeModule(std::move(M), std::move(Ctx))));
|
||||||
ThreadSafeModule(std::move(M), std::move(Ctx))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto MainSym = ExitOnErr(SJ->lookup("main"));
|
auto MainSym = ExitOnErr(SJ->lookup("main"));
|
||||||
|
@ -1079,10 +1079,6 @@ public:
|
|||||||
return F();
|
return F();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the "main" JITDylib, which is created automatically on construction of
|
|
||||||
/// the ExecutionSession.
|
|
||||||
JITDylib &getMainJITDylib();
|
|
||||||
|
|
||||||
/// Return a pointer to the "name" JITDylib.
|
/// Return a pointer to the "name" JITDylib.
|
||||||
/// Ownership of JITDylib remains within Execution Session
|
/// Ownership of JITDylib remains within Execution Session
|
||||||
JITDylib *getJITDylibByName(StringRef Name);
|
JITDylib *getJITDylibByName(StringRef Name);
|
||||||
@ -1092,8 +1088,7 @@ public:
|
|||||||
/// The JITDylib Name is required to be unique. Clients should verify that
|
/// The JITDylib Name is required to be unique. Clients should verify that
|
||||||
/// names are not being re-used (e.g. by calling getJITDylibByName) if names
|
/// names are not being re-used (e.g. by calling getJITDylibByName) if names
|
||||||
/// are based on user input.
|
/// are based on user input.
|
||||||
JITDylib &createJITDylib(std::string Name,
|
JITDylib &createJITDylib(std::string Name);
|
||||||
bool AddToMainDylibSearchOrder = true);
|
|
||||||
|
|
||||||
/// Allocate a module key for a new module to add to the JIT.
|
/// Allocate a module key for a new module to add to the JIT.
|
||||||
VModuleKey allocateVModule() {
|
VModuleKey allocateVModule() {
|
||||||
|
@ -172,8 +172,8 @@ CompileOnDemandLayer::PerDylibResources &
|
|||||||
CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) {
|
CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) {
|
||||||
auto I = DylibResources.find(&TargetD);
|
auto I = DylibResources.find(&TargetD);
|
||||||
if (I == DylibResources.end()) {
|
if (I == DylibResources.end()) {
|
||||||
auto &ImplD = getExecutionSession().createJITDylib(
|
auto &ImplD =
|
||||||
TargetD.getName() + ".impl", false);
|
getExecutionSession().createJITDylib(TargetD.getName() + ".impl");
|
||||||
TargetD.withSearchOrderDo(
|
TargetD.withSearchOrderDo(
|
||||||
[&](const JITDylibSearchOrder &TargetSearchOrder) {
|
[&](const JITDylibSearchOrder &TargetSearchOrder) {
|
||||||
auto NewSearchOrder = TargetSearchOrder;
|
auto NewSearchOrder = TargetSearchOrder;
|
||||||
|
@ -1854,12 +1854,6 @@ void JITDylib::transferEmittedNodeDependencies(
|
|||||||
|
|
||||||
ExecutionSession::ExecutionSession(std::shared_ptr<SymbolStringPool> SSP)
|
ExecutionSession::ExecutionSession(std::shared_ptr<SymbolStringPool> SSP)
|
||||||
: SSP(SSP ? std::move(SSP) : std::make_shared<SymbolStringPool>()) {
|
: SSP(SSP ? std::move(SSP) : std::make_shared<SymbolStringPool>()) {
|
||||||
// Construct the main dylib.
|
|
||||||
JDs.push_back(std::unique_ptr<JITDylib>(new JITDylib(*this, "<main>")));
|
|
||||||
}
|
|
||||||
|
|
||||||
JITDylib &ExecutionSession::getMainJITDylib() {
|
|
||||||
return runSessionLocked([this]() -> JITDylib & { return *JDs.front(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JITDylib *ExecutionSession::getJITDylibByName(StringRef Name) {
|
JITDylib *ExecutionSession::getJITDylibByName(StringRef Name) {
|
||||||
@ -1871,14 +1865,11 @@ JITDylib *ExecutionSession::getJITDylibByName(StringRef Name) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
JITDylib &ExecutionSession::createJITDylib(std::string Name,
|
JITDylib &ExecutionSession::createJITDylib(std::string Name) {
|
||||||
bool AddToMainDylibSearchOrder) {
|
|
||||||
assert(!getJITDylibByName(Name) && "JITDylib with that name already exists");
|
assert(!getJITDylibByName(Name) && "JITDylib with that name already exists");
|
||||||
return runSessionLocked([&, this]() -> JITDylib & {
|
return runSessionLocked([&, this]() -> JITDylib & {
|
||||||
JDs.push_back(
|
JDs.push_back(
|
||||||
std::unique_ptr<JITDylib>(new JITDylib(*this, std::move(Name))));
|
std::unique_ptr<JITDylib>(new JITDylib(*this, std::move(Name))));
|
||||||
if (AddToMainDylibSearchOrder)
|
|
||||||
JDs.front()->addToSearchOrder(*JDs.back());
|
|
||||||
return *JDs.back();
|
return *JDs.back();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ LLJIT::createCompileFunction(LLJITBuilderState &S,
|
|||||||
|
|
||||||
LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
|
LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
|
||||||
: ES(S.ES ? std::move(S.ES) : std::make_unique<ExecutionSession>()),
|
: ES(S.ES ? std::move(S.ES) : std::make_unique<ExecutionSession>()),
|
||||||
Main(this->ES->getMainJITDylib()), DL(""),
|
Main(this->ES->createJITDylib("<main>")), DL(""),
|
||||||
ObjLinkingLayer(createObjectLinkingLayer(S, *ES)),
|
ObjLinkingLayer(createObjectLinkingLayer(S, *ES)),
|
||||||
ObjTransformLayer(*this->ES, *ObjLinkingLayer), CtorRunner(Main),
|
ObjTransformLayer(*this->ES, *ObjLinkingLayer), CtorRunner(Main),
|
||||||
DtorRunner(Main) {
|
DtorRunner(Main) {
|
||||||
|
@ -397,7 +397,8 @@ static std::unique_ptr<jitlink::JITLinkMemoryManager> createMemoryManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Session::Session(Triple TT)
|
Session::Session(Triple TT)
|
||||||
: MemMgr(createMemoryManager()), ObjLayer(ES, *MemMgr), TT(std::move(TT)) {
|
: MainJD(ES.createJITDylib("<main>")), MemMgr(createMemoryManager()),
|
||||||
|
ObjLayer(ES, *MemMgr), TT(std::move(TT)) {
|
||||||
|
|
||||||
/// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the
|
/// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the
|
||||||
/// Session.
|
/// Session.
|
||||||
@ -560,7 +561,7 @@ Error loadProcessSymbols(Session &S) {
|
|||||||
auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) {
|
auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) {
|
||||||
return Name != InternedEntryPointName;
|
return Name != InternedEntryPointName;
|
||||||
};
|
};
|
||||||
S.ES.getMainJITDylib().addGenerator(
|
S.MainJD.addGenerator(
|
||||||
ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
|
ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
|
||||||
GlobalPrefix, FilterMainEntryPoint)));
|
GlobalPrefix, FilterMainEntryPoint)));
|
||||||
|
|
||||||
@ -589,10 +590,9 @@ Error loadObjects(Session &S) {
|
|||||||
LLVM_DEBUG(dbgs() << "Creating JITDylibs...\n");
|
LLVM_DEBUG(dbgs() << "Creating JITDylibs...\n");
|
||||||
{
|
{
|
||||||
// Create a "main" JITLinkDylib.
|
// Create a "main" JITLinkDylib.
|
||||||
auto &MainJD = S.ES.getMainJITDylib();
|
IdxToJLD[0] = &S.MainJD;
|
||||||
IdxToJLD[0] = &MainJD;
|
S.JDSearchOrder.push_back(&S.MainJD);
|
||||||
S.JDSearchOrder.push_back(&MainJD);
|
LLVM_DEBUG(dbgs() << " 0: " << S.MainJD.getName() << "\n");
|
||||||
LLVM_DEBUG(dbgs() << " 0: " << MainJD.getName() << "\n");
|
|
||||||
|
|
||||||
// Add any extra JITLinkDylibs from the command line.
|
// Add any extra JITLinkDylibs from the command line.
|
||||||
std::string JDNamePrefix("lib");
|
std::string JDNamePrefix("lib");
|
||||||
|
@ -26,6 +26,7 @@ namespace llvm {
|
|||||||
|
|
||||||
struct Session {
|
struct Session {
|
||||||
orc::ExecutionSession ES;
|
orc::ExecutionSession ES;
|
||||||
|
orc::JITDylib &MainJD;
|
||||||
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr;
|
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr;
|
||||||
orc::ObjectLinkingLayer ObjLayer;
|
orc::ObjectLinkingLayer ObjLayer;
|
||||||
std::vector<orc::JITDylib *> JDSearchOrder;
|
std::vector<orc::JITDylib *> JDSearchOrder;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user