[ORC] Make the VModuleKey optional, propagate it via MaterializationUnit and
MaterializationResponsibility.
VModuleKeys are intended to enable selective removal of modules from a JIT
session, however for a wide variety of use cases selective removal is not
needed and introduces unnecessary overhead. As of this commit, the default
constructed VModuleKey value is reserved as a "do not track" value, and
becomes the default when adding a new module to the JIT.
This commit also changes the propagation of VModuleKeys. They were passed
alongside the MaterializationResponsibity instance in XXLayer::emit methods,
but are now propagated as part of the MaterializationResponsibility instance
itself (and as part of MaterializationUnit when stored in a JITDylib).
Associating VModuleKeys with MaterializationUnits in this way should allow
for a thread-safe module removal mechanism in the future, even when a module
is in the process of being compiled, by having the
MaterializationResponsibility object check in on its VModuleKey's state
before commiting its results to the JITDylib.
llvm-svn: 344643
diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
index fa57414..8511e41 100644
--- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
@@ -84,8 +84,7 @@
NotifyEmitted(std::move(NotifyEmitted)) {}
void RTDyldObjectLinkingLayer::emit(MaterializationResponsibility R,
- VModuleKey K,
- std::unique_ptr<MemoryBuffer> O) {
+ std::unique_ptr<MemoryBuffer> O) {
assert(O && "Object must not be null");
// This method launches an asynchronous link step that will fulfill our
@@ -121,15 +120,9 @@
}
}
- auto MemoryManager = GetMemoryManager(K);
- auto &MemMgr = *MemoryManager;
- {
- std::lock_guard<std::mutex> Lock(RTDyldLayerMutex);
-
- assert(!MemMgrs.count(K) &&
- "A memory manager already exists for this key?");
- MemMgrs[K] = std::move(MemoryManager);
- }
+ auto K = R.getVModuleKey();
+ MemMgrs.push_back(GetMemoryManager());
+ auto &MemMgr = *MemMgrs.back();
JITDylibSearchOrderResolver Resolver(*SharedR);