diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h index a7fa3afc470..020b72c2394 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h @@ -39,14 +39,17 @@ private: MangleAndInterner Mangle; ThreadSafeContext Ctx; + JITDylib &MainJD; + public: KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL) : ObjectLayer(ES, []() { return std::make_unique(); }), CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))), DL(std::move(DL)), Mangle(ES, this->DL), - Ctx(std::make_unique()) { - ES.getMainJITDylib().addGenerator( + Ctx(std::make_unique()), + MainJD(ES.createJITDylib("
")) { + MainJD.addGenerator( cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess( DL.getGlobalPrefix()))); } @@ -69,12 +72,11 @@ public: LLVMContext &getContext() { return *Ctx.getContext(); } Error addModule(std::unique_ptr M) { - return CompileLayer.add(ES.getMainJITDylib(), - ThreadSafeModule(std::move(M), Ctx)); + return CompileLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx)); } Expected lookup(StringRef Name) { - return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name.str())); + return ES.lookup({&MainJD}, Mangle(Name.str())); } }; diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h index e9999efd37a..8037e58ae4f 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h @@ -45,15 +45,17 @@ private: MangleAndInterner Mangle; ThreadSafeContext Ctx; + JITDylib &MainJD; + public: KaleidoscopeJIT(JITTargetMachineBuilder JTMB, DataLayout DL) : ObjectLayer(ES, []() { return std::make_unique(); }), CompileLayer(ES, ObjectLayer, ConcurrentIRCompiler(std::move(JTMB))), - OptimizeLayer(ES, CompileLayer, optimizeModule), - DL(std::move(DL)), Mangle(ES, this->DL), - Ctx(std::make_unique()) { - ES.getMainJITDylib().addGenerator( + OptimizeLayer(ES, CompileLayer, optimizeModule), DL(std::move(DL)), + Mangle(ES, this->DL), Ctx(std::make_unique()), + MainJD(ES.createJITDylib("
")) { + MainJD.addGenerator( cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess( DL.getGlobalPrefix()))); } @@ -76,12 +78,11 @@ public: } Error addModule(std::unique_ptr M) { - return OptimizeLayer.add(ES.getMainJITDylib(), - ThreadSafeModule(std::move(M), Ctx)); + return OptimizeLayer.add(MainJD, ThreadSafeModule(std::move(M), Ctx)); } Expected lookup(StringRef Name) { - return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name.str())); + return ES.lookup({&MainJD}, Mangle(Name.str())); } private: diff --git a/examples/SpeculativeJIT/SpeculativeJIT.cpp b/examples/SpeculativeJIT/SpeculativeJIT.cpp index 5a0ad376bcd..f4cfb7403db 100644 --- a/examples/SpeculativeJIT/SpeculativeJIT.cpp +++ b/examples/SpeculativeJIT/SpeculativeJIT.cpp @@ -76,12 +76,12 @@ public: ExecutionSession &getES() { return *ES; } - Error addModule(JITDylib &JD, ThreadSafeModule TSM) { - return CODLayer.add(JD, std::move(TSM)); + Error addModule(ThreadSafeModule TSM) { + return CODLayer.add(MainJD, std::move(TSM)); } Expected lookup(StringRef UnmangledName) { - return ES->lookup({&ES->getMainJITDylib()}, Mangle(UnmangledName)); + return ES->lookup({&MainJD}, Mangle(UnmangledName)); } ~SpeculativeJIT() { CompileThreads.wait(); } @@ -101,15 +101,15 @@ private: std::unique_ptr LCTMgr, IndirectStubsManagerBuilderFunction ISMBuilder, std::unique_ptr 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("
")), LCTMgr(std::move(LCTMgr)), CompileLayer(*this->ES, ObjLayer, ConcurrentIRCompiler(std::move(JTMB))), S(Imps, *this->ES), SpeculateLayer(*this->ES, CompileLayer, S, Mangle, BlockFreqQuery()), CODLayer(*this->ES, SpeculateLayer, *this->LCTMgr, std::move(ISMBuilder)) { - this->ES->getMainJITDylib().addGenerator( - std::move(ProcessSymbolsGenerator)); + MainJD.addGenerator(std::move(ProcessSymbolsGenerator)); this->CODLayer.setImplMap(&Imps); this->ES->setDispatchMaterialization( @@ -119,9 +119,9 @@ private: auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); }; CompileThreads.async(std::move(Work)); }); - ExitOnErr(S.addSpeculationRuntime(this->ES->getMainJITDylib(), Mangle)); + ExitOnErr(S.addSpeculationRuntime(MainJD, Mangle)); LocalCXXRuntimeOverrides CXXRuntimeoverrides; - ExitOnErr(CXXRuntimeoverrides.enable(this->ES->getMainJITDylib(), Mangle)); + ExitOnErr(CXXRuntimeoverrides.enable(MainJD, Mangle)); } static std::unique_ptr createMemMgr() { @@ -133,6 +133,8 @@ private: MangleAndInterner Mangle{*ES, DL}; ThreadPool CompileThreads{NumThreads}; + JITDylib &MainJD; + Triple TT; std::unique_ptr LCTMgr; IRCompileLayer CompileLayer; @@ -172,8 +174,7 @@ int main(int argc, char *argv[]) { return 1; } - ExitOnErr(SJ->addModule(SJ->getES().getMainJITDylib(), - ThreadSafeModule(std::move(M), std::move(Ctx)))); + ExitOnErr(SJ->addModule(ThreadSafeModule(std::move(M), std::move(Ctx)))); } auto MainSym = ExitOnErr(SJ->lookup("main")); diff --git a/include/llvm/ExecutionEngine/Orc/Core.h b/include/llvm/ExecutionEngine/Orc/Core.h index 8f92b7ab766..2f52edb8de2 100644 --- a/include/llvm/ExecutionEngine/Orc/Core.h +++ b/include/llvm/ExecutionEngine/Orc/Core.h @@ -1079,10 +1079,6 @@ public: return F(); } - /// Get the "main" JITDylib, which is created automatically on construction of - /// the ExecutionSession. - JITDylib &getMainJITDylib(); - /// Return a pointer to the "name" JITDylib. /// Ownership of JITDylib remains within Execution Session JITDylib *getJITDylibByName(StringRef Name); @@ -1092,8 +1088,7 @@ public: /// 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 /// are based on user input. - JITDylib &createJITDylib(std::string Name, - bool AddToMainDylibSearchOrder = true); + JITDylib &createJITDylib(std::string Name); /// Allocate a module key for a new module to add to the JIT. VModuleKey allocateVModule() { diff --git a/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp b/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp index b8e42922027..f26835ff8a0 100644 --- a/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp +++ b/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp @@ -172,8 +172,8 @@ CompileOnDemandLayer::PerDylibResources & CompileOnDemandLayer::getPerDylibResources(JITDylib &TargetD) { auto I = DylibResources.find(&TargetD); if (I == DylibResources.end()) { - auto &ImplD = getExecutionSession().createJITDylib( - TargetD.getName() + ".impl", false); + auto &ImplD = + getExecutionSession().createJITDylib(TargetD.getName() + ".impl"); TargetD.withSearchOrderDo( [&](const JITDylibSearchOrder &TargetSearchOrder) { auto NewSearchOrder = TargetSearchOrder; diff --git a/lib/ExecutionEngine/Orc/Core.cpp b/lib/ExecutionEngine/Orc/Core.cpp index 0814ec1c5f8..63ef889dae4 100644 --- a/lib/ExecutionEngine/Orc/Core.cpp +++ b/lib/ExecutionEngine/Orc/Core.cpp @@ -1854,12 +1854,6 @@ void JITDylib::transferEmittedNodeDependencies( ExecutionSession::ExecutionSession(std::shared_ptr SSP) : SSP(SSP ? std::move(SSP) : std::make_shared()) { - // Construct the main dylib. - JDs.push_back(std::unique_ptr(new JITDylib(*this, "
"))); -} - -JITDylib &ExecutionSession::getMainJITDylib() { - return runSessionLocked([this]() -> JITDylib & { return *JDs.front(); }); } JITDylib *ExecutionSession::getJITDylibByName(StringRef Name) { @@ -1871,14 +1865,11 @@ JITDylib *ExecutionSession::getJITDylibByName(StringRef Name) { }); } -JITDylib &ExecutionSession::createJITDylib(std::string Name, - bool AddToMainDylibSearchOrder) { +JITDylib &ExecutionSession::createJITDylib(std::string Name) { assert(!getJITDylibByName(Name) && "JITDylib with that name already exists"); return runSessionLocked([&, this]() -> JITDylib & { JDs.push_back( std::unique_ptr(new JITDylib(*this, std::move(Name)))); - if (AddToMainDylibSearchOrder) - JDs.front()->addToSearchOrder(*JDs.back()); return *JDs.back(); }); } diff --git a/lib/ExecutionEngine/Orc/LLJIT.cpp b/lib/ExecutionEngine/Orc/LLJIT.cpp index fb5515ca64d..89dad6d61b4 100644 --- a/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -105,7 +105,7 @@ LLJIT::createCompileFunction(LLJITBuilderState &S, LLJIT::LLJIT(LLJITBuilderState &S, Error &Err) : ES(S.ES ? std::move(S.ES) : std::make_unique()), - Main(this->ES->getMainJITDylib()), DL(""), + Main(this->ES->createJITDylib("
")), DL(""), ObjLinkingLayer(createObjectLinkingLayer(S, *ES)), ObjTransformLayer(*this->ES, *ObjLinkingLayer), CtorRunner(Main), DtorRunner(Main) { diff --git a/tools/llvm-jitlink/llvm-jitlink.cpp b/tools/llvm-jitlink/llvm-jitlink.cpp index 0e0953d37b6..f5b841811cb 100644 --- a/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/tools/llvm-jitlink/llvm-jitlink.cpp @@ -397,7 +397,8 @@ static std::unique_ptr createMemoryManager() { } Session::Session(Triple TT) - : MemMgr(createMemoryManager()), ObjLayer(ES, *MemMgr), TT(std::move(TT)) { + : MainJD(ES.createJITDylib("
")), MemMgr(createMemoryManager()), + ObjLayer(ES, *MemMgr), TT(std::move(TT)) { /// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the /// Session. @@ -560,7 +561,7 @@ Error loadProcessSymbols(Session &S) { auto FilterMainEntryPoint = [InternedEntryPointName](SymbolStringPtr Name) { return Name != InternedEntryPointName; }; - S.ES.getMainJITDylib().addGenerator( + S.MainJD.addGenerator( ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess( GlobalPrefix, FilterMainEntryPoint))); @@ -589,10 +590,9 @@ Error loadObjects(Session &S) { LLVM_DEBUG(dbgs() << "Creating JITDylibs...\n"); { // Create a "main" JITLinkDylib. - auto &MainJD = S.ES.getMainJITDylib(); - IdxToJLD[0] = &MainJD; - S.JDSearchOrder.push_back(&MainJD); - LLVM_DEBUG(dbgs() << " 0: " << MainJD.getName() << "\n"); + IdxToJLD[0] = &S.MainJD; + S.JDSearchOrder.push_back(&S.MainJD); + LLVM_DEBUG(dbgs() << " 0: " << S.MainJD.getName() << "\n"); // Add any extra JITLinkDylibs from the command line. std::string JDNamePrefix("lib"); diff --git a/tools/llvm-jitlink/llvm-jitlink.h b/tools/llvm-jitlink/llvm-jitlink.h index f94a50993c1..005f7f211e9 100644 --- a/tools/llvm-jitlink/llvm-jitlink.h +++ b/tools/llvm-jitlink/llvm-jitlink.h @@ -26,6 +26,7 @@ namespace llvm { struct Session { orc::ExecutionSession ES; + orc::JITDylib &MainJD; std::unique_ptr MemMgr; orc::ObjectLinkingLayer ObjLayer; std::vector JDSearchOrder;