[llvm] r325180 - [ORC] Consolidate RTDyldObjectLinkingLayer GetMemMgr and GetResolver into a
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 14 14:13:03 PST 2018
Author: lhames
Date: Wed Feb 14 14:13:02 2018
New Revision: 325180
URL: http://llvm.org/viewvc/llvm-project?rev=325180&view=rev
Log:
[ORC] Consolidate RTDyldObjectLinkingLayer GetMemMgr and GetResolver into a
unified GetResources callback.
Having a single 'GetResources' callback will simplify adding new resources in
the future.
Modified:
llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
llvm/trunk/examples/Kaleidoscope/include/KaleidoscopeJIT.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
llvm/trunk/tools/lli/OrcLazyJIT.h
llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp
llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
Modified: llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h (original)
+++ llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h Wed Feb 14 14:13:02 2018
@@ -47,7 +47,6 @@ private:
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
public:
-
KaleidoscopeJIT()
: ES(SSP),
Resolver(createLegacyLookupResolver(
@@ -63,10 +62,11 @@ public:
},
[](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer(
- ES,
- [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
- [this](VModuleKey K) { return Resolver; }),
+ ObjectLayer(ES,
+ [this](VModuleKey) {
+ return RTDyldObjectLinkingLayer::Resources{
+ std::make_shared<SectionMemoryManager>(), Resolver};
+ }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}
Modified: llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h (original)
+++ llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h Wed Feb 14 14:13:02 2018
@@ -56,7 +56,6 @@ private:
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
public:
-
KaleidoscopeJIT()
: ES(SSP),
Resolver(createLegacyLookupResolver(
@@ -72,10 +71,11 @@ public:
},
[](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer(
- ES,
- [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
- [this](VModuleKey K) { return Resolver; }),
+ ObjectLayer(ES,
+ [this](VModuleKey) {
+ return RTDyldObjectLinkingLayer::Resources{
+ std::make_shared<SectionMemoryManager>(), Resolver};
+ }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer, [this](std::shared_ptr<Module> M) {
return optimizeModule(std::move(M));
Modified: llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h (original)
+++ llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h Wed Feb 14 14:13:02 2018
@@ -63,13 +63,14 @@ private:
CompileOnDemandLayer<decltype(OptimizeLayer)> CODLayer;
public:
-
KaleidoscopeJIT()
: ES(SSP), TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer(
- ES,
- [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
- [&](orc::VModuleKey K) { return Resolvers[K]; }),
+ ObjectLayer(ES,
+ [this](VModuleKey K) {
+ return RTDyldObjectLinkingLayer::Resources{
+ std::make_shared<SectionMemoryManager>(),
+ Resolvers[K]};
+ }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
Modified: llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h (original)
+++ llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h Wed Feb 14 14:13:02 2018
@@ -89,7 +89,6 @@ private:
std::unique_ptr<IndirectStubsManager> IndirectStubsMgr;
public:
-
KaleidoscopeJIT()
: ES(SSP),
Resolver(createLegacyLookupResolver(
@@ -107,10 +106,11 @@ public:
},
[](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer(
- ES,
- [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
- [&](VModuleKey K) { return Resolver; }),
+ ObjectLayer(ES,
+ [this](VModuleKey K) {
+ return RTDyldObjectLinkingLayer::Resources{
+ std::make_shared<SectionMemoryManager>(), Resolver};
+ }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
Modified: llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h (original)
+++ llvm/trunk/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h Wed Feb 14 14:13:02 2018
@@ -95,7 +95,6 @@ private:
MyRemote &Remote;
public:
-
KaleidoscopeJIT(MyRemote &Remote)
: ES(SSP),
Resolver(createLegacyLookupResolver(
@@ -115,10 +114,11 @@ public:
"", SmallVector<std::string, 0>())),
DL(TM->createDataLayout()),
ObjectLayer(ES,
- [&Remote](VModuleKey) {
- return cantFail(Remote.createRemoteMemoryManager());
- },
- [this](VModuleKey) { return Resolver; }),
+ [this](VModuleKey K) {
+ return RTDyldObjectLinkingLayer::Resources{
+ cantFail(this->Remote.createRemoteMemoryManager()),
+ Resolver};
+ }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
Modified: llvm/trunk/examples/Kaleidoscope/include/KaleidoscopeJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/include/KaleidoscopeJIT.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/include/KaleidoscopeJIT.h (original)
+++ llvm/trunk/examples/Kaleidoscope/include/KaleidoscopeJIT.h Wed Feb 14 14:13:02 2018
@@ -51,10 +51,11 @@ public:
},
[](Error Err) { cantFail(std::move(Err), "lookupFlags failed"); })),
TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
- ObjectLayer(
- ES,
- [](VModuleKey) { return std::make_shared<SectionMemoryManager>(); },
- [this](VModuleKey) { return Resolver; }),
+ ObjectLayer(ES,
+ [this](VModuleKey) {
+ return ObjLayerT::Resources{
+ std::make_shared<SectionMemoryManager>(), Resolver};
+ }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h Wed Feb 14 14:13:02 2018
@@ -213,23 +213,20 @@ private:
}
public:
+ struct Resources {
+ std::shared_ptr<RuntimeDyld::MemoryManager> MemMgr;
+ std::shared_ptr<SymbolResolver> Resolver;
+ };
- /// @brief Functor for creating memory managers.
- using MemoryManagerGetter =
- std::function<std::shared_ptr<RuntimeDyld::MemoryManager>(VModuleKey)>;
-
- using ResolverGetter =
- std::function<std::shared_ptr<SymbolResolver>(VModuleKey)>;
+ using ResourcesGetter = std::function<Resources(VModuleKey)>;
/// @brief Construct an ObjectLinkingLayer with the given NotifyLoaded,
/// and NotifyFinalized functors.
RTDyldObjectLinkingLayer(
- ExecutionSession &ES, MemoryManagerGetter GetMemMgr,
- ResolverGetter GetResolver,
+ ExecutionSession &ES, ResourcesGetter GetResources,
NotifyLoadedFtor NotifyLoaded = NotifyLoadedFtor(),
NotifyFinalizedFtor NotifyFinalized = NotifyFinalizedFtor())
- : ES(ES), GetMemMgr(std::move(GetMemMgr)),
- GetResolver(std::move(GetResolver)),
+ : ES(ES), GetResources(std::move(GetResources)),
NotifyLoaded(std::move(NotifyLoaded)),
NotifyFinalized(std::move(NotifyFinalized)), ProcessAllSections(false) {
}
@@ -270,9 +267,11 @@ public:
assert(!LinkedObjects.count(K) && "VModuleKey already in use");
- LinkedObjects[K] =
- createLinkedObject(ES, std::move(Obj), GetMemMgr(K), GetResolver(K),
- std::move(Finalizer), ProcessAllSections);
+ auto R = GetResources(K);
+
+ LinkedObjects[K] = createLinkedObject(
+ ES, std::move(Obj), std::move(R.MemMgr), std::move(R.Resolver),
+ std::move(Finalizer), ProcessAllSections);
return Error::success();
}
@@ -339,8 +338,7 @@ private:
ExecutionSession &ES;
std::map<VModuleKey, std::unique_ptr<LinkedObject>> LinkedObjects;
- MemoryManagerGetter GetMemMgr;
- ResolverGetter GetResolver;
+ ResourcesGetter GetResources;
NotifyLoadedFtor NotifyLoaded;
NotifyFinalizedFtor NotifyFinalized;
bool ProcessAllSections = false;
Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcCBindingsStack.h Wed Feb 14 14:13:02 2018
@@ -205,16 +205,14 @@ public:
: ES(SSP), DL(TM.createDataLayout()),
IndirectStubsMgr(IndirectStubsMgrBuilder()), CCMgr(std::move(CCMgr)),
ObjectLayer(ES,
- [](orc::VModuleKey K) {
- return std::make_shared<SectionMemoryManager>();
- },
[this](orc::VModuleKey K) {
auto ResolverI = Resolvers.find(K);
assert(ResolverI != Resolvers.end() &&
"No resolver for module K");
auto Resolver = std::move(ResolverI->second);
Resolvers.erase(ResolverI);
- return Resolver;
+ return ObjLayerT::Resources{
+ std::make_shared<SectionMemoryManager>(), Resolver};
}),
CompileLayer(ObjectLayer, orc::SimpleCompiler(TM)),
CODLayer(ES, CompileLayer,
Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h Wed Feb 14 14:13:02 2018
@@ -229,9 +229,12 @@ public:
Resolver(std::make_shared<LinkingORCResolver>(*this)),
ClientResolver(std::move(ClientResolver)), NotifyObjectLoaded(*this),
NotifyFinalized(*this),
- ObjectLayer(ES, [this](VModuleKey K) { return this->MemMgr; },
- [this](VModuleKey K) { return this->Resolver; },
- NotifyObjectLoaded, NotifyFinalized),
+ ObjectLayer(
+ ES,
+ [this](VModuleKey K) {
+ return ObjectLayerT::Resources{this->MemMgr, this->Resolver};
+ },
+ NotifyObjectLoaded, NotifyFinalized),
CompileLayer(ObjectLayer, SimpleCompiler(*this->TM)),
LazyEmitLayer(CompileLayer) {}
Modified: llvm/trunk/tools/lli/OrcLazyJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/OrcLazyJIT.h?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/tools/lli/OrcLazyJIT.h (original)
+++ llvm/trunk/tools/lli/OrcLazyJIT.h Wed Feb 14 14:13:02 2018
@@ -63,16 +63,15 @@ public:
: ES(SSP), TM(std::move(TM)), DL(this->TM->createDataLayout()),
CCMgr(std::move(CCMgr)),
ObjectLayer(ES,
- [](orc::VModuleKey) {
- return std::make_shared<SectionMemoryManager>();
- },
- [&](orc::VModuleKey K) {
+ [this](orc::VModuleKey K) {
auto ResolverI = Resolvers.find(K);
assert(ResolverI != Resolvers.end() &&
"Missing resolver for module K");
auto Resolver = std::move(ResolverI->second);
Resolvers.erase(ResolverI);
- return Resolver;
+ return ObjLayerT::Resources{
+ std::make_shared<SectionMemoryManager>(),
+ std::move(Resolver)};
}),
CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
IRDumpLayer(CompileLayer, createDebugDumper()),
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/ObjectTransformLayerTest.cpp Wed Feb 14 14:13:02 2018
@@ -11,6 +11,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
+#include "llvm/ExecutionEngine/Orc/NullResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/Object/ObjectFile.h"
@@ -281,12 +282,11 @@ TEST(ObjectTransformLayerTest, Main) {
};
// Construct the jit layers.
- RTDyldObjectLinkingLayer BaseLayer(
- ES,
- [](VModuleKey) { return std::make_shared<llvm::SectionMemoryManager>(); },
- [](VModuleKey) -> std::shared_ptr<SymbolResolver> {
- llvm_unreachable("Should never be called");
- });
+ RTDyldObjectLinkingLayer BaseLayer(ES, [](VModuleKey) {
+ return RTDyldObjectLinkingLayer::Resources{
+ std::make_shared<llvm::SectionMemoryManager>(),
+ std::make_shared<NullResolver>()};
+ });
auto IdentityTransform =
[](std::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile>>
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp?rev=325180&r1=325179&r2=325180&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp Wed Feb 14 14:13:02 2018
@@ -70,9 +70,10 @@ TEST(RTDyldObjectLinkingLayerTest, TestS
SymbolStringPool SSP;
ExecutionSession ES(SSP);
- RTDyldObjectLinkingLayer ObjLayer(
- ES, [&MM](VModuleKey) { return MM; },
- [](orc::VModuleKey) { return std::make_shared<NullResolver>(); });
+ RTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey) {
+ return RTDyldObjectLinkingLayer::Resources{
+ MM, std::make_shared<NullResolver>()};
+ });
LLVMContext Context;
auto M = llvm::make_unique<Module>("", Context);
@@ -131,15 +132,13 @@ TEST_F(RTDyldObjectLinkingLayerExecution
std::map<orc::VModuleKey, std::shared_ptr<orc::SymbolResolver>> Resolvers;
- RTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey) { return MM; },
- [&](VModuleKey K) {
- auto I = Resolvers.find(K);
- assert(I != Resolvers.end() &&
- "Missing resolver");
- auto R = std::move(I->second);
- Resolvers.erase(I);
- return R;
- });
+ RTDyldObjectLinkingLayer ObjLayer(ES, [&](VModuleKey K) {
+ auto I = Resolvers.find(K);
+ assert(I != Resolvers.end() && "Missing resolver");
+ auto R = std::move(I->second);
+ Resolvers.erase(I);
+ return RTDyldObjectLinkingLayer::Resources{MM, std::move(R)};
+ });
SimpleCompiler Compile(*TM);
// Create a pair of modules that will trigger recursive finalization:
@@ -220,9 +219,10 @@ TEST_F(RTDyldObjectLinkingLayerExecution
auto MM = std::make_shared<SectionMemoryManagerWrapper>();
- RTDyldObjectLinkingLayer ObjLayer(
- ES, [&MM](VModuleKey) { return MM; },
- [](VModuleKey) { return std::make_shared<NullResolver>(); });
+ RTDyldObjectLinkingLayer ObjLayer(ES, [&MM](VModuleKey K) {
+ return RTDyldObjectLinkingLayer::Resources{
+ MM, std::make_shared<NullResolver>()};
+ });
SimpleCompiler Compile(*TM);
// Create a pair of unrelated modules:
@@ -283,8 +283,11 @@ TEST_F(RTDyldObjectLinkingLayerExecution
SymbolStringPool SSP;
ExecutionSession ES(SSP);
RTDyldObjectLinkingLayer ObjLayer(
- ES, [](VModuleKey) { return nullptr; },
- [](VModuleKey) { return std::make_shared<NullResolver>(); },
+ ES,
+ [](VModuleKey) {
+ return RTDyldObjectLinkingLayer::Resources{
+ nullptr, std::make_shared<NullResolver>()};
+ },
[](VModuleKey, const RTDyldObjectLinkingLayer::ObjectPtr &obj,
const RuntimeDyld::LoadedObjectInfo &info) {});
}
More information about the llvm-commits
mailing list