[llvm] r344643 - [ORC] Make the VModuleKey optional, propagate it via MaterializationUnit and
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 16 13:13:06 PDT 2018
Author: lhames
Date: Tue Oct 16 13:13:06 2018
New Revision: 344643
URL: http://llvm.org/viewvc/llvm-project?rev=344643&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyReexports.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp
llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/trunk/lib/ExecutionEngine/Orc/Layer.cpp
llvm/trunk/lib/ExecutionEngine/Orc/LazyReexports.cpp
llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp
llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h
llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h Tue Oct 16 13:13:06 2018
@@ -94,8 +94,7 @@ public:
/// Emits the given module. This should not be called by clients: it will be
/// called by the JIT when a definition added via the add method is requested.
- void emit(MaterializationResponsibility R, VModuleKey K,
- ThreadSafeModule TSM) override;
+ void emit(MaterializationResponsibility R, ThreadSafeModule TSM) override;
private:
struct PerDylibResources {
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h Tue Oct 16 13:13:06 2018
@@ -168,6 +168,9 @@ public:
/// into.
JITDylib &getTargetJITDylib() const { return JD; }
+ /// Returns the VModuleKey for this instance.
+ VModuleKey getVModuleKey() const { return K; }
+
/// Returns the symbol flags map for this responsibility instance.
/// Note: The returned flags may have transient flags (Lazy, Materializing)
/// set. These should be stripped with JITSymbolFlags::stripTransientFlags
@@ -218,7 +221,8 @@ public:
/// Delegates responsibility for the given symbols to the returned
/// materialization responsibility. Useful for breaking up work between
/// threads, or different kinds of materialization processes.
- MaterializationResponsibility delegate(const SymbolNameSet &Symbols);
+ MaterializationResponsibility delegate(const SymbolNameSet &Symbols,
+ VModuleKey NewKey = VModuleKey());
void addDependencies(const SymbolStringPtr &Name,
const SymbolDependenceMap &Dependencies);
@@ -229,10 +233,12 @@ public:
private:
/// Create a MaterializationResponsibility for the given JITDylib and
/// initial symbols.
- MaterializationResponsibility(JITDylib &JD, SymbolFlagsMap SymbolFlags);
+ MaterializationResponsibility(JITDylib &JD, SymbolFlagsMap SymbolFlags,
+ VModuleKey K);
JITDylib &JD;
SymbolFlagsMap SymbolFlags;
+ VModuleKey K;
};
/// A MaterializationUnit represents a set of symbol definitions that can
@@ -245,8 +251,8 @@ private:
/// stronger definition is added or already present.
class MaterializationUnit {
public:
- MaterializationUnit(SymbolFlagsMap InitalSymbolFlags)
- : SymbolFlags(std::move(InitalSymbolFlags)) {}
+ MaterializationUnit(SymbolFlagsMap InitalSymbolFlags, VModuleKey K)
+ : SymbolFlags(std::move(InitalSymbolFlags)), K(std::move(K)) {}
virtual ~MaterializationUnit() {}
@@ -261,7 +267,8 @@ public:
/// ExecutionSession::DispatchMaterializationFunction) to trigger
/// materialization of this MaterializationUnit.
void doMaterialize(JITDylib &JD) {
- materialize(MaterializationResponsibility(JD, std::move(SymbolFlags)));
+ materialize(MaterializationResponsibility(JD, std::move(SymbolFlags),
+ std::move(K)));
}
/// Called by JITDylibs to notify MaterializationUnits that the given symbol
@@ -273,6 +280,7 @@ public:
protected:
SymbolFlagsMap SymbolFlags;
+ VModuleKey K;
private:
virtual void anchor();
@@ -298,7 +306,7 @@ using MaterializationUnitList =
/// materialized.
class AbsoluteSymbolsMaterializationUnit : public MaterializationUnit {
public:
- AbsoluteSymbolsMaterializationUnit(SymbolMap Symbols);
+ AbsoluteSymbolsMaterializationUnit(SymbolMap Symbols, VModuleKey K);
StringRef getName() const override;
@@ -321,9 +329,9 @@ private:
/// \endcode
///
inline std::unique_ptr<AbsoluteSymbolsMaterializationUnit>
-absoluteSymbols(SymbolMap Symbols) {
+absoluteSymbols(SymbolMap Symbols, VModuleKey K = VModuleKey()) {
return llvm::make_unique<AbsoluteSymbolsMaterializationUnit>(
- std::move(Symbols));
+ std::move(Symbols), std::move(K));
}
struct SymbolAliasMapEntry {
@@ -349,7 +357,8 @@ public:
/// Note: Care must be taken that no sets of aliases form a cycle, as such
/// a cycle will result in a deadlock when any symbol in the cycle is
/// resolved.
- ReExportsMaterializationUnit(JITDylib *SourceJD, SymbolAliasMap Aliases);
+ ReExportsMaterializationUnit(JITDylib *SourceJD, SymbolAliasMap Aliases,
+ VModuleKey K);
StringRef getName() const override;
@@ -374,17 +383,18 @@ private:
/// return Err;
/// \endcode
inline std::unique_ptr<ReExportsMaterializationUnit>
-symbolAliases(SymbolAliasMap Aliases) {
- return llvm::make_unique<ReExportsMaterializationUnit>(nullptr,
- std::move(Aliases));
+symbolAliases(SymbolAliasMap Aliases, VModuleKey K = VModuleKey()) {
+ return llvm::make_unique<ReExportsMaterializationUnit>(
+ nullptr, std::move(Aliases), std::move(K));
}
/// Create a materialization unit for re-exporting symbols from another JITDylib
/// with alternative names/flags.
inline std::unique_ptr<ReExportsMaterializationUnit>
-reexports(JITDylib &SourceJD, SymbolAliasMap Aliases) {
- return llvm::make_unique<ReExportsMaterializationUnit>(&SourceJD,
- std::move(Aliases));
+reexports(JITDylib &SourceJD, SymbolAliasMap Aliases,
+ VModuleKey K = VModuleKey()) {
+ return llvm::make_unique<ReExportsMaterializationUnit>(
+ &SourceJD, std::move(Aliases), std::move(K));
}
/// Build a SymbolAliasMap for the common case where you want to re-export
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h Tue Oct 16 13:13:06 2018
@@ -41,8 +41,7 @@ public:
void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
- void emit(MaterializationResponsibility R, VModuleKey K,
- ThreadSafeModule TSM) override;
+ void emit(MaterializationResponsibility R, ThreadSafeModule TSM) override;
private:
mutable std::mutex IRLayerMutex;
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h Tue Oct 16 13:13:06 2018
@@ -35,8 +35,7 @@ public:
this->Transform = std::move(Transform);
}
- void emit(MaterializationResponsibility R, VModuleKey K,
- ThreadSafeModule TSM) override;
+ void emit(MaterializationResponsibility R, ThreadSafeModule TSM) override;
static ThreadSafeModule
identityTransform(ThreadSafeModule TSM,
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h Tue Oct 16 13:13:06 2018
@@ -111,8 +111,6 @@ protected:
LLJIT(std::unique_ptr<ExecutionSession> ES, JITTargetMachineBuilder JTMB,
DataLayout DL, unsigned NumCompileThreads);
- std::unique_ptr<RuntimeDyld::MemoryManager> getMemoryManager(VModuleKey K);
-
std::string mangle(StringRef UnmangledName);
Error applyDataLayout(Module &M);
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h Tue Oct 16 13:13:06 2018
@@ -49,11 +49,11 @@ public:
/// Adds a MaterializationUnit representing the given IR to the given
/// JITDylib.
- virtual Error add(JITDylib &JD, VModuleKey K, ThreadSafeModule TSM);
+ virtual Error add(JITDylib &JD, ThreadSafeModule TSM,
+ VModuleKey K = VModuleKey());
/// Emit should materialize the given IR.
- virtual void emit(MaterializationResponsibility R, VModuleKey K,
- ThreadSafeModule TSM) = 0;
+ virtual void emit(MaterializationResponsibility R, ThreadSafeModule TSM) = 0;
private:
bool CloneToNewContextOnEmit = false;
@@ -70,14 +70,16 @@ public:
/// Create an IRMaterializationLayer. Scans the module to build the
/// SymbolFlags and SymbolToDefinition maps.
- IRMaterializationUnit(ExecutionSession &ES, ThreadSafeModule TSM);
+ IRMaterializationUnit(ExecutionSession &ES, ThreadSafeModule TSM,
+ VModuleKey K);
/// Create an IRMaterializationLayer from a module, and pre-existing
/// SymbolFlags and SymbolToDefinition maps. The maps must provide
/// entries for each definition in M.
/// This constructor is useful for delegating work from one
/// IRMaterializationUnit to another.
- IRMaterializationUnit(ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags,
+ IRMaterializationUnit(ThreadSafeModule TSM, VModuleKey K,
+ SymbolFlagsMap SymbolFlags,
SymbolNameToDefinitionMap SymbolToDefinition);
/// Return the ModuleIdentifier as the name for this MaterializationUnit.
@@ -119,10 +121,11 @@ public:
/// Adds a MaterializationUnit representing the given IR to the given
/// JITDylib.
- virtual Error add(JITDylib &JD, VModuleKey K, std::unique_ptr<MemoryBuffer> O);
+ virtual Error add(JITDylib &JD, std::unique_ptr<MemoryBuffer> O,
+ VModuleKey K = VModuleKey());
/// Emit should materialize the given IR.
- virtual void emit(MaterializationResponsibility R, VModuleKey K,
+ virtual void emit(MaterializationResponsibility R,
std::unique_ptr<MemoryBuffer> O) = 0;
private:
@@ -149,7 +152,6 @@ private:
void discard(const JITDylib &JD, const SymbolStringPtr &Name) override;
ObjectLayer &L;
- VModuleKey K;
std::unique_ptr<MemoryBuffer> O;
};
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyReexports.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyReexports.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyReexports.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/LazyReexports.h Tue Oct 16 13:13:06 2018
@@ -159,7 +159,8 @@ public:
LazyReexportsMaterializationUnit(LazyCallThroughManager &LCTManager,
IndirectStubsManager &ISManager,
JITDylib &SourceJD,
- SymbolAliasMap CallableAliases);
+ SymbolAliasMap CallableAliases,
+ VModuleKey K);
StringRef getName() const override;
@@ -182,9 +183,10 @@ private:
inline std::unique_ptr<LazyReexportsMaterializationUnit>
lazyReexports(LazyCallThroughManager &LCTManager,
IndirectStubsManager &ISManager, JITDylib &SourceJD,
- SymbolAliasMap CallableAliases) {
+ SymbolAliasMap CallableAliases, VModuleKey K = VModuleKey()) {
return llvm::make_unique<LazyReexportsMaterializationUnit>(
- LCTManager, ISManager, SourceJD, std::move(CallableAliases));
+ LCTManager, ISManager, SourceJD, std::move(CallableAliases),
+ std::move(K));
}
} // End namespace orc
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h Tue Oct 16 13:13:06 2018
@@ -32,7 +32,7 @@ public:
ObjectTransformLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
TransformFunction Transform);
- void emit(MaterializationResponsibility R, VModuleKey K,
+ void emit(MaterializationResponsibility R,
std::unique_ptr<MemoryBuffer> O) override;
private:
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=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h Tue Oct 16 13:13:06 2018
@@ -47,7 +47,7 @@ public:
using NotifyEmittedFunction = std::function<void(VModuleKey)>;
using GetMemoryManagerFunction =
- std::function<std::unique_ptr<RuntimeDyld::MemoryManager>(VModuleKey)>;
+ std::function<std::unique_ptr<RuntimeDyld::MemoryManager>()>;
/// Construct an ObjectLinkingLayer with the given NotifyLoaded,
/// and NotifyEmitted functors.
@@ -57,7 +57,7 @@ public:
NotifyEmittedFunction NotifyEmitted = NotifyEmittedFunction());
/// Emit the object.
- void emit(MaterializationResponsibility R, VModuleKey K,
+ void emit(MaterializationResponsibility R,
std::unique_ptr<MemoryBuffer> O) override;
/// Set the 'ProcessAllSections' flag.
@@ -118,7 +118,7 @@ private:
bool ProcessAllSections = false;
bool OverrideObjectFlags = false;
bool AutoClaimObjectSymbols = false;
- std::map<VModuleKey, std::shared_ptr<RuntimeDyld::MemoryManager>> MemMgrs;
+ std::vector<std::unique_ptr<RuntimeDyld::MemoryManager>> MemMgrs;
};
class LegacyRTDyldObjectLinkingLayerBase {
Modified: llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp Tue Oct 16 13:13:06 2018
@@ -68,14 +68,16 @@ namespace orc {
class PartitioningIRMaterializationUnit : public IRMaterializationUnit {
public:
PartitioningIRMaterializationUnit(ExecutionSession &ES, ThreadSafeModule TSM,
- CompileOnDemandLayer &Parent)
- : IRMaterializationUnit(ES, std::move(TSM)), Parent(Parent) {}
+ VModuleKey K, CompileOnDemandLayer &Parent)
+ : IRMaterializationUnit(ES, std::move(TSM), std::move(K)),
+ Parent(Parent) {}
PartitioningIRMaterializationUnit(
ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags,
SymbolNameToDefinitionMap SymbolToDefinition,
CompileOnDemandLayer &Parent)
- : IRMaterializationUnit(std::move(TSM), std::move(SymbolFlags),
+ : IRMaterializationUnit(std::move(TSM), std::move(K),
+ std::move(SymbolFlags),
std::move(SymbolToDefinition)),
Parent(Parent) {}
@@ -116,8 +118,8 @@ void CompileOnDemandLayer::setPartitionF
this->Partition = std::move(Partition);
}
-void CompileOnDemandLayer::emit(MaterializationResponsibility R, VModuleKey K,
- ThreadSafeModule TSM) {
+void CompileOnDemandLayer::emit(MaterializationResponsibility R,
+ ThreadSafeModule TSM) {
assert(TSM.getModule() && "Null module");
auto &ES = getExecutionSession();
@@ -149,7 +151,7 @@ void CompileOnDemandLayer::emit(Material
// implementation dylib.
if (auto Err = PDR.getImplDylib().define(
llvm::make_unique<PartitioningIRMaterializationUnit>(
- ES, std::move(TSM), *this))) {
+ ES, std::move(TSM), R.getVModuleKey(), *this))) {
ES.reportError(std::move(Err));
R.failMaterialization();
return;
@@ -245,7 +247,7 @@ void CompileOnDemandLayer::emitPartition
// unmodified to the base layer.
if (GVsToExtract == None) {
Defs.clear();
- BaseLayer.emit(std::move(R), ES.allocateVModule(), std::move(TSM));
+ BaseLayer.emit(std::move(R), std::move(TSM));
return;
}
@@ -285,9 +287,9 @@ void CompileOnDemandLayer::emitPartition
auto ExtractedTSM = extractSubModule(TSM, ".submodule", ShouldExtract);
R.replace(llvm::make_unique<PartitioningIRMaterializationUnit>(
- ES, std::move(TSM), *this));
+ ES, std::move(TSM), R.getVModuleKey(), *this));
- BaseLayer.emit(std::move(R), ES.allocateVModule(), std::move(ExtractedTSM));
+ BaseLayer.emit(std::move(R), std::move(ExtractedTSM));
}
} // end namespace orc
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp Tue Oct 16 13:13:06 2018
@@ -368,8 +368,8 @@ void AsynchronousSymbolQuery::detach() {
}
MaterializationResponsibility::MaterializationResponsibility(
- JITDylib &JD, SymbolFlagsMap SymbolFlags)
- : JD(JD), SymbolFlags(std::move(SymbolFlags)) {
+ JITDylib &JD, SymbolFlagsMap SymbolFlags, VModuleKey K)
+ : JD(JD), SymbolFlags(std::move(SymbolFlags)), K(std::move(K)) {
assert(!this->SymbolFlags.empty() && "Materializing nothing?");
#ifndef NDEBUG
@@ -461,7 +461,12 @@ void MaterializationResponsibility::repl
}
MaterializationResponsibility
-MaterializationResponsibility::delegate(const SymbolNameSet &Symbols) {
+MaterializationResponsibility::delegate(const SymbolNameSet &Symbols,
+ VModuleKey NewKey) {
+
+ if (NewKey == VModuleKey())
+ NewKey = K;
+
SymbolFlagsMap DelegatedFlags;
for (auto &Name : Symbols) {
@@ -474,7 +479,8 @@ MaterializationResponsibility::delegate(
SymbolFlags.erase(I);
}
- return MaterializationResponsibility(JD, std::move(DelegatedFlags));
+ return MaterializationResponsibility(JD, std::move(DelegatedFlags),
+ std::move(NewKey));
}
void MaterializationResponsibility::addDependencies(
@@ -491,8 +497,9 @@ void MaterializationResponsibility::addD
}
AbsoluteSymbolsMaterializationUnit::AbsoluteSymbolsMaterializationUnit(
- SymbolMap Symbols)
- : MaterializationUnit(extractFlags(Symbols)), Symbols(std::move(Symbols)) {}
+ SymbolMap Symbols, VModuleKey K)
+ : MaterializationUnit(extractFlags(Symbols), std::move(K)),
+ Symbols(std::move(Symbols)) {}
StringRef AbsoluteSymbolsMaterializationUnit::getName() const {
return "<Absolute Symbols>";
@@ -519,9 +526,9 @@ AbsoluteSymbolsMaterializationUnit::extr
}
ReExportsMaterializationUnit::ReExportsMaterializationUnit(
- JITDylib *SourceJD, SymbolAliasMap Aliases)
- : MaterializationUnit(extractFlags(Aliases)), SourceJD(SourceJD),
- Aliases(std::move(Aliases)) {}
+ JITDylib *SourceJD, SymbolAliasMap Aliases, VModuleKey K)
+ : MaterializationUnit(extractFlags(Aliases), std::move(K)),
+ SourceJD(SourceJD), Aliases(std::move(Aliases)) {}
StringRef ReExportsMaterializationUnit::getName() const {
return "<Reexports>";
Modified: llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp Tue Oct 16 13:13:06 2018
@@ -21,19 +21,19 @@ void IRCompileLayer::setNotifyCompiled(N
this->NotifyCompiled = std::move(NotifyCompiled);
}
-void IRCompileLayer::emit(MaterializationResponsibility R, VModuleKey K,
- ThreadSafeModule TSM) {
+void IRCompileLayer::emit(MaterializationResponsibility R,
+ ThreadSafeModule TSM) {
assert(TSM.getModule() && "Module must not be null");
if (auto Obj = Compile(*TSM.getModule())) {
{
std::lock_guard<std::mutex> Lock(IRLayerMutex);
if (NotifyCompiled)
- NotifyCompiled(K, std::move(TSM));
+ NotifyCompiled(R.getVModuleKey(), std::move(TSM));
else
TSM = ThreadSafeModule();
}
- BaseLayer.emit(std::move(R), std::move(K), std::move(*Obj));
+ BaseLayer.emit(std::move(R), std::move(*Obj));
} else {
R.failMaterialization();
getExecutionSession().reportError(Obj.takeError());
Modified: llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp Tue Oct 16 13:13:06 2018
@@ -18,12 +18,12 @@ IRTransformLayer::IRTransformLayer(Execu
TransformFunction Transform)
: IRLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
-void IRTransformLayer::emit(MaterializationResponsibility R, VModuleKey K,
- ThreadSafeModule TSM) {
+void IRTransformLayer::emit(MaterializationResponsibility R,
+ ThreadSafeModule TSM) {
assert(TSM.getModule() && "Module must not be null");
if (auto TransformedTSM = Transform(std::move(TSM), R))
- BaseLayer.emit(std::move(R), std::move(K), std::move(*TransformedTSM));
+ BaseLayer.emit(std::move(R), std::move(*TransformedTSM));
else {
R.failMaterialization();
getExecutionSession().reportError(TransformedTSM.takeError());
Modified: llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp Tue Oct 16 13:13:06 2018
@@ -27,8 +27,9 @@ public:
using CompileFunction = JITCompileCallbackManager::CompileFunction;
CompileCallbackMaterializationUnit(SymbolStringPtr Name,
- CompileFunction Compile)
- : MaterializationUnit(SymbolFlagsMap({{Name, JITSymbolFlags::Exported}})),
+ CompileFunction Compile, VModuleKey K)
+ : MaterializationUnit(SymbolFlagsMap({{Name, JITSymbolFlags::Exported}}),
+ std::move(K)),
Name(std::move(Name)), Compile(std::move(Compile)) {}
StringRef getName() const override { return "<Compile Callbacks>"; }
@@ -67,7 +68,8 @@ JITCompileCallbackManager::getCompileCal
AddrToSymbol[*TrampolineAddr] = CallbackName;
cantFail(CallbacksJD.define(
llvm::make_unique<CompileCallbackMaterializationUnit>(
- std::move(CallbackName), std::move(Compile))));
+ std::move(CallbackName), std::move(Compile),
+ ES.allocateVModule())));
return *TrampolineAddr;
} else
return TrampolineAddr.takeError();
Modified: llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp Tue Oct 16 13:13:06 2018
@@ -65,15 +65,13 @@ Error LLJIT::addIRModule(JITDylib &JD, T
if (auto Err = applyDataLayout(*TSM.getModule()))
return Err;
- auto K = ES->allocateVModule();
- return CompileLayer.add(JD, K, std::move(TSM));
+ return CompileLayer.add(JD, std::move(TSM), ES->allocateVModule());
}
Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
assert(Obj && "Can not add null object");
- auto K = ES->allocateVModule();
- return ObjLinkingLayer.add(JD, K, std::move(Obj));
+ return ObjLinkingLayer.add(JD, std::move(Obj), ES->allocateVModule());
}
Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD,
@@ -84,8 +82,9 @@ Expected<JITEvaluatedSymbol> LLJIT::look
LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES,
std::unique_ptr<TargetMachine> TM, DataLayout DL)
: ES(std::move(ES)), Main(this->ES->getMainJITDylib()), DL(std::move(DL)),
- ObjLinkingLayer(*this->ES,
- [this](VModuleKey K) { return getMemoryManager(K); }),
+ ObjLinkingLayer(
+ *this->ES,
+ []() { return llvm::make_unique<SectionMemoryManager>(); }),
CompileLayer(*this->ES, ObjLinkingLayer,
TMOwningSimpleCompiler(std::move(TM))),
CtorRunner(Main), DtorRunner(Main) {}
@@ -93,8 +92,9 @@ LLJIT::LLJIT(std::unique_ptr<ExecutionSe
LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES, JITTargetMachineBuilder JTMB,
DataLayout DL, unsigned NumCompileThreads)
: ES(std::move(ES)), Main(this->ES->getMainJITDylib()), DL(std::move(DL)),
- ObjLinkingLayer(*this->ES,
- [this](VModuleKey K) { return getMemoryManager(K); }),
+ ObjLinkingLayer(
+ *this->ES,
+ []() { return llvm::make_unique<SectionMemoryManager>(); }),
CompileLayer(*this->ES, ObjLinkingLayer,
ConcurrentIRCompiler(std::move(JTMB))),
CtorRunner(Main), DtorRunner(Main) {
@@ -117,11 +117,6 @@ LLJIT::LLJIT(std::unique_ptr<ExecutionSe
});
}
-std::unique_ptr<RuntimeDyld::MemoryManager>
-LLJIT::getMemoryManager(VModuleKey K) {
- return llvm::make_unique<SectionMemoryManager>();
-}
-
std::string LLJIT::mangle(StringRef UnmangledName) {
std::string MangledName;
{
@@ -187,8 +182,7 @@ Error LLLazyJIT::addLazyIRModule(JITDyli
recordCtorDtors(*TSM.getModule());
- auto K = ES->allocateVModule();
- return CODLayer.add(JD, K, std::move(TSM));
+ return CODLayer.add(JD, std::move(TSM), ES->allocateVModule());
}
LLLazyJIT::LLLazyJIT(
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Layer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Layer.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Layer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Layer.cpp Tue Oct 16 13:13:06 2018
@@ -19,14 +19,14 @@ namespace orc {
IRLayer::IRLayer(ExecutionSession &ES) : ES(ES) {}
IRLayer::~IRLayer() {}
-Error IRLayer::add(JITDylib &JD, VModuleKey K, ThreadSafeModule TSM) {
+Error IRLayer::add(JITDylib &JD, ThreadSafeModule TSM, VModuleKey K) {
return JD.define(llvm::make_unique<BasicIRLayerMaterializationUnit>(
*this, std::move(K), std::move(TSM)));
}
IRMaterializationUnit::IRMaterializationUnit(ExecutionSession &ES,
- ThreadSafeModule TSM)
- : MaterializationUnit(SymbolFlagsMap()), TSM(std::move(TSM)) {
+ ThreadSafeModule TSM, VModuleKey K)
+ : MaterializationUnit(SymbolFlagsMap(), std::move(K)), TSM(std::move(TSM)) {
assert(this->TSM && "Module must not be null");
@@ -42,10 +42,10 @@ IRMaterializationUnit::IRMaterialization
}
IRMaterializationUnit::IRMaterializationUnit(
- ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags,
+ ThreadSafeModule TSM, VModuleKey K, SymbolFlagsMap SymbolFlags,
SymbolNameToDefinitionMap SymbolToDefinition)
- : MaterializationUnit(std::move(SymbolFlags)), TSM(std::move(TSM)),
- SymbolToDefinition(std::move(SymbolToDefinition)) {}
+ : MaterializationUnit(std::move(SymbolFlags), std::move(K)),
+ TSM(std::move(TSM)), SymbolToDefinition(std::move(SymbolToDefinition)) {}
StringRef IRMaterializationUnit::getName() const {
if (TSM.getModule())
@@ -71,8 +71,9 @@ void IRMaterializationUnit::discard(cons
BasicIRLayerMaterializationUnit::BasicIRLayerMaterializationUnit(
IRLayer &L, VModuleKey K, ThreadSafeModule TSM)
- : IRMaterializationUnit(L.getExecutionSession(), std::move(TSM)), L(L),
- K(std::move(K)) {}
+ : IRMaterializationUnit(L.getExecutionSession(), std::move(TSM),
+ std::move(K)),
+ L(L), K(std::move(K)) {}
void BasicIRLayerMaterializationUnit::materialize(
MaterializationResponsibility R) {
@@ -94,7 +95,7 @@ void BasicIRLayerMaterializationUnit::ma
dbgs() << "Emitting, for " << R.getTargetJITDylib().getName() << ", "
<< *this << "\n";
}););
- L.emit(std::move(R), std::move(K), std::move(TSM));
+ L.emit(std::move(R), std::move(TSM));
LLVM_DEBUG(ES.runSessionLocked([&]() {
dbgs() << "Finished emitting, for " << R.getTargetJITDylib().getName()
<< ", " << *this << "\n";
@@ -105,8 +106,8 @@ ObjectLayer::ObjectLayer(ExecutionSessio
ObjectLayer::~ObjectLayer() {}
-Error ObjectLayer::add(JITDylib &JD, VModuleKey K,
- std::unique_ptr<MemoryBuffer> O) {
+Error ObjectLayer::add(JITDylib &JD, std::unique_ptr<MemoryBuffer> O,
+ VModuleKey K) {
auto ObjMU = BasicObjectLayerMaterializationUnit::Create(*this, std::move(K),
std::move(O));
if (!ObjMU)
@@ -131,7 +132,7 @@ BasicObjectLayerMaterializationUnit::Cre
BasicObjectLayerMaterializationUnit::BasicObjectLayerMaterializationUnit(
ObjectLayer &L, VModuleKey K, std::unique_ptr<MemoryBuffer> O,
SymbolFlagsMap SymbolFlags)
- : MaterializationUnit(std::move(SymbolFlags)), L(L), K(std::move(K)),
+ : MaterializationUnit(std::move(SymbolFlags), std::move(K)), L(L),
O(std::move(O)) {}
StringRef BasicObjectLayerMaterializationUnit::getName() const {
@@ -142,7 +143,7 @@ StringRef BasicObjectLayerMaterializatio
void BasicObjectLayerMaterializationUnit::materialize(
MaterializationResponsibility R) {
- L.emit(std::move(R), std::move(K), std::move(O));
+ L.emit(std::move(R), std::move(O));
}
void BasicObjectLayerMaterializationUnit::discard(const JITDylib &JD,
Modified: llvm/trunk/lib/ExecutionEngine/Orc/LazyReexports.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/LazyReexports.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/LazyReexports.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/LazyReexports.cpp Tue Oct 16 13:13:06 2018
@@ -125,8 +125,8 @@ createLocalLazyCallThroughManager(const
LazyReexportsMaterializationUnit::LazyReexportsMaterializationUnit(
LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager,
- JITDylib &SourceJD, SymbolAliasMap CallableAliases)
- : MaterializationUnit(extractFlags(CallableAliases)),
+ JITDylib &SourceJD, SymbolAliasMap CallableAliases, VModuleKey K)
+ : MaterializationUnit(extractFlags(CallableAliases), std::move(K)),
LCTManager(LCTManager), ISManager(ISManager), SourceJD(SourceJD),
CallableAliases(std::move(CallableAliases)),
NotifyResolved(LazyCallThroughManager::createNotifyResolvedFunction(
Modified: llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp Tue Oct 16 13:13:06 2018
@@ -18,12 +18,12 @@ ObjectTransformLayer::ObjectTransformLay
TransformFunction Transform)
: ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
-void ObjectTransformLayer::emit(MaterializationResponsibility R, VModuleKey K,
+void ObjectTransformLayer::emit(MaterializationResponsibility R,
std::unique_ptr<MemoryBuffer> O) {
assert(O && "Module must not be null");
if (auto TransformedObj = Transform(std::move(O)))
- BaseLayer.emit(std::move(R), std::move(K), std::move(*TransformedObj));
+ BaseLayer.emit(std::move(R), std::move(*TransformedObj));
else {
R.failMaterialization();
getExecutionSession().reportError(TransformedObj.takeError());
Modified: llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp Tue Oct 16 13:13:06 2018
@@ -84,8 +84,7 @@ RTDyldObjectLinkingLayer::RTDyldObjectLi
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 @@ void RTDyldObjectLinkingLayer::emit(Mate
}
}
- 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);
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/OrcTestCommon.h Tue Oct 16 13:13:06 2018
@@ -97,7 +97,7 @@ public:
orc::SymbolFlagsMap SymbolFlags, MaterializeFunction Materialize,
DiscardFunction Discard = DiscardFunction(),
DestructorFunction Destructor = DestructorFunction())
- : MaterializationUnit(std::move(SymbolFlags)),
+ : MaterializationUnit(std::move(SymbolFlags), orc::VModuleKey()),
Materialize(std::move(Materialize)), Discard(std::move(Discard)),
Destructor(std::move(Destructor)) {}
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp?rev=344643&r1=344642&r2=344643&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp Tue Oct 16 13:13:06 2018
@@ -54,7 +54,7 @@ static bool testSetProcessAllSections(st
auto &JD = ES.createJITDylib("main");
auto Foo = ES.intern("foo");
- RTDyldObjectLinkingLayer ObjLayer(ES, [&DebugSectionSeen](VModuleKey) {
+ RTDyldObjectLinkingLayer ObjLayer(ES, [&DebugSectionSeen]() {
return llvm::make_unique<MemoryManagerWrapper>(DebugSectionSeen);
});
@@ -65,8 +65,7 @@ static bool testSetProcessAllSections(st
auto OnReadyDoNothing = [](Error Err) { cantFail(std::move(Err)); };
ObjLayer.setProcessAllSections(ProcessAllSections);
- auto K = ES.allocateVModule();
- cantFail(ObjLayer.add(JD, K, std::move(Obj)));
+ cantFail(ObjLayer.add(JD, std::move(Obj), ES.allocateVModule()));
ES.lookup({&JD}, {Foo}, OnResolveDoNothing, OnReadyDoNothing,
NoDependenciesToRegister);
return DebugSectionSeen;
@@ -152,12 +151,12 @@ TEST(RTDyldObjectLinkingLayerTest, TestO
auto &JD = ES.createJITDylib("main");
auto Foo = ES.intern("foo");
RTDyldObjectLinkingLayer ObjLayer(
- ES, [](VModuleKey) { return llvm::make_unique<SectionMemoryManager>(); });
+ ES, []() { return llvm::make_unique<SectionMemoryManager>(); });
IRCompileLayer CompileLayer(ES, ObjLayer, FunkySimpleCompiler(*TM));
ObjLayer.setOverrideObjectFlagsWithResponsibilityFlags(true);
- cantFail(CompileLayer.add(JD, ES.allocateVModule(), std::move(M)));
+ cantFail(CompileLayer.add(JD, std::move(M), ES.allocateVModule()));
ES.lookup({&JD}, {Foo}, [](Expected<SymbolMap> R) { cantFail(std::move(R)); },
[](Error Err) { cantFail(std::move(Err)); },
NoDependenciesToRegister);
@@ -214,12 +213,12 @@ TEST(RTDyldObjectLinkingLayerTest, TestA
auto &JD = ES.createJITDylib("main");
auto Foo = ES.intern("foo");
RTDyldObjectLinkingLayer ObjLayer(
- ES, [](VModuleKey) { return llvm::make_unique<SectionMemoryManager>(); });
+ ES, []() { return llvm::make_unique<SectionMemoryManager>(); });
IRCompileLayer CompileLayer(ES, ObjLayer, FunkySimpleCompiler(*TM));
ObjLayer.setAutoClaimResponsibilityForObjectSymbols(true);
- cantFail(CompileLayer.add(JD, ES.allocateVModule(), std::move(M)));
+ cantFail(CompileLayer.add(JD, std::move(M), ES.allocateVModule()));
ES.lookup({&JD}, {Foo}, [](Expected<SymbolMap> R) { cantFail(std::move(R)); },
[](Error Err) { cantFail(std::move(Err)); },
NoDependenciesToRegister);
More information about the llvm-commits
mailing list