diff options
21 files changed, 124 insertions, 117 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h index 7721f74fe0c..884878925cd 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h @@ -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 { diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h index 86c5ebb6d27..2e56854340c 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h @@ -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 diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h index a62d8be2fa6..30d71e69cd7 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h @@ -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; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h index 55a1ce4c930..49e65b9f2a8 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h @@ -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, diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h index 05a566fedb6..8b6465e1f02 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -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); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h index be5d9653dd8..cd797445a2e 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h @@ -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; }; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h b/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h index 8f897009ac2..b5041325bce 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h @@ -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 diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h index 6cd688ad58a..44d6b490e19 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h @@ -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: diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h index bbd782fdece..401f6e3fa81 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h @@ -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 { diff --git a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp index f27a814f33f..de1fa079dde 100644 --- a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp @@ -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::setPartitionFunction(PartitionFunction Partition) { 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(MaterializationResponsibility R, VModuleKey K, // 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 diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index d477ca523d8..5e31e448c7d 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -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::replace( } 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(const SymbolNameSet &Symbols) { 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::addDependenciesForAll( } 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::extractFlags(const SymbolMap &Symbols) { } 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>"; diff --git a/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp b/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp index 6d029e16ba9..d952d1be70d 100644 --- a/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp @@ -21,19 +21,19 @@ void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) { 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()); diff --git a/llvm/lib/ExecutionEngine/Orc/IRTransformLayer.cpp b/llvm/lib/ExecutionEngine/Orc/IRTransformLayer.cpp index acba7916d40..7bc0d696e3a 100644 --- a/llvm/lib/ExecutionEngine/Orc/IRTransformLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IRTransformLayer.cpp @@ -18,12 +18,12 @@ IRTransformLayer::IRTransformLayer(ExecutionSession &ES, 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()); diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index 6bc33c90cbc..c10d15ab117 100644 --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -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::getCompileCallback(CompileFunction Compile) { 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(); diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index e464da267ae..ac71a5e7673 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -65,15 +65,13 @@ Error LLJIT::addIRModule(JITDylib &JD, ThreadSafeModule TSM) { 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::lookupLinkerMangled(JITDylib &JD, 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<ExecutionSession> ES, 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<ExecutionSession> ES, JITTargetMachineBuilder JTMB, }); } -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(JITDylib &JD, ThreadSafeModule TSM) { 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( diff --git a/llvm/lib/ExecutionEngine/Orc/Layer.cpp b/llvm/lib/ExecutionEngine/Orc/Layer.cpp index 22dbf5c26d1..11af76825e9 100644 --- a/llvm/lib/ExecutionEngine/Orc/Layer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Layer.cpp @@ -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::IRMaterializationUnit(ExecutionSession &ES, } 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(const JITDylib &JD, 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::materialize( 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(ExecutionSession &ES) : ES(ES) {} 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::Create(ObjectLayer &L, VModuleKey K, 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 BasicObjectLayerMaterializationUnit::getName() const { 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, diff --git a/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp b/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp index 1cce0c6cd2c..af4c508d7f1 100644 --- a/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp @@ -125,8 +125,8 @@ createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, 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( diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp index 0be23f2e1a4..825f5320473 100644 --- a/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp @@ -18,12 +18,12 @@ ObjectTransformLayer::ObjectTransformLayer(ExecutionSession &ES, 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()); diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp index fa574140d48..8511e41c4f2 100644 --- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp @@ -84,8 +84,7 @@ RTDyldObjectLinkingLayer::RTDyldObjectLinkingLayer( 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(MaterializationResponsibility R, } } - 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); diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h index 284a1e37f10..e76d2fae5e3 100644 --- a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h +++ b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h @@ -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)) {} diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp index 75ccfc9ab0d..1660670ae63 100644 --- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp @@ -54,7 +54,7 @@ static bool testSetProcessAllSections(std::unique_ptr<MemoryBuffer> Obj, 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(std::unique_ptr<MemoryBuffer> Obj, 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, TestOverrideObjectFlags) { 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, TestAutoClaimResponsibilityForSymbols) { 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); |