Skip to content
Permalink
Browse files

[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.
  • Loading branch information
lhames committed Dec 16, 2019
1 parent 1ea5ce6 commit c0143f37dab38a2da27c9bb6f44f3a54ca9cf86f
@@ -79,7 +79,7 @@ class ObjectLinkingLayer : public ObjectLayer {
/// Construct an ObjectLinkingLayer with the given NotifyLoaded,
/// and NotifyEmitted functors.
ObjectLinkingLayer(ExecutionSession &ES,
jitlink::JITLinkMemoryManager &MemMgr);
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr);

/// Destruct an ObjectLinkingLayer.
~ObjectLinkingLayer();
@@ -145,7 +145,7 @@ class ObjectLinkingLayer : public ObjectLayer {
Error removeAllModules();

mutable std::mutex LayerMutex;
jitlink::JITLinkMemoryManager &MemMgr;
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr;
bool OverrideObjectFlags = false;
bool AutoClaimObjectSymbols = false;
ReturnObjectBufferFunction ReturnObjectBuffer;
@@ -36,7 +36,7 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
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 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {

ObjectLinkingLayer::Plugin::~Plugin() {}

ObjectLinkingLayer::ObjectLinkingLayer(ExecutionSession &ES,
JITLinkMemoryManager &MemMgr)
: ObjectLayer(ES), MemMgr(MemMgr) {}
ObjectLinkingLayer::ObjectLinkingLayer(
ExecutionSession &ES, std::unique_ptr<JITLinkMemoryManager> MemMgr)
: ObjectLayer(ES), MemMgr(std::move(MemMgr)) {}

ObjectLinkingLayer::~ObjectLinkingLayer() {
if (auto Err = removeAllModules())
@@ -397,8 +397,8 @@ static std::unique_ptr<jitlink::JITLinkMemoryManager> createMemoryManager() {
}

Session::Session(Triple TT)
: MainJD(ES.createJITDylib("<main>")), MemMgr(createMemoryManager()),
ObjLayer(ES, *MemMgr), TT(std::move(TT)) {
: MainJD(ES.createJITDylib("<main>")), ObjLayer(ES, createMemoryManager()),
TT(std::move(TT)) {

/// Local ObjectLinkingLayer::Plugin class to forward modifyPassConfig to the
/// Session.
@@ -27,7 +27,6 @@ namespace llvm {
struct Session {
orc::ExecutionSession ES;
orc::JITDylib &MainJD;
std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr;
orc::ObjectLinkingLayer ObjLayer;
std::vector<orc::JITDylib *> JDSearchOrder;
Triple TT;

0 comments on commit c0143f3

Please sign in to comment.
You can’t perform that action at this time.