diff options
author | Lang Hames <lhames@gmail.com> | 2018-04-02 20:57:56 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2018-04-02 20:57:56 +0000 |
commit | 73bcd8b27c50620d2cb5c23a4de65f75e6a6db4b (patch) | |
tree | 0b95599ac5062e289af5d7b147986e367aff9226 | |
parent | dd9d04ad20e56a20066058a01191f973ab10ec27 (diff) |
[ORC] Create a new SymbolStringPool by default in ExecutionSession constructor.
This makes the common case of constructing an ExecutionSession tidier.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329013 91177308-0d34-0410-b5e6-96231b3b80d8
16 files changed, 29 insertions, 57 deletions
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h index a7eb1db8625..902f5f0403a 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h @@ -38,7 +38,6 @@ namespace orc { class KaleidoscopeJIT { private: - SymbolStringPool SSP; ExecutionSession ES; std::shared_ptr<SymbolResolver> Resolver; std::unique_ptr<TargetMachine> TM; @@ -48,8 +47,7 @@ private: public: KaleidoscopeJIT() - : ES(SSP), - Resolver(createLegacyLookupResolver( + : Resolver(createLegacyLookupResolver( [this](const std::string &Name) -> JITSymbol { if (auto Sym = CompileLayer.findSymbol(Name, false)) return Sym; diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h index 679d72e2050..653e2fd302b 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h @@ -42,7 +42,6 @@ namespace orc { class KaleidoscopeJIT { private: - SymbolStringPool SSP; ExecutionSession ES; std::shared_ptr<SymbolResolver> Resolver; std::unique_ptr<TargetMachine> TM; @@ -57,8 +56,7 @@ private: public: KaleidoscopeJIT() - : ES(SSP), - Resolver(createLegacyLookupResolver( + : Resolver(createLegacyLookupResolver( [this](const std::string &Name) -> JITSymbol { if (auto Sym = OptimizeLayer.findSymbol(Name, false)) return Sym; diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h index cca82293018..fa306c61789 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h @@ -46,7 +46,6 @@ namespace orc { class KaleidoscopeJIT { private: - SymbolStringPool SSP; ExecutionSession ES; std::map<VModuleKey, std::shared_ptr<SymbolResolver>> Resolvers; std::unique_ptr<TargetMachine> TM; @@ -64,7 +63,7 @@ private: public: KaleidoscopeJIT() - : ES(SSP), TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()), + : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()), ObjectLayer(ES, [this](VModuleKey K) { return RTDyldObjectLinkingLayer::Resources{ diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h index 6378dd61e29..c4ddc5094c4 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h @@ -72,7 +72,6 @@ namespace orc { class KaleidoscopeJIT { private: - SymbolStringPool SSP; ExecutionSession ES; std::shared_ptr<SymbolResolver> Resolver; std::unique_ptr<TargetMachine> TM; @@ -90,8 +89,7 @@ private: public: KaleidoscopeJIT() - : ES(SSP), - Resolver(createLegacyLookupResolver( + : Resolver(createLegacyLookupResolver( [this](const std::string &Name) -> JITSymbol { if (auto Sym = IndirectStubsMgr->findStub(Name, false)) return Sym; diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h index acb4090b5eb..d41cce717d4 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h @@ -77,7 +77,6 @@ using MyRemote = remote::OrcRemoteTargetClient; class KaleidoscopeJIT { private: - SymbolStringPool SSP; ExecutionSession ES; std::shared_ptr<SymbolResolver> Resolver; std::unique_ptr<TargetMachine> TM; @@ -96,8 +95,7 @@ private: public: KaleidoscopeJIT(MyRemote &Remote) - : ES(SSP), - Resolver(createLegacyLookupResolver( + : Resolver(createLegacyLookupResolver( [this](const std::string &Name) -> JITSymbol { if (auto Sym = IndirectStubsMgr->findStub(Name, false)) return Sym; diff --git a/examples/Kaleidoscope/include/KaleidoscopeJIT.h b/examples/Kaleidoscope/include/KaleidoscopeJIT.h index 3e2fe42a5d8..79d39515625 100644 --- a/examples/Kaleidoscope/include/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/include/KaleidoscopeJIT.h @@ -44,8 +44,7 @@ public: using CompileLayerT = IRCompileLayer<ObjLayerT, SimpleCompiler>; KaleidoscopeJIT() - : ES(SSP), - Resolver(createLegacyLookupResolver( + : Resolver(createLegacyLookupResolver( [this](const std::string &Name) { return ObjectLayer.findSymbol(Name, true); }, @@ -126,7 +125,6 @@ private: return nullptr; } - SymbolStringPool SSP; ExecutionSession ES; std::shared_ptr<SymbolResolver> Resolver; std::unique_ptr<TargetMachine> TM; diff --git a/include/llvm/ExecutionEngine/Orc/Core.h b/include/llvm/ExecutionEngine/Orc/Core.h index 26fec8b359f..4f530d414a8 100644 --- a/include/llvm/ExecutionEngine/Orc/Core.h +++ b/include/llvm/ExecutionEngine/Orc/Core.h @@ -327,10 +327,11 @@ public: /// @brief Construct an ExecutionEngine. /// /// SymbolStringPools may be shared between ExecutionSessions. - ExecutionSession(SymbolStringPool &SSP); + ExecutionSession(std::shared_ptr<SymbolStringPool> SSP = nullptr) + : SSP(std::move(SSP)) {} /// @brief Returns the SymbolStringPool for this ExecutionSession. - SymbolStringPool &getSymbolStringPool() const { return SSP; } + SymbolStringPool &getSymbolStringPool() const { return *SSP; } /// @brief Set the error reporter function. void setErrorReporter(ErrorReporter ReportError) { @@ -343,17 +344,17 @@ public: void reportError(Error Err) { ReportError(std::move(Err)); } /// @brief Allocate a module key for a new module to add to the JIT. - VModuleKey allocateVModule(); + VModuleKey allocateVModule() { return ++LastKey; } /// @brief Return a module key to the ExecutionSession so that it can be /// re-used. This should only be done once all resources associated //// with the original key have been released. - void releaseVModule(VModuleKey Key); + void releaseVModule(VModuleKey Key) { /* FIXME: Recycle keys */ } public: static void logErrorsToStdErr(Error Err); - SymbolStringPool &SSP; + std::shared_ptr<SymbolStringPool> SSP; VModuleKey LastKey = 0; ErrorReporter ReportError = logErrorsToStdErr; }; diff --git a/lib/ExecutionEngine/Orc/Core.cpp b/lib/ExecutionEngine/Orc/Core.cpp index 46b234faed3..4c1126b23bf 100644 --- a/lib/ExecutionEngine/Orc/Core.cpp +++ b/lib/ExecutionEngine/Orc/Core.cpp @@ -526,14 +526,6 @@ lookup(const std::vector<VSO *> VSOs, SymbolStringPtr Name, return ResultMap.takeError(); } -ExecutionSession::ExecutionSession(SymbolStringPool &SSP) : SSP(SSP) {} - -VModuleKey ExecutionSession::allocateVModule() { return ++LastKey; } - -void ExecutionSession::releaseVModule(VModuleKey VMod) { - // FIXME: Recycle keys. -} - void ExecutionSession::logErrorsToStdErr(Error Err) { logAllUnhandledErrors(std::move(Err), errs(), "JIT session error: "); } diff --git a/lib/ExecutionEngine/Orc/OrcCBindingsStack.h b/lib/ExecutionEngine/Orc/OrcCBindingsStack.h index a9621172d30..a14859ae98f 100644 --- a/lib/ExecutionEngine/Orc/OrcCBindingsStack.h +++ b/lib/ExecutionEngine/Orc/OrcCBindingsStack.h @@ -200,7 +200,7 @@ public: OrcCBindingsStack(TargetMachine &TM, std::unique_ptr<CompileCallbackMgr> CCMgr, IndirectStubsManagerBuilder IndirectStubsMgrBuilder) - : ES(SSP), DL(TM.createDataLayout()), + : DL(TM.createDataLayout()), IndirectStubsMgr(IndirectStubsMgrBuilder()), CCMgr(std::move(CCMgr)), ObjectLayer(ES, [this](orc::VModuleKey K) { @@ -421,7 +421,6 @@ private: logAllUnhandledErrors(std::move(Err), errs(), "ORC error: "); }; - orc::SymbolStringPool SSP; orc::ExecutionSession ES; DataLayout DL; diff --git a/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h b/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h index bdb4d07b132..af87df9ac34 100644 --- a/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h +++ b/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h @@ -225,7 +225,8 @@ public: OrcMCJITReplacement(std::shared_ptr<MCJITMemoryManager> MemMgr, std::shared_ptr<LegacyJITSymbolResolver> ClientResolver, std::unique_ptr<TargetMachine> TM) - : ExecutionEngine(TM->createDataLayout()), ES(SSP), TM(std::move(TM)), + : ExecutionEngine(TM->createDataLayout()), + TM(std::move(TM)), MemMgr( std::make_shared<MCJITReplacementMemMgr>(*this, std::move(MemMgr))), Resolver(std::make_shared<LinkingORCResolver>(*this)), @@ -450,7 +451,6 @@ private: using CompileLayerT = IRCompileLayer<ObjectLayerT, orc::SimpleCompiler>; using LazyEmitLayerT = LazyEmittingLayer<CompileLayerT>; - SymbolStringPool SSP; ExecutionSession ES; std::unique_ptr<TargetMachine> TM; diff --git a/tools/lli/OrcLazyJIT.h b/tools/lli/OrcLazyJIT.h index 42b063fc697..c2b10ffa595 100644 --- a/tools/lli/OrcLazyJIT.h +++ b/tools/lli/OrcLazyJIT.h @@ -60,7 +60,8 @@ public: std::unique_ptr<CompileCallbackMgr> CCMgr, IndirectStubsManagerBuilder IndirectStubsMgrBuilder, bool InlineStubs) - : ES(SSP), TM(std::move(TM)), DL(this->TM->createDataLayout()), + : TM(std::move(TM)), + DL(this->TM->createDataLayout()), CCMgr(std::move(CCMgr)), ObjectLayer(ES, [this](orc::VModuleKey K) { diff --git a/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp b/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp index 4501b53c3c0..833b7621674 100644 --- a/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/CompileOnDemandLayerTest.cpp @@ -59,8 +59,7 @@ TEST(CompileOnDemandLayerTest, FindSymbol) { DummyCallbackManager CallbackMgr; - SymbolStringPool SSP; - ExecutionSession ES(SSP); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); auto GetResolver = [](orc::VModuleKey) -> std::shared_ptr<llvm::orc::SymbolResolver> { diff --git a/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp index f862119c165..878f0a532b8 100644 --- a/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp +++ b/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp @@ -335,8 +335,8 @@ TEST(CoreAPIsTest, TestLookupWithUnthreadedMaterialization) { constexpr JITTargetAddress FakeFooAddr = 0xdeadbeef; JITEvaluatedSymbol FooSym(FakeFooAddr, JITSymbolFlags::Exported); - SymbolStringPool SSP; - auto Foo = SSP.intern("foo"); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); + auto Foo = ES.getSymbolStringPool().intern("foo"); auto MU = llvm::make_unique<SimpleMaterializationUnit>( [=]() { @@ -355,7 +355,6 @@ TEST(CoreAPIsTest, TestLookupWithUnthreadedMaterialization) { cantFail(V.defineLazy(std::move(MU))); - ExecutionSession ES(SSP); auto FooLookupResult = cantFail(lookup({&V}, Foo, MaterializeOnCurrentThread(ES))); @@ -370,8 +369,8 @@ TEST(CoreAPIsTest, TestLookupWithThreadedMaterialization) { constexpr JITTargetAddress FakeFooAddr = 0xdeadbeef; JITEvaluatedSymbol FooSym(FakeFooAddr, JITSymbolFlags::Exported); - SymbolStringPool SSP; - auto Foo = SSP.intern("foo"); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); + auto Foo = ES.getSymbolStringPool().intern("foo"); auto MU = llvm::make_unique<SimpleMaterializationUnit>( [=]() { @@ -390,8 +389,6 @@ TEST(CoreAPIsTest, TestLookupWithThreadedMaterialization) { cantFail(V.defineLazy(std::move(MU))); - ExecutionSession ES(SSP); - std::thread MaterializationThread; auto MaterializeOnNewThread = [&](VSO &V, std::unique_ptr<MaterializationUnit> MU) { diff --git a/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp b/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp index 6c7384a9af5..db29024f470 100644 --- a/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp +++ b/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp @@ -18,9 +18,8 @@ namespace { TEST(LegacyAPIInteropTest, QueryAgainstVSO) { - SymbolStringPool SP; - ExecutionSession ES(SP); - auto Foo = SP.intern("foo"); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); + auto Foo = ES.getSymbolStringPool().intern("foo"); VSO V; SymbolMap Defs; diff --git a/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp b/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp index eacd3e0b0f9..6ad3c19ada9 100644 --- a/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp @@ -179,8 +179,7 @@ private: TEST(ObjectTransformLayerTest, Main) { MockBaseLayer M; - SymbolStringPool SSP; - ExecutionSession ES(SSP); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); // Create one object transform layer using a transform (as a functor) // that allocates new objects, and deals in unique pointers. diff --git a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp index f52ee6b967e..650fd524812 100644 --- a/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp +++ b/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp @@ -67,8 +67,7 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) { bool DebugSectionSeen = false; auto MM = std::make_shared<MemoryManagerWrapper>(DebugSectionSeen); - SymbolStringPool SSP; - ExecutionSession ES(SSP); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); RTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey) { return RTDyldObjectLinkingLayer::Resources{ @@ -124,8 +123,7 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) { if (!SupportsJIT) return; - SymbolStringPool SSP; - ExecutionSession ES(SSP); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); auto MM = std::make_shared<SectionMemoryManagerWrapper>(); @@ -209,8 +207,7 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) { if (!SupportsJIT) return; - SymbolStringPool SSP; - ExecutionSession ES(SSP); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); auto MM = std::make_shared<SectionMemoryManagerWrapper>(); @@ -271,8 +268,7 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) { } TEST_F(RTDyldObjectLinkingLayerExecutionTest, TestNotifyLoadedSignature) { - SymbolStringPool SSP; - ExecutionSession ES(SSP); + ExecutionSession ES(std::make_shared<SymbolStringPool>()); RTDyldObjectLinkingLayer ObjLayer( ES, [](VModuleKey) { |