mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-23 11:49:50 +00:00
[Orc] Remove the memory manager argument to addModule, and de-templatize the
symbol resolver argument. De-templatizing the symbol resolver is part of the ongoing simplification of ORC layer API. Removing the memory management argument (and delegating construction of memory managers for RTDyldObjectLinkingLayer to a functor passed in to the constructor) allows us to build JITs whose base object layers need not be compatible with RTDyldObjectLinkingLayer's memory mangement scheme. For example, a 'remote object layer' that sends fully relocatable objects directly to the remote does not need a memory management scheme at all (that will be handled by the remote). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307058 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
285f30181c
commit
966d9ebd7f
@ -48,6 +48,7 @@ public:
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
|
||||
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
|
||||
}
|
||||
@ -75,7 +76,6 @@ public:
|
||||
// Add the set to the JIT with the resolver we created above and a newly
|
||||
// created SectionMemoryManager.
|
||||
return CompileLayer.addModule(std::move(M),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
@ -88,7 +89,6 @@ public:
|
||||
// Add the set to the JIT with the resolver we created above and a newly
|
||||
// created SectionMemoryManager.
|
||||
return OptimizeLayer.addModule(std::move(M),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ public:
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
@ -101,7 +102,6 @@ public:
|
||||
// Add the set to the JIT with the resolver we created above and a newly
|
||||
// created SectionMemoryManager.
|
||||
return CODLayer.addModule(std::move(M),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,7 @@ public:
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()),
|
||||
DL(TM->createDataLayout()),
|
||||
ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
@ -128,7 +129,6 @@ public:
|
||||
// Add the set to the JIT with the resolver we created above and a newly
|
||||
// created SectionMemoryManager.
|
||||
return OptimizeLayer.addModule(std::move(M),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,15 @@ public:
|
||||
: TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "",
|
||||
"", SmallVector<std::string, 0>())),
|
||||
DL(TM->createDataLayout()),
|
||||
ObjectLayer([&Remote]() {
|
||||
std::unique_ptr<MyRemote::RCMemoryManager> MemMgr;
|
||||
if (auto Err = Remote.createRemoteMemoryManager(MemMgr)) {
|
||||
logAllUnhandledErrors(std::move(Err), errs(),
|
||||
"Error creating remote memory manager:");
|
||||
exit(1);
|
||||
}
|
||||
return MemMgr;
|
||||
}),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
@ -146,17 +155,9 @@ public:
|
||||
return JITSymbol(nullptr);
|
||||
});
|
||||
|
||||
std::unique_ptr<MyRemote::RCMemoryManager> MemMgr;
|
||||
if (auto Err = Remote.createRemoteMemoryManager(MemMgr)) {
|
||||
logAllUnhandledErrors(std::move(Err), errs(),
|
||||
"Error creating remote memory manager:");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Add the set to the JIT with the resolver we created above and a newly
|
||||
// created SectionMemoryManager.
|
||||
return OptimizeLayer.addModule(std::move(M),
|
||||
std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
|
||||
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
|
||||
}
|
||||
@ -63,7 +64,6 @@ public:
|
||||
},
|
||||
[](const std::string &S) { return nullptr; });
|
||||
auto H = CompileLayer.addModule(std::move(M),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
|
||||
ModuleHandles.push_back(H);
|
||||
|
@ -146,7 +146,7 @@ private:
|
||||
std::unique_ptr<JITSymbolResolver>)>;
|
||||
|
||||
struct SourceModuleEntry {
|
||||
std::unique_ptr<ResourceOwner<Module>> SourceMod;
|
||||
std::shared_ptr<Module> SourceMod;
|
||||
std::set<Function*> StubsToClone;
|
||||
};
|
||||
|
||||
@ -154,7 +154,7 @@ private:
|
||||
using SourceModuleHandle = typename SourceModulesList::size_type;
|
||||
|
||||
SourceModuleHandle
|
||||
addSourceModule(std::unique_ptr<ResourceOwner<Module>> M) {
|
||||
addSourceModule(std::shared_ptr<Module> M) {
|
||||
SourceModuleHandle H = SourceModules.size();
|
||||
SourceModules.push_back(SourceModuleEntry());
|
||||
SourceModules.back().SourceMod = std::move(M);
|
||||
@ -162,7 +162,7 @@ private:
|
||||
}
|
||||
|
||||
Module& getSourceModule(SourceModuleHandle H) {
|
||||
return SourceModules[H].SourceMod->getResource();
|
||||
return *SourceModules[H].SourceMod;
|
||||
}
|
||||
|
||||
std::set<Function*>& getStubsToClone(SourceModuleHandle H) {
|
||||
@ -184,11 +184,9 @@ private:
|
||||
BaseLayer.removeModule(BLH);
|
||||
}
|
||||
|
||||
std::unique_ptr<JITSymbolResolver> ExternalSymbolResolver;
|
||||
std::unique_ptr<ResourceOwner<RuntimeDyld::MemoryManager>> MemMgr;
|
||||
std::shared_ptr<JITSymbolResolver> ExternalSymbolResolver;
|
||||
std::unique_ptr<IndirectStubsMgrT> StubsMgr;
|
||||
StaticGlobalRenamer StaticRenamer;
|
||||
ModuleAdderFtor ModuleAdder;
|
||||
SourceModulesList SourceModules;
|
||||
std::vector<BaseLayerModuleHandleT> BaseLayerHandles;
|
||||
};
|
||||
@ -196,6 +194,7 @@ private:
|
||||
using LogicalDylibList = std::list<LogicalDylib>;
|
||||
|
||||
public:
|
||||
|
||||
/// @brief Handle to loaded module.
|
||||
using ModuleHandleT = typename LogicalDylibList::iterator;
|
||||
|
||||
@ -222,27 +221,16 @@ public:
|
||||
}
|
||||
|
||||
/// @brief Add a module to the compile-on-demand layer.
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
ModuleHandleT addModule(std::shared_ptr<Module> M,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
std::shared_ptr<JITSymbolResolver> Resolver) {
|
||||
|
||||
LogicalDylibs.push_back(LogicalDylib());
|
||||
auto &LD = LogicalDylibs.back();
|
||||
LD.ExternalSymbolResolver = std::move(Resolver);
|
||||
LD.StubsMgr = CreateIndirectStubsManager();
|
||||
|
||||
auto &MemMgrRef = *MemMgr;
|
||||
LD.MemMgr = wrapOwnership<RuntimeDyld::MemoryManager>(std::move(MemMgr));
|
||||
|
||||
LD.ModuleAdder =
|
||||
[&MemMgrRef](BaseLayerT &B, std::unique_ptr<Module> M,
|
||||
std::unique_ptr<JITSymbolResolver> R) {
|
||||
return B.addModule(std::move(M), &MemMgrRef, std::move(R));
|
||||
};
|
||||
|
||||
// Process each of the modules in this module set.
|
||||
addLogicalModule(LogicalDylibs.back(), std::move(M));
|
||||
addLogicalModule(LD, std::move(M));
|
||||
|
||||
return std::prev(LogicalDylibs.end());
|
||||
}
|
||||
@ -309,8 +297,9 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename ModulePtrT>
|
||||
void addLogicalModule(LogicalDylib &LD, ModulePtrT SrcMPtr) {
|
||||
|
||||
void addLogicalModule(LogicalDylib &LD, std::shared_ptr<Module> SrcMPtr) {
|
||||
|
||||
// Rename all static functions / globals to $static.X :
|
||||
// This will unique the names across all modules in the logical dylib,
|
||||
// simplifying symbol lookup.
|
||||
@ -322,7 +311,7 @@ private:
|
||||
|
||||
// Create a logical module handle for SrcM within the logical dylib.
|
||||
Module &SrcM = *SrcMPtr;
|
||||
auto LMId = LD.addSourceModule(wrapOwnership<Module>(std::move(SrcMPtr)));
|
||||
auto LMId = LD.addSourceModule(std::move(SrcMPtr));
|
||||
|
||||
// Create stub functions.
|
||||
const DataLayout &DL = SrcM.getDataLayout();
|
||||
@ -448,8 +437,7 @@ private:
|
||||
return LD.ExternalSymbolResolver->findSymbol(Name);
|
||||
});
|
||||
|
||||
auto GVsH = LD.ModuleAdder(BaseLayer, std::move(GVsM),
|
||||
std::move(GVsResolver));
|
||||
auto GVsH = BaseLayer.addModule(std::move(GVsM), std::move(GVsResolver));
|
||||
LD.BaseLayerHandles.push_back(GVsH);
|
||||
}
|
||||
|
||||
@ -575,7 +563,7 @@ private:
|
||||
return LD.ExternalSymbolResolver->findSymbol(Name);
|
||||
});
|
||||
|
||||
return LD.ModuleAdder(BaseLayer, std::move(M), std::move(Resolver));
|
||||
return BaseLayer.addModule(std::move(M), std::move(Resolver));
|
||||
}
|
||||
|
||||
BaseLayerT &BaseLayer;
|
||||
|
@ -50,14 +50,11 @@ public:
|
||||
/// along with the given memory manager and symbol resolver.
|
||||
///
|
||||
/// @return A handle for the added module.
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
ModuleHandleT addModule(std::shared_ptr<Module> M,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
std::shared_ptr<JITSymbolResolver> Resolver) {
|
||||
using CompileResult = decltype(Compile(*M));
|
||||
auto Obj = std::make_shared<CompileResult>(Compile(*M));
|
||||
return BaseLayer.addObject(std::move(Obj), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
return BaseLayer.addObject(std::move(Obj), std::move(Resolver));
|
||||
}
|
||||
|
||||
/// @brief Remove the module associated with the handle H.
|
||||
|
@ -42,12 +42,9 @@ public:
|
||||
/// the layer below, along with the memory manager and symbol resolver.
|
||||
///
|
||||
/// @return A handle for the added modules.
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
ModuleHandleT addModule(std::shared_ptr<Module> M,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
return BaseLayer.addModule(Transform(std::move(M)), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
std::shared_ptr<JITSymbolResolver> Resolver) {
|
||||
return BaseLayer.addModule(Transform(std::move(M)), std::move(Resolver));
|
||||
}
|
||||
|
||||
/// @brief Remove the module associated with the handle H.
|
||||
|
@ -45,7 +45,7 @@ private:
|
||||
|
||||
template <typename DylibLookupFtorT,
|
||||
typename ExternalLookupFtorT>
|
||||
std::unique_ptr<LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT>>
|
||||
std::shared_ptr<LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT>>
|
||||
createLambdaResolver(DylibLookupFtorT DylibLookupFtor,
|
||||
ExternalLookupFtorT ExternalLookupFtor) {
|
||||
using LR = LambdaResolver<DylibLookupFtorT, ExternalLookupFtorT>;
|
||||
|
@ -46,8 +46,9 @@ public:
|
||||
private:
|
||||
class EmissionDeferredModule {
|
||||
public:
|
||||
EmissionDeferredModule() = default;
|
||||
virtual ~EmissionDeferredModule() = default;
|
||||
EmissionDeferredModule(std::shared_ptr<Module> M,
|
||||
std::shared_ptr<JITSymbolResolver> Resolver)
|
||||
: M(std::move(M)), Resolver(std::move(Resolver)) {}
|
||||
|
||||
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
|
||||
switch (EmitState) {
|
||||
@ -101,33 +102,10 @@ private:
|
||||
BaseLayer.emitAndFinalize(Handle);
|
||||
}
|
||||
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
static std::unique_ptr<EmissionDeferredModule>
|
||||
create(BaseLayerT &B, std::shared_ptr<Module> M, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver);
|
||||
|
||||
protected:
|
||||
virtual const GlobalValue* searchGVs(StringRef Name,
|
||||
bool ExportedSymbolsOnly) const = 0;
|
||||
virtual BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) = 0;
|
||||
|
||||
private:
|
||||
enum { NotEmitted, Emitting, Emitted } EmitState = NotEmitted;
|
||||
BaseLayerHandleT Handle;
|
||||
};
|
||||
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
class EmissionDeferredModuleImpl : public EmissionDeferredModule {
|
||||
public:
|
||||
EmissionDeferredModuleImpl(std::shared_ptr<Module> M,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver)
|
||||
: M(std::move(M)), MemMgr(std::move(MemMgr)),
|
||||
Resolver(std::move(Resolver)) {}
|
||||
|
||||
protected:
|
||||
const GlobalValue* searchGVs(StringRef Name,
|
||||
bool ExportedSymbolsOnly) const override {
|
||||
bool ExportedSymbolsOnly) const {
|
||||
// FIXME: We could clean all this up if we had a way to reliably demangle
|
||||
// names: We could just demangle name and search, rather than
|
||||
// mangling everything else.
|
||||
@ -149,15 +127,13 @@ private:
|
||||
return buildMangledSymbols(Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) override {
|
||||
BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) {
|
||||
// We don't need the mangled names set any more: Once we've emitted this
|
||||
// to the base layer we'll just look for symbols there.
|
||||
MangledSymbols.reset();
|
||||
return BaseLayer.addModule(std::move(M), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
return BaseLayer.addModule(std::move(M), std::move(Resolver));
|
||||
}
|
||||
|
||||
private:
|
||||
// If the mangled name of the given GlobalValue matches the given search
|
||||
// name (and its visibility conforms to the ExportedSymbolsOnly flag) then
|
||||
// return the symbol. Otherwise, add the mangled name to the Names map and
|
||||
@ -207,9 +183,10 @@ private:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
enum { NotEmitted, Emitting, Emitted } EmitState = NotEmitted;
|
||||
BaseLayerHandleT Handle;
|
||||
std::shared_ptr<Module> M;
|
||||
MemoryManagerPtrT MemMgr;
|
||||
SymbolResolverPtrT Resolver;
|
||||
std::shared_ptr<JITSymbolResolver> Resolver;
|
||||
mutable std::unique_ptr<StringMap<const GlobalValue*>> MangledSymbols;
|
||||
};
|
||||
|
||||
@ -219,6 +196,7 @@ private:
|
||||
ModuleListT ModuleList;
|
||||
|
||||
public:
|
||||
|
||||
/// @brief Handle to a loaded module.
|
||||
using ModuleHandleT = typename ModuleListT::iterator;
|
||||
|
||||
@ -226,15 +204,12 @@ public:
|
||||
LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
|
||||
|
||||
/// @brief Add the given module to the lazy emitting layer.
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
ModuleHandleT addModule(std::shared_ptr<Module> M,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
std::shared_ptr<JITSymbolResolver> Resolver) {
|
||||
return ModuleList.insert(
|
||||
ModuleList.end(),
|
||||
EmissionDeferredModule::create(BaseLayer, std::move(M),
|
||||
std::move(MemMgr),
|
||||
std::move(Resolver)));
|
||||
llvm::make_unique<EmissionDeferredModule>(std::move(M),
|
||||
std::move(Resolver)));
|
||||
}
|
||||
|
||||
/// @brief Remove the module represented by the given handle.
|
||||
@ -281,17 +256,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template <typename BaseLayerT>
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>::EmissionDeferredModule>
|
||||
LazyEmittingLayer<BaseLayerT>::EmissionDeferredModule::create(
|
||||
BaseLayerT &B, std::shared_ptr<Module> M, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
using EDS = EmissionDeferredModuleImpl<MemoryManagerPtrT, SymbolResolverPtrT>;
|
||||
return llvm::make_unique<EDS>(std::move(M), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
|
@ -42,12 +42,10 @@ public:
|
||||
/// memory manager and symbol resolver.
|
||||
///
|
||||
/// @return A handle for the added objects.
|
||||
template <typename ObjPtrT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ObjHandleT addObject(ObjPtrT Obj, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
return BaseLayer.addObject(Transform(std::move(Obj)), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
template <typename ObjectPtr>
|
||||
ObjHandleT addObject(ObjectPtr Obj,
|
||||
std::shared_ptr<JITSymbolResolver> Resolver) {
|
||||
return BaseLayer.addObject(Transform(std::move(Obj)), std::move(Resolver));
|
||||
}
|
||||
|
||||
/// @brief Remove the object set associated with the handle H.
|
||||
|
@ -228,13 +228,20 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
/// @brief Functor for creating memory managers.
|
||||
using MemoryManagerGetter =
|
||||
std::function<std::shared_ptr<RuntimeDyld::MemoryManager>()>;
|
||||
|
||||
/// @brief Construct an ObjectLinkingLayer with the given NotifyLoaded,
|
||||
/// and NotifyFinalized functors.
|
||||
RTDyldObjectLinkingLayer(
|
||||
MemoryManagerGetter GetMemMgr,
|
||||
NotifyLoadedFtor NotifyLoaded = NotifyLoadedFtor(),
|
||||
NotifyFinalizedFtor NotifyFinalized = NotifyFinalizedFtor())
|
||||
: NotifyLoaded(std::move(NotifyLoaded)),
|
||||
NotifyFinalized(std::move(NotifyFinalized)) {}
|
||||
: GetMemMgr(GetMemMgr),
|
||||
NotifyLoaded(std::move(NotifyLoaded)),
|
||||
NotifyFinalized(std::move(NotifyFinalized)),
|
||||
ProcessAllSections(false) {}
|
||||
|
||||
/// @brief Set the 'ProcessAllSections' flag.
|
||||
///
|
||||
@ -251,12 +258,8 @@ public:
|
||||
///
|
||||
/// @return A handle that can be used to refer to the loaded objects (for
|
||||
/// symbol searching, finalization, freeing memory, etc.).
|
||||
template <typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ObjHandleT addObject(ObjectPtr Obj,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
|
||||
std::shared_ptr<JITSymbolResolver> Resolver) {
|
||||
auto Finalizer = [&](ObjHandleT H, RuntimeDyld &RTDyld,
|
||||
const ObjectPtr &ObjToLoad,
|
||||
std::function<void()> LOSHandleLoad) {
|
||||
@ -275,8 +278,9 @@ public:
|
||||
};
|
||||
|
||||
auto LO =
|
||||
createLinkedObject(std::move(Obj), std::move(MemMgr), std::move(Resolver),
|
||||
std::move(Finalizer), ProcessAllSections);
|
||||
createLinkedObject(std::move(Obj), GetMemMgr(),
|
||||
std::move(Resolver), std::move(Finalizer),
|
||||
ProcessAllSections);
|
||||
// LOS is an owning-ptr. Keep a non-owning one so that we can set the handle
|
||||
// below.
|
||||
auto *LOPtr = LO.get();
|
||||
@ -341,6 +345,7 @@ public:
|
||||
private:
|
||||
|
||||
LinkedObjectListT LinkedObjList;
|
||||
MemoryManagerGetter GetMemMgr;
|
||||
NotifyLoadedFtor NotifyLoaded;
|
||||
NotifyFinalizedFtor NotifyFinalized;
|
||||
bool ProcessAllSections = false;
|
||||
|
@ -105,6 +105,10 @@ public:
|
||||
IndirectStubsManagerBuilder IndirectStubsMgrBuilder)
|
||||
: DL(TM.createDataLayout()), IndirectStubsMgr(IndirectStubsMgrBuilder()),
|
||||
CCMgr(std::move(CCMgr)),
|
||||
ObjectLayer(
|
||||
[]() {
|
||||
return std::make_shared<SectionMemoryManager>();
|
||||
}),
|
||||
CompileLayer(ObjectLayer, orc::SimpleCompiler(TM)),
|
||||
CODLayer(CompileLayer,
|
||||
[](Function &F) { return std::set<Function *>({&F}); },
|
||||
@ -155,7 +159,7 @@ public:
|
||||
return mapError(IndirectStubsMgr->updatePointer(Name, Addr));
|
||||
}
|
||||
|
||||
std::unique_ptr<JITSymbolResolver>
|
||||
std::shared_ptr<JITSymbolResolver>
|
||||
createResolver(LLVMOrcSymbolResolverFn ExternalResolver,
|
||||
void *ExternalResolverCtx) {
|
||||
return orc::createLambdaResolver(
|
||||
@ -204,8 +208,7 @@ public:
|
||||
auto Resolver = createResolver(ExternalResolver, ExternalResolverCtx);
|
||||
|
||||
// Add the module to the JIT.
|
||||
auto LH = Layer.addModule(std::move(M), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
auto LH = Layer.addModule(std::move(M), std::move(Resolver));
|
||||
ModuleHandleT H = createHandle(Layer, LH);
|
||||
|
||||
// Run the static constructors, and save the static destructor runner for
|
||||
|
@ -172,10 +172,13 @@ public:
|
||||
std::shared_ptr<JITSymbolResolver> ClientResolver,
|
||||
std::unique_ptr<TargetMachine> TM)
|
||||
: ExecutionEngine(TM->createDataLayout()), TM(std::move(TM)),
|
||||
MemMgr(*this, std::move(MemMgr)), Resolver(*this),
|
||||
MemMgr(std::make_shared<MCJITReplacementMemMgr>(*this,
|
||||
std::move(MemMgr))),
|
||||
Resolver(std::make_shared<LinkingResolver>(*this)),
|
||||
ClientResolver(std::move(ClientResolver)), NotifyObjectLoaded(*this),
|
||||
NotifyFinalized(*this),
|
||||
ObjectLayer(NotifyObjectLoaded, NotifyFinalized),
|
||||
ObjectLayer([this]() { return this->MemMgr; }, NotifyObjectLoaded,
|
||||
NotifyFinalized),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*this->TM)),
|
||||
LazyEmitLayer(CompileLayer) {}
|
||||
|
||||
@ -199,20 +202,20 @@ public:
|
||||
delete Mod;
|
||||
};
|
||||
LocalModules.push_back(std::shared_ptr<Module>(MPtr, std::move(Deleter)));
|
||||
LazyEmitLayer.addModule(LocalModules.back(), &MemMgr, &Resolver);
|
||||
LazyEmitLayer.addModule(LocalModules.back(), Resolver);
|
||||
}
|
||||
|
||||
void addObjectFile(std::unique_ptr<object::ObjectFile> O) override {
|
||||
auto Obj =
|
||||
std::make_shared<object::OwningBinary<object::ObjectFile>>(std::move(O),
|
||||
nullptr);
|
||||
ObjectLayer.addObject(std::move(Obj), &MemMgr, &Resolver);
|
||||
ObjectLayer.addObject(std::move(Obj), Resolver);
|
||||
}
|
||||
|
||||
void addObjectFile(object::OwningBinary<object::ObjectFile> O) override {
|
||||
auto Obj =
|
||||
std::make_shared<object::OwningBinary<object::ObjectFile>>(std::move(O));
|
||||
ObjectLayer.addObject(std::move(Obj), &MemMgr, &Resolver);
|
||||
ObjectLayer.addObject(std::move(Obj), Resolver);
|
||||
}
|
||||
|
||||
void addArchive(object::OwningBinary<object::Archive> A) override {
|
||||
@ -320,7 +323,7 @@ private:
|
||||
auto Obj =
|
||||
std::make_shared<object::OwningBinary<object::ObjectFile>>(
|
||||
std::move(ChildObj), nullptr);
|
||||
ObjectLayer.addObject(std::move(Obj), &MemMgr, &Resolver);
|
||||
ObjectLayer.addObject(std::move(Obj), Resolver);
|
||||
if (auto Sym = ObjectLayer.findSymbol(Name, true))
|
||||
return Sym;
|
||||
}
|
||||
@ -341,7 +344,7 @@ private:
|
||||
const LoadedObjectInfo &Info) const {
|
||||
M.UnfinalizedSections[H] = std::move(M.SectionsAllocatedSinceLastLoad);
|
||||
M.SectionsAllocatedSinceLastLoad = SectionAddrSet();
|
||||
M.MemMgr.notifyObjectLoaded(&M, *Obj->getBinary());
|
||||
M.MemMgr->notifyObjectLoaded(&M, *Obj->getBinary());
|
||||
}
|
||||
private:
|
||||
OrcMCJITReplacement &M;
|
||||
@ -373,8 +376,8 @@ private:
|
||||
using LazyEmitLayerT = LazyEmittingLayer<CompileLayerT>;
|
||||
|
||||
std::unique_ptr<TargetMachine> TM;
|
||||
MCJITReplacementMemMgr MemMgr;
|
||||
LinkingResolver Resolver;
|
||||
std::shared_ptr<MCJITReplacementMemMgr> MemMgr;
|
||||
std::shared_ptr<LinkingResolver> Resolver;
|
||||
std::shared_ptr<JITSymbolResolver> ClientResolver;
|
||||
Mangler Mang;
|
||||
|
||||
|
@ -61,7 +61,8 @@ public:
|
||||
IndirectStubsManagerBuilder IndirectStubsMgrBuilder,
|
||||
bool InlineStubs)
|
||||
: TM(std::move(TM)), DL(this->TM->createDataLayout()),
|
||||
CCMgr(std::move(CCMgr)),
|
||||
CCMgr(std::move(CCMgr)),
|
||||
ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
|
||||
CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
|
||||
IRDumpLayer(CompileLayer, createDebugDumper()),
|
||||
CODLayer(IRDumpLayer, extractSingleFunction, *this->CCMgr,
|
||||
@ -125,9 +126,7 @@ public:
|
||||
|
||||
// Add the module to the JIT.
|
||||
ModulesHandle =
|
||||
CODLayer.addModule(std::move(M),
|
||||
llvm::make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
CODLayer.addModule(std::move(M), std::move(Resolver));
|
||||
} else
|
||||
CODLayer.addExtraModule(ModulesHandle, std::move(M));
|
||||
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
this->MemMgr = std::move(MemMgr);
|
||||
}
|
||||
|
||||
void setResolver(std::unique_ptr<JITSymbolResolver> Resolver) {
|
||||
void setResolver(std::shared_ptr<JITSymbolResolver> Resolver) {
|
||||
this->Resolver = std::move(Resolver);
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr;
|
||||
std::unique_ptr<JITSymbolResolver> Resolver;
|
||||
std::shared_ptr<JITSymbolResolver> Resolver;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ struct MockBaseLayer {
|
||||
TEST(LazyEmittingLayerTest, Empty) {
|
||||
MockBaseLayer M;
|
||||
llvm::orc::LazyEmittingLayer<MockBaseLayer> L(M);
|
||||
L.addModule(std::unique_ptr<llvm::Module>(), nullptr, nullptr);
|
||||
L.addModule(std::unique_ptr<llvm::Module>(), nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/NullResolver.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -21,12 +22,6 @@ using namespace llvm::orc;
|
||||
|
||||
namespace {
|
||||
|
||||
// Stand-in for RuntimeDyld::MemoryManager
|
||||
typedef int MockMemoryManager;
|
||||
|
||||
// Stand-in for RuntimeDyld::SymbolResolver
|
||||
typedef int MockSymbolResolver;
|
||||
|
||||
// stand-in for object::ObjectFile
|
||||
typedef int MockObjectFile;
|
||||
|
||||
@ -54,24 +49,24 @@ public:
|
||||
|
||||
MockBaseLayer() : MockSymbol(nullptr) { resetExpectations(); }
|
||||
|
||||
template <typename ObjPtrT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ObjHandleT addObject(ObjPtrT Obj, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
EXPECT_EQ(MockManager, *MemMgr) << "MM should pass through";
|
||||
EXPECT_EQ(MockResolver, *Resolver) << "Resolver should pass through";
|
||||
template <typename ObjPtrT>
|
||||
ObjHandleT addObject(ObjPtrT Obj,
|
||||
std::shared_ptr<llvm::JITSymbolResolver> Resolver) {
|
||||
EXPECT_EQ(MockResolver, Resolver) << "Resolver should pass through";
|
||||
EXPECT_EQ(MockObject + 1, *Obj) << "Transform should be applied";
|
||||
LastCalled = "addObject";
|
||||
MockObjHandle = 111;
|
||||
return MockObjHandle;
|
||||
}
|
||||
|
||||
template <typename ObjPtrT>
|
||||
void expectAddObject(ObjPtrT Obj, MockMemoryManager *MemMgr,
|
||||
MockSymbolResolver *Resolver) {
|
||||
MockManager = *MemMgr;
|
||||
MockResolver = *Resolver;
|
||||
void expectAddObject(ObjPtrT Obj,
|
||||
std::shared_ptr<llvm::JITSymbolResolver> Resolver) {
|
||||
MockResolver = Resolver;
|
||||
MockObject = *Obj;
|
||||
}
|
||||
|
||||
|
||||
void verifyAddObject(ObjHandleT Returned) {
|
||||
EXPECT_EQ("addObject", LastCalled);
|
||||
EXPECT_EQ(MockObjHandle, Returned) << "Return should pass through";
|
||||
@ -160,8 +155,7 @@ public:
|
||||
private:
|
||||
// Backing fields for remembering parameter/return values
|
||||
std::string LastCalled;
|
||||
MockMemoryManager MockManager;
|
||||
MockSymbolResolver MockResolver;
|
||||
std::shared_ptr<llvm::JITSymbolResolver> MockResolver;
|
||||
MockObjectFile MockObject;
|
||||
ObjHandleT MockObjHandle;
|
||||
std::string MockName;
|
||||
@ -174,8 +168,7 @@ private:
|
||||
// Clear remembered parameters between calls
|
||||
void resetExpectations() {
|
||||
LastCalled = "nothing";
|
||||
MockManager = 0;
|
||||
MockResolver = 0;
|
||||
MockResolver = nullptr;
|
||||
MockObject = 0;
|
||||
MockObjHandle = 0;
|
||||
MockName = "bogus";
|
||||
@ -204,22 +197,17 @@ TEST(ObjectTransformLayerTest, Main) {
|
||||
return Obj;
|
||||
});
|
||||
|
||||
// Instantiate some mock objects to use below
|
||||
MockMemoryManager MockManager = 233;
|
||||
MockSymbolResolver MockResolver = 244;
|
||||
|
||||
// Test addObject with T1 (allocating)
|
||||
auto Obj1 = std::make_shared<MockObjectFile>(211);
|
||||
auto MM = llvm::make_unique<MockMemoryManager>(MockManager);
|
||||
auto SR = llvm::make_unique<MockSymbolResolver>(MockResolver);
|
||||
M.expectAddObject(Obj1, MM.get(), SR.get());
|
||||
auto H = T1.addObject(std::move(Obj1), std::move(MM), std::move(SR));
|
||||
auto SR = std::make_shared<NullResolver>();
|
||||
M.expectAddObject(Obj1, SR);
|
||||
auto H = T1.addObject(std::move(Obj1), SR);
|
||||
M.verifyAddObject(H);
|
||||
|
||||
// Test addObjectSet with T2 (mutating)
|
||||
auto Obj2 = std::make_shared<MockObjectFile>(222);
|
||||
M.expectAddObject(Obj2, &MockManager, &MockResolver);
|
||||
H = T2.addObject(Obj2, &MockManager, &MockResolver);
|
||||
M.expectAddObject(Obj2, SR);
|
||||
H = T2.addObject(Obj2, SR);
|
||||
M.verifyAddObject(H);
|
||||
EXPECT_EQ(223, *Obj2) << "Expected mutation";
|
||||
|
||||
@ -295,7 +283,11 @@ TEST(ObjectTransformLayerTest, Main) {
|
||||
};
|
||||
|
||||
// Construct the jit layers.
|
||||
RTDyldObjectLinkingLayer BaseLayer;
|
||||
RTDyldObjectLinkingLayer BaseLayer(
|
||||
[]() {
|
||||
return std::make_shared<llvm::SectionMemoryManager>();
|
||||
});
|
||||
|
||||
auto IdentityTransform =
|
||||
[](std::shared_ptr<llvm::object::OwningBinary<llvm::object::ObjectFile>>
|
||||
Obj) {
|
||||
@ -312,9 +304,8 @@ TEST(ObjectTransformLayerTest, Main) {
|
||||
|
||||
// Make sure that the calls from IRCompileLayer to ObjectTransformLayer
|
||||
// compile.
|
||||
NullResolver Resolver;
|
||||
NullManager Manager;
|
||||
CompileLayer.addModule(std::shared_ptr<llvm::Module>(), &Manager, &Resolver);
|
||||
auto Resolver = std::make_shared<NullResolver>();
|
||||
CompileLayer.addModule(std::shared_ptr<llvm::Module>(), Resolver);
|
||||
|
||||
// Make sure that the calls from ObjectTransformLayer to ObjectLinkingLayer
|
||||
// compile.
|
||||
|
@ -45,9 +45,9 @@ public:
|
||||
};
|
||||
|
||||
TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
|
||||
class SectionMemoryManagerWrapper : public SectionMemoryManager {
|
||||
class MemoryManagerWrapper : public SectionMemoryManager {
|
||||
public:
|
||||
SectionMemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {}
|
||||
MemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {}
|
||||
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
|
||||
unsigned SectionID,
|
||||
StringRef SectionName,
|
||||
@ -63,7 +63,10 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
|
||||
bool &DebugSeen;
|
||||
};
|
||||
|
||||
RTDyldObjectLinkingLayer ObjLayer;
|
||||
bool DebugSectionSeen = false;
|
||||
auto MM = std::make_shared<MemoryManagerWrapper>(DebugSectionSeen);
|
||||
|
||||
RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
|
||||
|
||||
LLVMContext Context;
|
||||
auto M = llvm::make_unique<Module>("", Context);
|
||||
@ -89,9 +92,6 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
|
||||
std::make_shared<object::OwningBinary<object::ObjectFile>>(
|
||||
SimpleCompiler(*TM)(*M));
|
||||
|
||||
bool DebugSectionSeen = false;
|
||||
auto SMMW =
|
||||
std::make_shared<SectionMemoryManagerWrapper>(DebugSectionSeen);
|
||||
auto Resolver =
|
||||
createLambdaResolver(
|
||||
[](const std::string &Name) {
|
||||
@ -103,7 +103,7 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
|
||||
|
||||
{
|
||||
// Test with ProcessAllSections = false (the default).
|
||||
auto H = ObjLayer.addObject(Obj, SMMW, &*Resolver);
|
||||
auto H = ObjLayer.addObject(Obj, Resolver);
|
||||
ObjLayer.emitAndFinalize(H);
|
||||
EXPECT_EQ(DebugSectionSeen, false)
|
||||
<< "Unexpected debug info section";
|
||||
@ -113,7 +113,7 @@ TEST(RTDyldObjectLinkingLayerTest, TestSetProcessAllSections) {
|
||||
{
|
||||
// Test with ProcessAllSections = true.
|
||||
ObjLayer.setProcessAllSections(true);
|
||||
auto H = ObjLayer.addObject(Obj, SMMW, &*Resolver);
|
||||
auto H = ObjLayer.addObject(Obj, Resolver);
|
||||
ObjLayer.emitAndFinalize(H);
|
||||
EXPECT_EQ(DebugSectionSeen, true)
|
||||
<< "Expected debug info section not seen";
|
||||
@ -125,7 +125,9 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
|
||||
if (!TM)
|
||||
return;
|
||||
|
||||
RTDyldObjectLinkingLayer ObjLayer;
|
||||
auto MM = std::make_shared<SectionMemoryManagerWrapper>();
|
||||
|
||||
RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
|
||||
SimpleCompiler Compile(*TM);
|
||||
|
||||
// Create a pair of modules that will trigger recursive finalization:
|
||||
@ -179,15 +181,14 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
|
||||
return JITSymbol(nullptr);
|
||||
});
|
||||
|
||||
auto SMMW = std::make_shared<SectionMemoryManagerWrapper>();
|
||||
ObjLayer.addObject(std::move(Obj1), SMMW, &*Resolver);
|
||||
auto H = ObjLayer.addObject(std::move(Obj2), SMMW, &*Resolver);
|
||||
ObjLayer.addObject(std::move(Obj1), Resolver);
|
||||
auto H = ObjLayer.addObject(std::move(Obj2), Resolver);
|
||||
ObjLayer.emitAndFinalize(H);
|
||||
ObjLayer.removeObject(H);
|
||||
|
||||
// Finalization of module 2 should trigger finalization of module 1.
|
||||
// Verify that finalize on SMMW is only called once.
|
||||
EXPECT_EQ(SMMW->FinalizationCount, 1)
|
||||
EXPECT_EQ(MM->FinalizationCount, 1)
|
||||
<< "Extra call to finalize";
|
||||
}
|
||||
|
||||
@ -195,7 +196,9 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
|
||||
if (!TM)
|
||||
return;
|
||||
|
||||
RTDyldObjectLinkingLayer ObjLayer;
|
||||
auto MM = std::make_shared<SectionMemoryManagerWrapper>();
|
||||
|
||||
RTDyldObjectLinkingLayer ObjLayer([&MM]() { return MM; });
|
||||
SimpleCompiler Compile(*TM);
|
||||
|
||||
// Create a pair of unrelated modules:
|
||||
@ -240,15 +243,14 @@ TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
|
||||
std::make_shared<object::OwningBinary<object::ObjectFile>>(
|
||||
Compile(*MB2.getModule()));
|
||||
|
||||
auto SMMW = std::make_shared<SectionMemoryManagerWrapper>();
|
||||
NullResolver NR;
|
||||
auto H = ObjLayer.addObject(std::move(Obj1), SMMW, &NR);
|
||||
ObjLayer.addObject(std::move(Obj2), SMMW, &NR);
|
||||
auto NR = std::make_shared<NullResolver>();
|
||||
auto H = ObjLayer.addObject(std::move(Obj1), NR);
|
||||
ObjLayer.addObject(std::move(Obj2), NR);
|
||||
ObjLayer.emitAndFinalize(H);
|
||||
ObjLayer.removeObject(H);
|
||||
|
||||
// Only one call to needsToReserveAllocationSpace should have been made.
|
||||
EXPECT_EQ(SMMW->NeedsToReserveAllocationSpaceCount, 1)
|
||||
EXPECT_EQ(MM->NeedsToReserveAllocationSpaceCount, 1)
|
||||
<< "More than one call to needsToReserveAllocationSpace "
|
||||
"(multiple unrelated objects loaded prior to finalization)";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user