[ORC] Make ObjectLinkingLayer own its jitlink::MemoryManager.

This relieves ObjectLinkingLayer clients of the responsibility of holding the
memory manager. This makes it easier to select between RTDyldObjectLinkingLayer
(which already owned its memory manager factory) and ObjectLinkingLayer at
runtime as clients aren't required to hold a jitlink::MemoryManager field just
in case ObjectLinkingLayer is selected.
This commit is contained in:
Lang Hames 2019-12-15 17:23:36 -08:00
parent 1ea5ce6335
commit c0143f37da
4 changed files with 8 additions and 9 deletions

View File

@ -79,7 +79,7 @@ public:
/// Construct an ObjectLinkingLayer with the given NotifyLoaded, /// Construct an ObjectLinkingLayer with the given NotifyLoaded,
/// and NotifyEmitted functors. /// and NotifyEmitted functors.
ObjectLinkingLayer(ExecutionSession &ES, ObjectLinkingLayer(ExecutionSession &ES,
jitlink::JITLinkMemoryManager &MemMgr); std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);
/// Destruct an ObjectLinkingLayer. /// Destruct an ObjectLinkingLayer.
~ObjectLinkingLayer(); ~ObjectLinkingLayer();
@ -145,7 +145,7 @@ private:
Error removeAllModules(); Error removeAllModules();
mutable std::mutex LayerMutex; mutable std::mutex LayerMutex;
jitlink::JITLinkMemoryManager &MemMgr; std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr;
bool OverrideObjectFlags = false; bool OverrideObjectFlags = false;
bool AutoClaimObjectSymbols = false; bool AutoClaimObjectSymbols = false;
ReturnObjectBufferFunction ReturnObjectBuffer; ReturnObjectBufferFunction ReturnObjectBuffer;

View File

@ -36,7 +36,7 @@ public:
Layer.ReturnObjectBuffer(std::move(ObjBuffer)); Layer.ReturnObjectBuffer(std::move(ObjBuffer));
} }
JITLinkMemoryManager &getMemoryManager() override { return Layer.MemMgr; } JITLinkMemoryManager &getMemoryManager() override { return *Layer.MemMgr; }
MemoryBufferRef getObjectBuffer() const override { MemoryBufferRef getObjectBuffer() const override {
return ObjBuffer->getMemBufferRef(); return ObjBuffer->getMemBufferRef();
@ -328,9 +328,9 @@ private:
ObjectLinkingLayer::Plugin::~Plugin() {} ObjectLinkingLayer::Plugin::~Plugin() {}
ObjectLinkingLayer::ObjectLinkingLayer(ExecutionSession &ES, ObjectLinkingLayer::ObjectLinkingLayer(
JITLinkMemoryManager &MemMgr) ExecutionSession &ES, std::unique_ptr<JITLinkMemoryManager> MemMgr)
: ObjectLayer(ES), MemMgr(MemMgr) {} : ObjectLayer(ES), MemMgr(std::move(MemMgr)) {}
ObjectLinkingLayer::~ObjectLinkingLayer() { ObjectLinkingLayer::~ObjectLinkingLayer() {
if (auto Err = removeAllModules()) if (auto Err = removeAllModules())

View File

@ -397,8 +397,8 @@ static std::unique_ptr<jitlink::JITLinkMemoryManager> createMemoryManager() {
} }
Session::Session(Triple TT) Session::Session(Triple TT)
: MainJD(ES.createJITDylib("<main>")), MemMgr(createMemoryManager()), : MainJD(ES.createJITDylib("<main>")), ObjLayer(ES, createMemoryManager()),
ObjLayer(ES, *MemMgr), TT(std::move(TT)) { TT(std::move(TT)) {
/// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the /// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the
/// Session. /// Session.

View File

@ -27,7 +27,6 @@ namespace llvm {
struct Session { struct Session {
orc::ExecutionSession ES; orc::ExecutionSession ES;
orc::JITDylib &MainJD; orc::JITDylib &MainJD;
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr;
orc::ObjectLinkingLayer ObjLayer; orc::ObjectLinkingLayer ObjLayer;
std::vector<orc::JITDylib *> JDSearchOrder; std::vector<orc::JITDylib *> JDSearchOrder;
Triple TT; Triple TT;