From c0143f37dab38a2da27c9bb6f44f3a54ca9cf86f Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Sun, 15 Dec 2019 17:23:36 -0800 Subject: [PATCH] [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. --- .../include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h | 4 ++-- llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp | 8 ++++---- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 4 ++-- llvm/tools/llvm-jitlink/llvm-jitlink.h | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h index caf8e707516d..50d25f18891e 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h @@ -79,7 +79,7 @@ public: /// Construct an ObjectLinkingLayer with the given NotifyLoaded, /// and NotifyEmitted functors. ObjectLinkingLayer(ExecutionSession &ES, - jitlink::JITLinkMemoryManager &MemMgr); + std::unique_ptr MemMgr); /// Destruct an ObjectLinkingLayer. ~ObjectLinkingLayer(); @@ -145,7 +145,7 @@ private: Error removeAllModules(); mutable std::mutex LayerMutex; - jitlink::JITLinkMemoryManager &MemMgr; + std::unique_ptr MemMgr; bool OverrideObjectFlags = false; bool AutoClaimObjectSymbols = false; ReturnObjectBufferFunction ReturnObjectBuffer; diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp index be0ce4a1d75a..2572b7f4878d 100644 --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -36,7 +36,7 @@ public: Layer.ReturnObjectBuffer(std::move(ObjBuffer)); } - JITLinkMemoryManager &getMemoryManager() override { return Layer.MemMgr; } + JITLinkMemoryManager &getMemoryManager() override { return *Layer.MemMgr; } MemoryBufferRef getObjectBuffer() const override { return ObjBuffer->getMemBufferRef(); @@ -328,9 +328,9 @@ private: ObjectLinkingLayer::Plugin::~Plugin() {} -ObjectLinkingLayer::ObjectLinkingLayer(ExecutionSession &ES, - JITLinkMemoryManager &MemMgr) - : ObjectLayer(ES), MemMgr(MemMgr) {} +ObjectLinkingLayer::ObjectLinkingLayer( + ExecutionSession &ES, std::unique_ptr MemMgr) + : ObjectLayer(ES), MemMgr(std::move(MemMgr)) {} ObjectLinkingLayer::~ObjectLinkingLayer() { if (auto Err = removeAllModules()) diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index de52bb9ec637..26bcf46d60a6 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -397,8 +397,8 @@ static std::unique_ptr createMemoryManager() { } Session::Session(Triple TT) - : MainJD(ES.createJITDylib("
")), MemMgr(createMemoryManager()), - ObjLayer(ES, *MemMgr), TT(std::move(TT)) { + : MainJD(ES.createJITDylib("
")), ObjLayer(ES, createMemoryManager()), + TT(std::move(TT)) { /// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the /// Session. diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.h b/llvm/tools/llvm-jitlink/llvm-jitlink.h index 005f7f211e98..0f92d7605012 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.h +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.h @@ -27,7 +27,6 @@ namespace llvm { struct Session { orc::ExecutionSession ES; orc::JITDylib &MainJD; - std::unique_ptr MemMgr; orc::ObjectLinkingLayer ObjLayer; std::vector JDSearchOrder; Triple TT;