forked from OSchip/llvm-project
This reverts commit r306166 and r306168.
Revert "[ORC] Remove redundant semicolons from DEFINE_SIMPLE_CONVERSION_FUNCTIONS uses." Revert "[ORC] Move ORC IR layer interface from addModuleSet to addModule and fix the module type as std::shared_ptr<Module>." They broke ExecutionEngine/OrcMCJIT/test-global-ctors.ll on linux. llvm-svn: 306176
This commit is contained in:
parent
33d501f7d1
commit
f6242c3e90
|
@ -44,7 +44,7 @@ private:
|
|||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||
|
||||
public:
|
||||
using ModuleHandle = decltype(CompileLayer)::ModuleHandleT;
|
||||
using ModuleHandle = decltype(CompileLayer)::ModuleSetHandleT;
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
|
@ -72,11 +72,15 @@ public:
|
|||
return JITSymbol(nullptr);
|
||||
});
|
||||
|
||||
// Build a singleton module set to hold our module.
|
||||
std::vector<std::unique_ptr<Module>> Ms;
|
||||
Ms.push_back(std::move(M));
|
||||
|
||||
// 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));
|
||||
return CompileLayer.addModuleSet(std::move(Ms),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
JITSymbol findSymbol(const std::string Name) {
|
||||
|
@ -87,7 +91,7 @@ public:
|
|||
}
|
||||
|
||||
void removeModule(ModuleHandle H) {
|
||||
CompileLayer.removeModule(H);
|
||||
CompileLayer.removeModuleSet(H);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -48,18 +48,18 @@ private:
|
|||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||
|
||||
using OptimizeFunction =
|
||||
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
||||
|
||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||
|
||||
public:
|
||||
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT;
|
||||
using ModuleHandle = decltype(OptimizeLayer)::ModuleSetHandleT;
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
[this](std::unique_ptr<Module> M) {
|
||||
return optimizeModule(std::move(M));
|
||||
}) {
|
||||
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
|
||||
|
@ -85,11 +85,15 @@ public:
|
|||
return JITSymbol(nullptr);
|
||||
});
|
||||
|
||||
// Build a singleton module set to hold our module.
|
||||
std::vector<std::unique_ptr<Module>> Ms;
|
||||
Ms.push_back(std::move(M));
|
||||
|
||||
// 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));
|
||||
return OptimizeLayer.addModuleSet(std::move(Ms),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
JITSymbol findSymbol(const std::string Name) {
|
||||
|
@ -100,11 +104,11 @@ public:
|
|||
}
|
||||
|
||||
void removeModule(ModuleHandle H) {
|
||||
OptimizeLayer.removeModule(H);
|
||||
OptimizeLayer.removeModuleSet(H);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Module> optimizeModule(std::shared_ptr<Module> M) {
|
||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
||||
// Create a function pass manager.
|
||||
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||
|
||||
using OptimizeFunction =
|
||||
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
||||
|
||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||
|
||||
|
@ -59,13 +59,13 @@ private:
|
|||
CompileOnDemandLayer<decltype(OptimizeLayer)> CODLayer;
|
||||
|
||||
public:
|
||||
using ModuleHandle = decltype(CODLayer)::ModuleHandleT;
|
||||
using ModuleHandle = decltype(CODLayer)::ModuleSetHandleT;
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
[this](std::unique_ptr<Module> M) {
|
||||
return optimizeModule(std::move(M));
|
||||
}),
|
||||
CompileCallbackManager(
|
||||
|
@ -98,11 +98,15 @@ public:
|
|||
return JITSymbol(nullptr);
|
||||
});
|
||||
|
||||
// Build a singleton module set to hold our module.
|
||||
std::vector<std::unique_ptr<Module>> Ms;
|
||||
Ms.push_back(std::move(M));
|
||||
|
||||
// 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));
|
||||
return CODLayer.addModuleSet(std::move(Ms),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
JITSymbol findSymbol(const std::string Name) {
|
||||
|
@ -113,11 +117,11 @@ public:
|
|||
}
|
||||
|
||||
void removeModule(ModuleHandle H) {
|
||||
CODLayer.removeModule(H);
|
||||
CODLayer.removeModuleSet(H);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Module> optimizeModule(std::shared_ptr<Module> M) {
|
||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
||||
// Create a function pass manager.
|
||||
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ private:
|
|||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||
|
||||
using OptimizeFunction =
|
||||
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
||||
|
||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||
|
||||
|
@ -85,14 +85,14 @@ private:
|
|||
std::unique_ptr<IndirectStubsManager> IndirectStubsMgr;
|
||||
|
||||
public:
|
||||
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT;
|
||||
using ModuleHandle = decltype(OptimizeLayer)::ModuleSetHandleT;
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()),
|
||||
DL(TM->createDataLayout()),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
[this](std::unique_ptr<Module> M) {
|
||||
return optimizeModule(std::move(M));
|
||||
}),
|
||||
CompileCallbackMgr(
|
||||
|
@ -125,11 +125,15 @@ public:
|
|||
return JITSymbol(nullptr);
|
||||
});
|
||||
|
||||
// Build a singleton module set to hold our module.
|
||||
std::vector<std::unique_ptr<Module>> Ms;
|
||||
Ms.push_back(std::move(M));
|
||||
|
||||
// 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));
|
||||
return OptimizeLayer.addModuleSet(std::move(Ms),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
|
||||
|
@ -195,7 +199,7 @@ public:
|
|||
}
|
||||
|
||||
void removeModule(ModuleHandle H) {
|
||||
OptimizeLayer.removeModule(H);
|
||||
OptimizeLayer.removeModuleSet(H);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -206,7 +210,7 @@ private:
|
|||
return MangledNameStream.str();
|
||||
}
|
||||
|
||||
std::shared_ptr<Module> optimizeModule(std::shared_ptr<Module> M) {
|
||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
||||
// Create a function pass manager.
|
||||
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ private:
|
|||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||
|
||||
using OptimizeFunction =
|
||||
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
||||
|
||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||
|
||||
|
@ -91,7 +91,7 @@ private:
|
|||
MyRemote &Remote;
|
||||
|
||||
public:
|
||||
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT;
|
||||
using ModuleHandle = decltype(OptimizeLayer)::ModuleSetHandleT;
|
||||
|
||||
KaleidoscopeJIT(MyRemote &Remote)
|
||||
: TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "",
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
DL(TM->createDataLayout()),
|
||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||
OptimizeLayer(CompileLayer,
|
||||
[this](std::shared_ptr<Module> M) {
|
||||
[this](std::unique_ptr<Module> M) {
|
||||
return optimizeModule(std::move(M));
|
||||
}),
|
||||
Remote(Remote) {
|
||||
|
@ -153,11 +153,15 @@ public:
|
|||
exit(1);
|
||||
}
|
||||
|
||||
// Build a singleton module set to hold our module.
|
||||
std::vector<std::unique_ptr<Module>> Ms;
|
||||
Ms.push_back(std::move(M));
|
||||
|
||||
// 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));
|
||||
return OptimizeLayer.addModuleSet(std::move(Ms),
|
||||
std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
|
||||
|
@ -227,7 +231,7 @@ public:
|
|||
}
|
||||
|
||||
void removeModule(ModuleHandle H) {
|
||||
OptimizeLayer.removeModule(H);
|
||||
OptimizeLayer.removeModuleSet(H);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -238,7 +242,7 @@ private:
|
|||
return MangledNameStream.str();
|
||||
}
|
||||
|
||||
std::shared_ptr<Module> optimizeModule(std::shared_ptr<Module> M) {
|
||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
||||
// Create a function pass manager.
|
||||
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class KaleidoscopeJIT {
|
|||
public:
|
||||
using ObjLayerT = RTDyldObjectLinkingLayer;
|
||||
using CompileLayerT = IRCompileLayer<ObjLayerT, SimpleCompiler>;
|
||||
using ModuleHandleT = CompileLayerT::ModuleHandleT;
|
||||
using ModuleHandleT = CompileLayerT::ModuleSetHandleT;
|
||||
|
||||
KaleidoscopeJIT()
|
||||
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
|
||||
|
@ -62,9 +62,9 @@ public:
|
|||
return JITSymbol(nullptr);
|
||||
},
|
||||
[](const std::string &S) { return nullptr; });
|
||||
auto H = CompileLayer.addModule(std::move(M),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
auto H = CompileLayer.addModuleSet(singletonSet(std::move(M)),
|
||||
make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
|
||||
ModuleHandles.push_back(H);
|
||||
return H;
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
|
||||
void removeModule(ModuleHandleT H) {
|
||||
ModuleHandles.erase(find(ModuleHandles, H));
|
||||
CompileLayer.removeModule(H);
|
||||
CompileLayer.removeModuleSet(H);
|
||||
}
|
||||
|
||||
JITSymbol findSymbol(const std::string Name) {
|
||||
|
@ -89,6 +89,12 @@ private:
|
|||
return MangledName;
|
||||
}
|
||||
|
||||
template <typename T> static std::vector<T> singletonSet(T t) {
|
||||
std::vector<T> Vec;
|
||||
Vec.push_back(std::move(t));
|
||||
return Vec;
|
||||
}
|
||||
|
||||
JITSymbol findMangledSymbol(const std::string &Name) {
|
||||
#ifdef LLVM_ON_WIN32
|
||||
// The symbol lookup of ObjectLinkingLayer uses the SymbolRef::SF_Exported
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct LLVMOpaqueSharedModule *LLVMSharedModuleRef;
|
||||
typedef struct LLVMOpaqueSharedObjectBuffer *LLVMSharedObjectBufferRef;
|
||||
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
|
||||
typedef uint32_t LLVMOrcModuleHandle;
|
||||
typedef uint64_t LLVMOrcTargetAddress;
|
||||
|
@ -40,45 +38,6 @@ typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
|
|||
|
||||
typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
|
||||
|
||||
/**
|
||||
* Turn an LLVMModuleRef into an LLVMSharedModuleRef.
|
||||
*
|
||||
* The JIT uses shared ownership for LLVM modules, since it is generally
|
||||
* difficult to know when the JIT will be finished with a module (and the JIT
|
||||
* has no way of knowing when a user may be finished with one).
|
||||
*
|
||||
* Calling this method with an LLVMModuleRef creates a shared-pointer to the
|
||||
* module, and returns a reference to this shared pointer.
|
||||
*
|
||||
* The shared module should be disposed when finished with by calling
|
||||
* LLVMOrcDisposeSharedModule (not LLVMDisposeModule). The Module will be
|
||||
* deleted when the last shared pointer owner relinquishes it.
|
||||
*/
|
||||
|
||||
LLVMSharedModuleRef LLVMOrcMakeSharedModule(LLVMModuleRef Mod);
|
||||
|
||||
/**
|
||||
* Dispose of a shared module.
|
||||
*
|
||||
* The module should not be accessed after this call. The module will be
|
||||
* deleted once all clients (including the JIT itself) have released their
|
||||
* shared pointers.
|
||||
*/
|
||||
|
||||
void LLVMOrcDisposeSharedModuleRef(LLVMSharedModuleRef SharedMod);
|
||||
|
||||
/**
|
||||
* Get an LLVMSharedObjectBufferRef from an LLVMMemoryBufferRef.
|
||||
*/
|
||||
LLVMSharedObjectBufferRef
|
||||
LLVMOrcMakeSharedObjectBuffer(LLVMMemoryBufferRef ObjBuffer);
|
||||
|
||||
/**
|
||||
* Dispose of a shared object buffer.
|
||||
*/
|
||||
void
|
||||
LLVMOrcDisposeSharedObjectBufferRef(LLVMSharedObjectBufferRef SharedObjBuffer);
|
||||
|
||||
/**
|
||||
* Create an ORC JIT stack.
|
||||
*
|
||||
|
@ -136,8 +95,7 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
|
|||
* Add module to be eagerly compiled.
|
||||
*/
|
||||
LLVMOrcModuleHandle
|
||||
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||
LLVMSharedModuleRef Mod,
|
||||
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
|
||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||
void *SymbolResolverCtx);
|
||||
|
||||
|
@ -145,8 +103,7 @@ LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
|||
* Add module to be lazily compiled one function at a time.
|
||||
*/
|
||||
LLVMOrcModuleHandle
|
||||
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||
LLVMSharedModuleRef Mod,
|
||||
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
|
||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||
void *SymbolResolverCtx);
|
||||
|
||||
|
@ -154,7 +111,7 @@ LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
|||
* Add an object file.
|
||||
*/
|
||||
LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
|
||||
LLVMSharedObjectBufferRef Obj,
|
||||
LLVMObjectFileRef Obj,
|
||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||
void *SymbolResolverCtx);
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ private:
|
|||
return LambdaMaterializer<MaterializerFtor>(std::move(M));
|
||||
}
|
||||
|
||||
using BaseLayerModuleHandleT = typename BaseLayerT::ModuleHandleT;
|
||||
using BaseLayerModuleSetHandleT = typename BaseLayerT::ModuleSetHandleT;
|
||||
|
||||
// Provide type-erasure for the Modules and MemoryManagers.
|
||||
template <typename ResourceT>
|
||||
|
@ -139,11 +139,9 @@ private:
|
|||
struct LogicalDylib {
|
||||
using SymbolResolverFtor = std::function<JITSymbol(const std::string&)>;
|
||||
|
||||
using ModuleAdderFtor =
|
||||
std::function<typename BaseLayerT::ModuleHandleT(
|
||||
BaseLayerT&,
|
||||
std::unique_ptr<Module>,
|
||||
std::unique_ptr<JITSymbolResolver>)>;
|
||||
using ModuleAdderFtor = std::function<typename BaseLayerT::ModuleSetHandleT(
|
||||
BaseLayerT &, std::unique_ptr<Module>,
|
||||
std::unique_ptr<JITSymbolResolver>)>;
|
||||
|
||||
struct SourceModuleEntry {
|
||||
std::unique_ptr<ResourceOwner<Module>> SourceMod;
|
||||
|
@ -181,7 +179,7 @@ private:
|
|||
|
||||
void removeModulesFromBaseLayer(BaseLayerT &BaseLayer) {
|
||||
for (auto &BLH : BaseLayerHandles)
|
||||
BaseLayer.removeModule(BLH);
|
||||
BaseLayer.removeModuleSet(BLH);
|
||||
}
|
||||
|
||||
std::unique_ptr<JITSymbolResolver> ExternalSymbolResolver;
|
||||
|
@ -190,14 +188,14 @@ private:
|
|||
StaticGlobalRenamer StaticRenamer;
|
||||
ModuleAdderFtor ModuleAdder;
|
||||
SourceModulesList SourceModules;
|
||||
std::vector<BaseLayerModuleHandleT> BaseLayerHandles;
|
||||
std::vector<BaseLayerModuleSetHandleT> BaseLayerHandles;
|
||||
};
|
||||
|
||||
using LogicalDylibList = std::list<LogicalDylib>;
|
||||
|
||||
public:
|
||||
/// @brief Handle to loaded module.
|
||||
using ModuleHandleT = typename LogicalDylibList::iterator;
|
||||
/// @brief Handle to a set of loaded modules.
|
||||
using ModuleSetHandleT = typename LogicalDylibList::iterator;
|
||||
|
||||
/// @brief Module partitioning functor.
|
||||
using PartitioningFtor = std::function<std::set<Function*>(Function&)>;
|
||||
|
@ -218,15 +216,15 @@ public:
|
|||
|
||||
~CompileOnDemandLayer() {
|
||||
while (!LogicalDylibs.empty())
|
||||
removeModule(LogicalDylibs.begin());
|
||||
removeModuleSet(LogicalDylibs.begin());
|
||||
}
|
||||
|
||||
/// @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) {
|
||||
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ModuleSetHandleT addModuleSet(ModuleSetT Ms,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
LogicalDylibs.push_back(LogicalDylib());
|
||||
auto &LD = LogicalDylibs.back();
|
||||
LD.ExternalSymbolResolver = std::move(Resolver);
|
||||
|
@ -238,25 +236,23 @@ public:
|
|||
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));
|
||||
std::vector<std::unique_ptr<Module>> Ms;
|
||||
Ms.push_back(std::move(M));
|
||||
return B.addModuleSet(std::move(Ms), &MemMgrRef, std::move(R));
|
||||
};
|
||||
|
||||
// Process each of the modules in this module set.
|
||||
addLogicalModule(LogicalDylibs.back(), std::move(M));
|
||||
for (auto &M : Ms)
|
||||
addLogicalModule(LogicalDylibs.back(), std::move(M));
|
||||
|
||||
return std::prev(LogicalDylibs.end());
|
||||
}
|
||||
|
||||
/// @brief Add extra modules to an existing logical module.
|
||||
void addExtraModule(ModuleHandleT H, std::shared_ptr<Module> M) {
|
||||
addLogicalModule(*H, std::move(M));
|
||||
}
|
||||
|
||||
/// @brief Remove the module represented by the given handle.
|
||||
///
|
||||
/// This will remove all modules in the layers below that were derived from
|
||||
/// the module represented by H.
|
||||
void removeModule(ModuleHandleT H) {
|
||||
void removeModuleSet(ModuleSetHandleT H) {
|
||||
H->removeModulesFromBaseLayer(BaseLayer);
|
||||
LogicalDylibs.erase(H);
|
||||
}
|
||||
|
@ -278,7 +274,7 @@ public:
|
|||
|
||||
/// @brief Get the address of a symbol provided by this layer, or some layer
|
||||
/// below this one.
|
||||
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
|
||||
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
|
||||
bool ExportedSymbolsOnly) {
|
||||
return H->findSymbol(BaseLayer, Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
@ -502,7 +498,7 @@ private:
|
|||
}
|
||||
|
||||
template <typename PartitionT>
|
||||
BaseLayerModuleHandleT
|
||||
BaseLayerModuleSetHandleT
|
||||
emitPartition(LogicalDylib &LD,
|
||||
typename LogicalDylib::SourceModuleHandle LMId,
|
||||
const PartitionT &Part) {
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
/// @brief Construct a CtorDtorRunner for the given range using the given
|
||||
/// name mangling function.
|
||||
CtorDtorRunner(std::vector<std::string> CtorDtorNames,
|
||||
typename JITLayerT::ModuleHandleT H)
|
||||
typename JITLayerT::ModuleSetHandleT H)
|
||||
: CtorDtorNames(std::move(CtorDtorNames)), H(H) {}
|
||||
|
||||
/// @brief Run the recorded constructors/destructors through the given JIT
|
||||
|
@ -116,7 +116,7 @@ public:
|
|||
|
||||
private:
|
||||
std::vector<std::string> CtorDtorNames;
|
||||
typename JITLayerT::ModuleHandleT H;
|
||||
typename JITLayerT::ModuleSetHandleT H;
|
||||
};
|
||||
|
||||
/// @brief Support class for static dtor execution. For hosted (in-process) JITs
|
||||
|
|
|
@ -28,15 +28,15 @@ namespace orc {
|
|||
|
||||
/// @brief Eager IR compiling layer.
|
||||
///
|
||||
/// This layer immediately compiles each IR module added via addModule to an
|
||||
/// object file and adds this module file to the layer below, which must
|
||||
/// implement the object layer concept.
|
||||
/// This layer accepts sets of LLVM IR Modules (via addModuleSet). It
|
||||
/// immediately compiles each IR module to an object file (each IR Module is
|
||||
/// compiled separately). The resulting set of object files is then added to
|
||||
/// the layer below, which must implement the object layer concept.
|
||||
template <typename BaseLayerT, typename CompileFtor>
|
||||
class IRCompileLayer {
|
||||
public:
|
||||
|
||||
/// @brief Handle to a compiled module.
|
||||
using ModuleHandleT = typename BaseLayerT::ObjHandleT;
|
||||
/// @brief Handle to a set of compiled modules.
|
||||
using ModuleSetHandleT = typename BaseLayerT::ObjHandleT;
|
||||
|
||||
/// @brief Construct an IRCompileLayer with the given BaseLayer, which must
|
||||
/// implement the ObjectLayer concept.
|
||||
|
@ -46,22 +46,25 @@ public:
|
|||
/// @brief Get a reference to the compiler functor.
|
||||
CompileFtor& getCompiler() { return Compile; }
|
||||
|
||||
/// @brief Compile the module, and add the resulting object to the base layer
|
||||
/// along with the given memory manager and symbol resolver.
|
||||
/// @brief Compile each module in the given module set, then add the resulting
|
||||
/// set of objects to the base layer along with the 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) {
|
||||
using CompileResult = decltype(Compile(*M));
|
||||
auto Obj = std::make_shared<CompileResult>(Compile(*M));
|
||||
/// @return A handle for the added modules.
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ModuleSetHandleT addModuleSet(ModuleSetT Ms,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
assert(Ms.size() == 1);
|
||||
using CompileResult = decltype(Compile(*Ms.front()));
|
||||
auto Obj = std::make_shared<CompileResult>(Compile(*Ms.front()));
|
||||
return BaseLayer.addObject(std::move(Obj), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
/// @brief Remove the module associated with the handle H.
|
||||
void removeModule(ModuleHandleT H) { BaseLayer.removeObject(H); }
|
||||
/// @brief Remove the module set associated with the handle H.
|
||||
void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeObject(H); }
|
||||
|
||||
/// @brief Search for the given named symbol.
|
||||
/// @param Name The name of the symbol to search for.
|
||||
|
@ -71,23 +74,23 @@ public:
|
|||
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
/// @brief Get the address of the given symbol in compiled module represented
|
||||
/// by the handle H. This call is forwarded to the base layer's
|
||||
/// implementation.
|
||||
/// @param H The handle for the module to search in.
|
||||
/// @brief Get the address of the given symbol in the context of the set of
|
||||
/// compiled modules represented by the handle H. This call is
|
||||
/// forwarded to the base layer's implementation.
|
||||
/// @param H The handle for the module set to search in.
|
||||
/// @param Name The name of the symbol to search for.
|
||||
/// @param ExportedSymbolsOnly If true, search only for exported symbols.
|
||||
/// @return A handle for the given named symbol, if it is found in the
|
||||
/// given module.
|
||||
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
|
||||
/// given module set.
|
||||
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
|
||||
bool ExportedSymbolsOnly) {
|
||||
return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
/// @brief Immediately emit and finalize the module represented by the given
|
||||
/// handle.
|
||||
/// @param H Handle for module to emit/finalize.
|
||||
void emitAndFinalize(ModuleHandleT H) {
|
||||
/// @brief Immediately emit and finalize the moduleOB set represented by the
|
||||
/// given handle.
|
||||
/// @param H Handle for module set to emit/finalize.
|
||||
void emitAndFinalize(ModuleSetHandleT H) {
|
||||
BaseLayer.emitAndFinalize(H);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,34 +22,39 @@ namespace orc {
|
|||
|
||||
/// @brief IR mutating layer.
|
||||
///
|
||||
/// This layer applies a user supplied transform to each module that is added,
|
||||
/// then adds the transformed module to the layer below.
|
||||
/// This layer accepts sets of LLVM IR Modules (via addModuleSet). It
|
||||
/// immediately applies the user supplied functor to each module, then adds
|
||||
/// the set of transformed modules to the layer below.
|
||||
template <typename BaseLayerT, typename TransformFtor>
|
||||
class IRTransformLayer {
|
||||
public:
|
||||
|
||||
/// @brief Handle to a set of added modules.
|
||||
using ModuleHandleT = typename BaseLayerT::ModuleHandleT;
|
||||
using ModuleSetHandleT = typename BaseLayerT::ModuleSetHandleT;
|
||||
|
||||
/// @brief Construct an IRTransformLayer with the given BaseLayer
|
||||
IRTransformLayer(BaseLayerT &BaseLayer,
|
||||
TransformFtor Transform = TransformFtor())
|
||||
: BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
|
||||
|
||||
/// @brief Apply the transform functor to the module, then add the module to
|
||||
/// the layer below, along with the memory manager and symbol resolver.
|
||||
/// @brief Apply the transform functor to each module in the module set, then
|
||||
/// add the resulting set of modules to the base layer, 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));
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ModuleSetHandleT addModuleSet(ModuleSetT Ms,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
for (auto I = Ms.begin(), E = Ms.end(); I != E; ++I)
|
||||
*I = Transform(std::move(*I));
|
||||
|
||||
return BaseLayer.addModuleSet(std::move(Ms), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
/// @brief Remove the module associated with the handle H.
|
||||
void removeModule(ModuleHandleT H) { BaseLayer.removeModule(H); }
|
||||
/// @brief Remove the module set associated with the handle H.
|
||||
void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeModuleSet(H); }
|
||||
|
||||
/// @brief Search for the given named symbol.
|
||||
/// @param Name The name of the symbol to search for.
|
||||
|
@ -59,23 +64,23 @@ public:
|
|||
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
/// @brief Get the address of the given symbol in the context of the module
|
||||
/// represented by the handle H. This call is forwarded to the base
|
||||
/// layer's implementation.
|
||||
/// @param H The handle for the module to search in.
|
||||
/// @brief Get the address of the given symbol in the context of the set of
|
||||
/// modules represented by the handle H. This call is forwarded to the
|
||||
/// base layer's implementation.
|
||||
/// @param H The handle for the module set to search in.
|
||||
/// @param Name The name of the symbol to search for.
|
||||
/// @param ExportedSymbolsOnly If true, search only for exported symbols.
|
||||
/// @return A handle for the given named symbol, if it is found in the
|
||||
/// given module.
|
||||
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
|
||||
/// given module set.
|
||||
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
|
||||
bool ExportedSymbolsOnly) {
|
||||
return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
/// @brief Immediately emit and finalize the module represented by the given
|
||||
/// handle.
|
||||
/// @param H Handle for module to emit/finalize.
|
||||
void emitAndFinalize(ModuleHandleT H) {
|
||||
/// @brief Immediately emit and finalize the module set represented by the
|
||||
/// given handle.
|
||||
/// @param H Handle for module set to emit/finalize.
|
||||
void emitAndFinalize(ModuleSetHandleT H) {
|
||||
BaseLayer.emitAndFinalize(H);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,20 +34,19 @@ namespace orc {
|
|||
|
||||
/// @brief Lazy-emitting IR layer.
|
||||
///
|
||||
/// This layer accepts LLVM IR Modules (via addModule), but does not
|
||||
/// immediately emit them the layer below. Instead, emissing to the base layer
|
||||
/// is deferred until the first time the client requests the address (via
|
||||
/// JITSymbol::getAddress) for a symbol contained in this layer.
|
||||
/// This layer accepts sets of LLVM IR Modules (via addModuleSet), but does
|
||||
/// not immediately emit them the layer below. Instead, emissing to the base
|
||||
/// layer is deferred until the first time the client requests the address
|
||||
/// (via JITSymbol::getAddress) for a symbol contained in this layer.
|
||||
template <typename BaseLayerT> class LazyEmittingLayer {
|
||||
public:
|
||||
|
||||
using BaseLayerHandleT = typename BaseLayerT::ModuleHandleT;
|
||||
using BaseLayerHandleT = typename BaseLayerT::ModuleSetHandleT;
|
||||
|
||||
private:
|
||||
class EmissionDeferredModule {
|
||||
class EmissionDeferredSet {
|
||||
public:
|
||||
EmissionDeferredModule() = default;
|
||||
virtual ~EmissionDeferredModule() = default;
|
||||
EmissionDeferredSet() = default;
|
||||
virtual ~EmissionDeferredSet() = default;
|
||||
|
||||
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
|
||||
switch (EmitState) {
|
||||
|
@ -85,9 +84,9 @@ private:
|
|||
llvm_unreachable("Invalid emit-state.");
|
||||
}
|
||||
|
||||
void removeModuleFromBaseLayer(BaseLayerT &BaseLayer) {
|
||||
void removeModulesFromBaseLayer(BaseLayerT &BaseLayer) {
|
||||
if (EmitState != NotEmitted)
|
||||
BaseLayer.removeModule(Handle);
|
||||
BaseLayer.removeModuleSet(Handle);
|
||||
}
|
||||
|
||||
void emitAndFinalize(BaseLayerT &BaseLayer) {
|
||||
|
@ -101,9 +100,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,
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
static std::unique_ptr<EmissionDeferredSet>
|
||||
create(BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver);
|
||||
|
||||
protected:
|
||||
|
@ -116,13 +116,14 @@ private:
|
|||
BaseLayerHandleT Handle;
|
||||
};
|
||||
|
||||
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
|
||||
class EmissionDeferredModuleImpl : public EmissionDeferredModule {
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
class EmissionDeferredSetImpl : public EmissionDeferredSet {
|
||||
public:
|
||||
EmissionDeferredModuleImpl(std::shared_ptr<Module> M,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver)
|
||||
: M(std::move(M)), MemMgr(std::move(MemMgr)),
|
||||
EmissionDeferredSetImpl(ModuleSetT Ms,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver)
|
||||
: Ms(std::move(Ms)), MemMgr(std::move(MemMgr)),
|
||||
Resolver(std::move(Resolver)) {}
|
||||
|
||||
protected:
|
||||
|
@ -153,8 +154,8 @@ private:
|
|||
// 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.addModuleSet(std::move(Ms), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -196,54 +197,56 @@ private:
|
|||
|
||||
auto Symbols = llvm::make_unique<StringMap<const GlobalValue*>>();
|
||||
|
||||
Mangler Mang;
|
||||
for (const auto &M : Ms) {
|
||||
Mangler Mang;
|
||||
|
||||
for (const auto &GO : M->global_objects())
|
||||
for (const auto &GO : M->global_objects())
|
||||
if (auto GV = addGlobalValue(*Symbols, GO, Mang, SearchName,
|
||||
ExportedSymbolsOnly))
|
||||
return GV;
|
||||
}
|
||||
|
||||
MangledSymbols = std::move(Symbols);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Module> M;
|
||||
ModuleSetT Ms;
|
||||
MemoryManagerPtrT MemMgr;
|
||||
SymbolResolverPtrT Resolver;
|
||||
mutable std::unique_ptr<StringMap<const GlobalValue*>> MangledSymbols;
|
||||
};
|
||||
|
||||
using ModuleListT = std::list<std::unique_ptr<EmissionDeferredModule>>;
|
||||
using ModuleSetListT = std::list<std::unique_ptr<EmissionDeferredSet>>;
|
||||
|
||||
BaseLayerT &BaseLayer;
|
||||
ModuleListT ModuleList;
|
||||
ModuleSetListT ModuleSetList;
|
||||
|
||||
public:
|
||||
/// @brief Handle to a loaded module.
|
||||
using ModuleHandleT = typename ModuleListT::iterator;
|
||||
/// @brief Handle to a set of loaded modules.
|
||||
using ModuleSetHandleT = typename ModuleSetListT::iterator;
|
||||
|
||||
/// @brief Construct a lazy emitting layer.
|
||||
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) {
|
||||
return ModuleList.insert(
|
||||
ModuleList.end(),
|
||||
EmissionDeferredModule::create(BaseLayer, std::move(M),
|
||||
std::move(MemMgr),
|
||||
std::move(Resolver)));
|
||||
/// @brief Add the given set of modules to the lazy emitting layer.
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ModuleSetHandleT addModuleSet(ModuleSetT Ms,
|
||||
MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
return ModuleSetList.insert(
|
||||
ModuleSetList.end(),
|
||||
EmissionDeferredSet::create(BaseLayer, std::move(Ms), std::move(MemMgr),
|
||||
std::move(Resolver)));
|
||||
}
|
||||
|
||||
/// @brief Remove the module represented by the given handle.
|
||||
/// @brief Remove the module set represented by the given handle.
|
||||
///
|
||||
/// This method will free the memory associated with the given module, both
|
||||
/// in this layer, and the base layer.
|
||||
void removeModule(ModuleHandleT H) {
|
||||
(*H)->removeModuleFromBaseLayer(BaseLayer);
|
||||
ModuleList.erase(H);
|
||||
/// This method will free the memory associated with the given module set,
|
||||
/// both in this layer, and the base layer.
|
||||
void removeModuleSet(ModuleSetHandleT H) {
|
||||
(*H)->removeModulesFromBaseLayer(BaseLayer);
|
||||
ModuleSetList.erase(H);
|
||||
}
|
||||
|
||||
/// @brief Search for the given named symbol.
|
||||
|
@ -255,40 +258,42 @@ public:
|
|||
if (auto Symbol = BaseLayer.findSymbol(Name, ExportedSymbolsOnly))
|
||||
return Symbol;
|
||||
|
||||
// If not found then search the deferred modules. If any of these contain a
|
||||
// If not found then search the deferred sets. If any of these contain a
|
||||
// definition of 'Name' then they will return a JITSymbol that will emit
|
||||
// the corresponding module when the symbol address is requested.
|
||||
for (auto &DeferredMod : ModuleList)
|
||||
if (auto Symbol = DeferredMod->find(Name, ExportedSymbolsOnly, BaseLayer))
|
||||
for (auto &DeferredSet : ModuleSetList)
|
||||
if (auto Symbol = DeferredSet->find(Name, ExportedSymbolsOnly, BaseLayer))
|
||||
return Symbol;
|
||||
|
||||
// If no definition found anywhere return a null symbol.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// @brief Get the address of the given symbol in the context of the of
|
||||
/// @brief Get the address of the given symbol in the context of the set of
|
||||
/// compiled modules represented by the handle H.
|
||||
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
|
||||
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
|
||||
bool ExportedSymbolsOnly) {
|
||||
return (*H)->find(Name, ExportedSymbolsOnly, BaseLayer);
|
||||
}
|
||||
|
||||
/// @brief Immediately emit and finalize the module represented by the given
|
||||
/// handle.
|
||||
/// @param H Handle for module to emit/finalize.
|
||||
void emitAndFinalize(ModuleHandleT H) {
|
||||
/// @brief Immediately emit and finalize the moduleOB set represented by the
|
||||
/// given handle.
|
||||
/// @param H Handle for module set to emit/finalize.
|
||||
void emitAndFinalize(ModuleSetHandleT H) {
|
||||
(*H)->emitAndFinalize(BaseLayer);
|
||||
}
|
||||
};
|
||||
|
||||
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,
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet>
|
||||
LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet::create(
|
||||
BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
using EDS = EmissionDeferredModuleImpl<MemoryManagerPtrT, SymbolResolverPtrT>;
|
||||
return llvm::make_unique<EDS>(std::move(M), std::move(MemMgr),
|
||||
using EDS = EmissionDeferredSetImpl<ModuleSetT, MemoryManagerPtrT,
|
||||
SymbolResolverPtrT>;
|
||||
return llvm::make_unique<EDS>(std::move(Ms), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,24 +12,6 @@
|
|||
|
||||
using namespace llvm;
|
||||
|
||||
LLVMSharedModuleRef LLVMOrcMakeSharedModule(LLVMModuleRef Mod) {
|
||||
return wrap(new std::shared_ptr<Module>(unwrap(Mod)));
|
||||
}
|
||||
|
||||
void LLVMOrcDisposeSharedModuleRef(LLVMSharedModuleRef SharedMod) {
|
||||
delete unwrap(SharedMod);
|
||||
}
|
||||
|
||||
LLVMSharedObjectBufferRef
|
||||
LLVMOrcMakeSharedObjectBuffer(LLVMMemoryBufferRef ObjBuffer) {
|
||||
return wrap(new std::shared_ptr<MemoryBuffer>(unwrap(ObjBuffer)));
|
||||
}
|
||||
|
||||
void
|
||||
LLVMOrcDisposeSharedObjectBufferRef(LLVMSharedObjectBufferRef SharedObjBuffer) {
|
||||
delete unwrap(SharedObjBuffer);
|
||||
}
|
||||
|
||||
LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) {
|
||||
TargetMachine *TM2(unwrap(TM));
|
||||
|
||||
|
@ -83,23 +65,21 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
|
|||
}
|
||||
|
||||
LLVMOrcModuleHandle
|
||||
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||
LLVMSharedModuleRef Mod,
|
||||
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
|
||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||
void *SymbolResolverCtx) {
|
||||
OrcCBindingsStack &J = *unwrap(JITStack);
|
||||
std::shared_ptr<Module> *M(unwrap(Mod));
|
||||
return J.addIRModuleEager(*M, SymbolResolver, SymbolResolverCtx);
|
||||
Module *M(unwrap(Mod));
|
||||
return J.addIRModuleEager(M, SymbolResolver, SymbolResolverCtx);
|
||||
}
|
||||
|
||||
LLVMOrcModuleHandle
|
||||
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||
LLVMSharedModuleRef Mod,
|
||||
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
|
||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||
void *SymbolResolverCtx) {
|
||||
OrcCBindingsStack &J = *unwrap(JITStack);
|
||||
std::shared_ptr<Module> *M(unwrap(Mod));
|
||||
return J.addIRModuleLazy(*M, SymbolResolver, SymbolResolverCtx);
|
||||
Module *M(unwrap(Mod));
|
||||
return J.addIRModuleLazy(M, SymbolResolver, SymbolResolverCtx);
|
||||
}
|
||||
|
||||
void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H) {
|
||||
|
|
|
@ -42,10 +42,6 @@ namespace llvm {
|
|||
|
||||
class OrcCBindingsStack;
|
||||
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::shared_ptr<Module>,
|
||||
LLVMSharedModuleRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::shared_ptr<MemoryBuffer>,
|
||||
LLVMSharedObjectBufferRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcCBindingsStack, LLVMOrcJITStackRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
||||
|
||||
|
@ -75,7 +71,7 @@ private:
|
|||
|
||||
template <typename LayerT> class GenericHandleImpl : public GenericHandle {
|
||||
public:
|
||||
GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleHandleT Handle)
|
||||
GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleSetHandleT Handle)
|
||||
: Layer(Layer), Handle(std::move(Handle)) {}
|
||||
|
||||
JITSymbol findSymbolIn(const std::string &Name,
|
||||
|
@ -83,21 +79,24 @@ private:
|
|||
return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
void removeModule() override { return Layer.removeModule(Handle); }
|
||||
void removeModule() override { return Layer.removeModuleSet(Handle); }
|
||||
|
||||
private:
|
||||
LayerT &Layer;
|
||||
typename LayerT::ModuleHandleT Handle;
|
||||
typename LayerT::ModuleSetHandleT Handle;
|
||||
};
|
||||
|
||||
template <typename LayerT>
|
||||
std::unique_ptr<GenericHandleImpl<LayerT>>
|
||||
createGenericHandle(LayerT &Layer, typename LayerT::ModuleHandleT Handle) {
|
||||
createGenericHandle(LayerT &Layer, typename LayerT::ModuleSetHandleT Handle) {
|
||||
return llvm::make_unique<GenericHandleImpl<LayerT>>(Layer,
|
||||
std::move(Handle));
|
||||
}
|
||||
|
||||
public:
|
||||
// We need a 'ModuleSetHandleT' to conform to the layer concept.
|
||||
using ModuleSetHandleT = unsigned;
|
||||
|
||||
using ModuleHandleT = unsigned;
|
||||
|
||||
OrcCBindingsStack(TargetMachine &TM,
|
||||
|
@ -184,7 +183,7 @@ public:
|
|||
}
|
||||
|
||||
template <typename LayerT>
|
||||
ModuleHandleT addIRModule(LayerT &Layer, std::shared_ptr<Module> M,
|
||||
ModuleHandleT addIRModule(LayerT &Layer, Module *M,
|
||||
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
|
||||
LLVMOrcSymbolResolverFn ExternalResolver,
|
||||
void *ExternalResolverCtx) {
|
||||
|
@ -204,8 +203,11 @@ 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));
|
||||
std::vector<Module *> S;
|
||||
S.push_back(std::move(M));
|
||||
|
||||
auto LH = Layer.addModuleSet(std::move(S), std::move(MemMgr),
|
||||
std::move(Resolver));
|
||||
ModuleHandleT H = createHandle(Layer, LH);
|
||||
|
||||
// Run the static constructors, and save the static destructor runner for
|
||||
|
@ -218,7 +220,7 @@ public:
|
|||
return H;
|
||||
}
|
||||
|
||||
ModuleHandleT addIRModuleEager(std::shared_ptr<Module> M,
|
||||
ModuleHandleT addIRModuleEager(Module *M,
|
||||
LLVMOrcSymbolResolverFn ExternalResolver,
|
||||
void *ExternalResolverCtx) {
|
||||
return addIRModule(CompileLayer, std::move(M),
|
||||
|
@ -226,7 +228,7 @@ public:
|
|||
std::move(ExternalResolver), ExternalResolverCtx);
|
||||
}
|
||||
|
||||
ModuleHandleT addIRModuleLazy(std::shared_ptr<Module> M,
|
||||
ModuleHandleT addIRModuleLazy(Module *M,
|
||||
LLVMOrcSymbolResolverFn ExternalResolver,
|
||||
void *ExternalResolverCtx) {
|
||||
return addIRModule(CODLayer, std::move(M),
|
||||
|
@ -255,7 +257,8 @@ public:
|
|||
|
||||
private:
|
||||
template <typename LayerT>
|
||||
unsigned createHandle(LayerT &Layer, typename LayerT::ModuleHandleT Handle) {
|
||||
unsigned createHandle(LayerT &Layer,
|
||||
typename LayerT::ModuleSetHandleT Handle) {
|
||||
unsigned NewHandle;
|
||||
if (!FreeHandleIndexes.empty()) {
|
||||
NewHandle = FreeHandleIndexes.back();
|
||||
|
|
|
@ -191,15 +191,10 @@ public:
|
|||
} else {
|
||||
assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
|
||||
}
|
||||
auto *MPtr = M.release();
|
||||
Retain[MPtr] = false;
|
||||
auto Deleter =
|
||||
[this](Module *Mod) {
|
||||
if (!Retain[Mod])
|
||||
delete Mod;
|
||||
};
|
||||
LocalModules.push_back(std::shared_ptr<Module>(MPtr, std::move(Deleter)));
|
||||
LazyEmitLayer.addModule(LocalModules.back(), &MemMgr, &Resolver);
|
||||
Modules.push_back(std::move(M));
|
||||
std::vector<Module *> Ms;
|
||||
Ms.push_back(&*Modules.back());
|
||||
LazyEmitLayer.addModuleSet(std::move(Ms), &MemMgr, &Resolver);
|
||||
}
|
||||
|
||||
void addObjectFile(std::unique_ptr<object::ObjectFile> O) override {
|
||||
|
@ -386,8 +381,6 @@ private:
|
|||
std::map<ObjectLayerT::ObjHandleT, SectionAddrSet, ObjHandleCompare>
|
||||
UnfinalizedSections;
|
||||
|
||||
std::map<Module*, bool> Retain;
|
||||
std::vector<std::shared_ptr<Module>> LocalModules;
|
||||
std::vector<object::OwningBinary<object::Archive>> Archives;
|
||||
};
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ static cl::opt<bool> OrcInlineStubs("orc-lazy-inline-stubs",
|
|||
OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
|
||||
switch (OrcDumpKind) {
|
||||
case DumpKind::NoDump:
|
||||
return [](std::shared_ptr<Module> M) { return M; };
|
||||
return [](std::unique_ptr<Module> M) { return M; };
|
||||
|
||||
case DumpKind::DumpFuncsToStdOut:
|
||||
return [](std::shared_ptr<Module> M) {
|
||||
return [](std::unique_ptr<Module> M) {
|
||||
printf("[ ");
|
||||
|
||||
for (const auto &F : *M) {
|
||||
|
@ -76,7 +76,7 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
|
|||
};
|
||||
|
||||
case DumpKind::DumpModsToStdOut:
|
||||
return [](std::shared_ptr<Module> M) {
|
||||
return [](std::unique_ptr<Module> M) {
|
||||
outs() << "----- Module Start -----\n" << *M
|
||||
<< "----- Module End -----\n";
|
||||
|
||||
|
@ -84,7 +84,7 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
|
|||
};
|
||||
|
||||
case DumpKind::DumpModsToDisk:
|
||||
return [](std::shared_ptr<Module> M) {
|
||||
return [](std::unique_ptr<Module> M) {
|
||||
std::error_code EC;
|
||||
raw_fd_ostream Out(M->getModuleIdentifier() + ".ll", EC,
|
||||
sys::fs::F_Text);
|
||||
|
@ -147,8 +147,7 @@ int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,
|
|||
OrcInlineStubs);
|
||||
|
||||
// Add the module, look up main and run it.
|
||||
for (auto &M : Ms)
|
||||
J.addModule(std::shared_ptr<Module>(std::move(M)));
|
||||
J.addModuleSet(std::move(Ms));
|
||||
auto MainSym = J.findSymbol("main");
|
||||
|
||||
if (!MainSym) {
|
||||
|
|
|
@ -50,11 +50,11 @@ public:
|
|||
using ObjLayerT = orc::RTDyldObjectLinkingLayer;
|
||||
using CompileLayerT = orc::IRCompileLayer<ObjLayerT, orc::SimpleCompiler>;
|
||||
using TransformFtor =
|
||||
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
||||
using IRDumpLayerT = orc::IRTransformLayer<CompileLayerT, TransformFtor>;
|
||||
using CODLayerT = orc::CompileOnDemandLayer<IRDumpLayerT, CompileCallbackMgr>;
|
||||
using IndirectStubsManagerBuilder = CODLayerT::IndirectStubsManagerBuilderT;
|
||||
using ModuleHandleT = CODLayerT::ModuleHandleT;
|
||||
using ModuleSetHandleT = CODLayerT::ModuleSetHandleT;
|
||||
|
||||
OrcLazyJIT(std::unique_ptr<TargetMachine> TM,
|
||||
std::unique_ptr<CompileCallbackMgr> CCMgr,
|
||||
|
@ -77,9 +77,11 @@ public:
|
|||
DtorRunner.runViaLayer(CODLayer);
|
||||
}
|
||||
|
||||
void addModule(std::shared_ptr<Module> M) {
|
||||
if (M->getDataLayout().isDefault())
|
||||
M->setDataLayout(DL);
|
||||
ModuleSetHandleT addModuleSet(std::vector<std::unique_ptr<Module>> Ms) {
|
||||
// Attach a data-layouts if they aren't already present.
|
||||
for (auto &M : Ms)
|
||||
if (M->getDataLayout().isDefault())
|
||||
M->setDataLayout(DL);
|
||||
|
||||
// Rename, bump linkage and record static constructors and destructors.
|
||||
// We have to do this before we hand over ownership of the module to the
|
||||
|
@ -87,19 +89,21 @@ public:
|
|||
std::vector<std::string> CtorNames, DtorNames;
|
||||
{
|
||||
unsigned CtorId = 0, DtorId = 0;
|
||||
for (auto Ctor : orc::getConstructors(*M)) {
|
||||
std::string NewCtorName = ("$static_ctor." + Twine(CtorId++)).str();
|
||||
Ctor.Func->setName(NewCtorName);
|
||||
Ctor.Func->setLinkage(GlobalValue::ExternalLinkage);
|
||||
Ctor.Func->setVisibility(GlobalValue::HiddenVisibility);
|
||||
CtorNames.push_back(mangle(NewCtorName));
|
||||
}
|
||||
for (auto Dtor : orc::getDestructors(*M)) {
|
||||
std::string NewDtorName = ("$static_dtor." + Twine(DtorId++)).str();
|
||||
Dtor.Func->setLinkage(GlobalValue::ExternalLinkage);
|
||||
Dtor.Func->setVisibility(GlobalValue::HiddenVisibility);
|
||||
DtorNames.push_back(mangle(Dtor.Func->getName()));
|
||||
Dtor.Func->setName(NewDtorName);
|
||||
for (auto &M : Ms) {
|
||||
for (auto Ctor : orc::getConstructors(*M)) {
|
||||
std::string NewCtorName = ("$static_ctor." + Twine(CtorId++)).str();
|
||||
Ctor.Func->setName(NewCtorName);
|
||||
Ctor.Func->setLinkage(GlobalValue::ExternalLinkage);
|
||||
Ctor.Func->setVisibility(GlobalValue::HiddenVisibility);
|
||||
CtorNames.push_back(mangle(NewCtorName));
|
||||
}
|
||||
for (auto Dtor : orc::getDestructors(*M)) {
|
||||
std::string NewDtorName = ("$static_dtor." + Twine(DtorId++)).str();
|
||||
Dtor.Func->setLinkage(GlobalValue::ExternalLinkage);
|
||||
Dtor.Func->setVisibility(GlobalValue::HiddenVisibility);
|
||||
DtorNames.push_back(mangle(Dtor.Func->getName()));
|
||||
Dtor.Func->setName(NewDtorName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,45 +111,41 @@ public:
|
|||
// 1) Search the JIT symbols.
|
||||
// 2) Check for C++ runtime overrides.
|
||||
// 3) Search the host process (LLI)'s symbol table.
|
||||
if (ModulesHandle == CODLayerT::ModuleHandleT()) {
|
||||
auto Resolver =
|
||||
orc::createLambdaResolver(
|
||||
[this](const std::string &Name) -> JITSymbol {
|
||||
if (auto Sym = CODLayer.findSymbol(Name, true))
|
||||
return Sym;
|
||||
return CXXRuntimeOverrides.searchOverrides(Name);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
if (auto Addr =
|
||||
RTDyldMemoryManager::getSymbolAddressInProcess(Name))
|
||||
return JITSymbol(Addr, JITSymbolFlags::Exported);
|
||||
return JITSymbol(nullptr);
|
||||
}
|
||||
);
|
||||
auto Resolver =
|
||||
orc::createLambdaResolver(
|
||||
[this](const std::string &Name) -> JITSymbol {
|
||||
if (auto Sym = CODLayer.findSymbol(Name, true))
|
||||
return Sym;
|
||||
return CXXRuntimeOverrides.searchOverrides(Name);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
if (auto Addr =
|
||||
RTDyldMemoryManager::getSymbolAddressInProcess(Name))
|
||||
return JITSymbol(Addr, JITSymbolFlags::Exported);
|
||||
return JITSymbol(nullptr);
|
||||
}
|
||||
);
|
||||
|
||||
// Add the module to the JIT.
|
||||
ModulesHandle =
|
||||
CODLayer.addModule(std::move(M),
|
||||
llvm::make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
} else
|
||||
CODLayer.addExtraModule(ModulesHandle, std::move(M));
|
||||
// Add the module to the JIT.
|
||||
auto H = CODLayer.addModuleSet(std::move(Ms),
|
||||
llvm::make_unique<SectionMemoryManager>(),
|
||||
std::move(Resolver));
|
||||
|
||||
// Run the static constructors, and save the static destructor runner for
|
||||
// execution when the JIT is torn down.
|
||||
orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames),
|
||||
ModulesHandle);
|
||||
orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames), H);
|
||||
CtorRunner.runViaLayer(CODLayer);
|
||||
|
||||
IRStaticDestructorRunners.emplace_back(std::move(DtorNames),
|
||||
ModulesHandle);
|
||||
IRStaticDestructorRunners.emplace_back(std::move(DtorNames), H);
|
||||
|
||||
return H;
|
||||
}
|
||||
|
||||
JITSymbol findSymbol(const std::string &Name) {
|
||||
return CODLayer.findSymbol(mangle(Name), true);
|
||||
}
|
||||
|
||||
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) {
|
||||
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name) {
|
||||
return CODLayer.findSymbolIn(H, mangle(Name), true);
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,6 @@ private:
|
|||
|
||||
orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;
|
||||
std::vector<orc::CtorDtorRunner<CODLayerT>> IRStaticDestructorRunners;
|
||||
CODLayerT::ModuleHandleT ModulesHandle;
|
||||
};
|
||||
|
||||
int runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
namespace {
|
||||
|
||||
struct MockBaseLayer {
|
||||
typedef int ModuleHandleT;
|
||||
ModuleHandleT addModule(
|
||||
std::shared_ptr<llvm::Module>,
|
||||
typedef int ModuleSetHandleT;
|
||||
ModuleSetHandleT addModuleSet(
|
||||
std::list<std::unique_ptr<llvm::Module>>,
|
||||
std::unique_ptr<llvm::RuntimeDyld::MemoryManager> MemMgr,
|
||||
std::unique_ptr<llvm::JITSymbolResolver> Resolver) {
|
||||
EXPECT_FALSE(MemMgr);
|
||||
|
@ -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.addModuleSet(std::list<std::unique_ptr<llvm::Module>>(), nullptr, nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ TEST(ObjectTransformLayerTest, Main) {
|
|||
// compile.
|
||||
NullResolver Resolver;
|
||||
NullManager Manager;
|
||||
CompileLayer.addModule(std::shared_ptr<llvm::Module>(), &Manager, &Resolver);
|
||||
CompileLayer.addModuleSet(std::vector<llvm::Module *>(), &Manager, &Resolver);
|
||||
|
||||
// Make sure that the calls from ObjectTransformLayer to ObjectLinkingLayer
|
||||
// compile.
|
||||
|
|
|
@ -65,9 +65,8 @@ protected:
|
|||
CompileContext *CCtx = static_cast<CompileContext*>(Ctx);
|
||||
auto *ET = CCtx->APIExecTest;
|
||||
CCtx->M = ET->createTestModule(ET->TM->getTargetTriple());
|
||||
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(CCtx->M.release()));
|
||||
CCtx->H = LLVMOrcAddEagerlyCompiledIR(JITStack, SM, myResolver, nullptr);
|
||||
LLVMOrcDisposeSharedModuleRef(SM);
|
||||
CCtx->H = LLVMOrcAddEagerlyCompiledIR(JITStack, wrap(CCtx->M.get()),
|
||||
myResolver, nullptr);
|
||||
CCtx->Compiled = true;
|
||||
LLVMOrcTargetAddress MainAddr = LLVMOrcGetSymbolAddress(JITStack, "main");
|
||||
LLVMOrcSetIndirectStubPointer(JITStack, "foo", MainAddr);
|
||||
|
@ -88,10 +87,8 @@ TEST_F(OrcCAPIExecutionTest, TestEagerIRCompilation) {
|
|||
|
||||
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
|
||||
|
||||
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M.release()));
|
||||
LLVMOrcModuleHandle H =
|
||||
LLVMOrcAddEagerlyCompiledIR(JIT, SM, myResolver, nullptr);
|
||||
LLVMOrcDisposeSharedModuleRef(SM);
|
||||
LLVMOrcAddEagerlyCompiledIR(JIT, wrap(M.get()), myResolver, nullptr);
|
||||
MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddress(JIT, "main");
|
||||
int Result = MainFn();
|
||||
EXPECT_EQ(Result, 42)
|
||||
|
@ -114,10 +111,8 @@ TEST_F(OrcCAPIExecutionTest, TestLazyIRCompilation) {
|
|||
|
||||
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
|
||||
|
||||
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M.release()));
|
||||
LLVMOrcModuleHandle H =
|
||||
LLVMOrcAddLazilyCompiledIR(JIT, SM, myResolver, nullptr);
|
||||
LLVMOrcDisposeSharedModuleRef(SM);
|
||||
LLVMOrcAddLazilyCompiledIR(JIT, wrap(M.get()), myResolver, nullptr);
|
||||
MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddress(JIT, "main");
|
||||
int Result = MainFn();
|
||||
EXPECT_EQ(Result, 42)
|
||||
|
|
|
@ -106,65 +106,65 @@ public:
|
|||
};
|
||||
|
||||
template <typename HandleT,
|
||||
typename AddModuleFtor,
|
||||
typename RemoveModuleFtor,
|
||||
typename AddModuleSetFtor,
|
||||
typename RemoveModuleSetFtor,
|
||||
typename FindSymbolFtor,
|
||||
typename FindSymbolInFtor>
|
||||
class MockBaseLayer {
|
||||
public:
|
||||
|
||||
typedef HandleT ModuleHandleT;
|
||||
typedef HandleT ModuleSetHandleT;
|
||||
|
||||
MockBaseLayer(AddModuleFtor &&AddModule,
|
||||
RemoveModuleFtor &&RemoveModule,
|
||||
MockBaseLayer(AddModuleSetFtor &&AddModuleSet,
|
||||
RemoveModuleSetFtor &&RemoveModuleSet,
|
||||
FindSymbolFtor &&FindSymbol,
|
||||
FindSymbolInFtor &&FindSymbolIn)
|
||||
: AddModule(AddModule), RemoveModule(RemoveModule),
|
||||
: AddModuleSet(AddModuleSet), RemoveModuleSet(RemoveModuleSet),
|
||||
FindSymbol(FindSymbol), FindSymbolIn(FindSymbolIn)
|
||||
{}
|
||||
|
||||
template <typename ModuleT, typename MemoryManagerPtrT,
|
||||
template <typename ModuleSetT, typename MemoryManagerPtrT,
|
||||
typename SymbolResolverPtrT>
|
||||
ModuleHandleT addModule(ModuleT Ms, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
return AddModule(std::move(Ms), std::move(MemMgr), std::move(Resolver));
|
||||
ModuleSetHandleT addModuleSet(ModuleSetT Ms, MemoryManagerPtrT MemMgr,
|
||||
SymbolResolverPtrT Resolver) {
|
||||
return AddModuleSet(std::move(Ms), std::move(MemMgr), std::move(Resolver));
|
||||
}
|
||||
|
||||
void removeModule(ModuleHandleT H) {
|
||||
RemoveModule(H);
|
||||
void removeModuleSet(ModuleSetHandleT H) {
|
||||
RemoveModuleSet(H);
|
||||
}
|
||||
|
||||
JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
|
||||
return FindSymbol(Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
|
||||
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
|
||||
bool ExportedSymbolsOnly) {
|
||||
return FindSymbolIn(H, Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
private:
|
||||
AddModuleFtor AddModule;
|
||||
RemoveModuleFtor RemoveModule;
|
||||
AddModuleSetFtor AddModuleSet;
|
||||
RemoveModuleSetFtor RemoveModuleSet;
|
||||
FindSymbolFtor FindSymbol;
|
||||
FindSymbolInFtor FindSymbolIn;
|
||||
};
|
||||
|
||||
template <typename ModuleHandleT,
|
||||
typename AddModuleFtor,
|
||||
typename RemoveModuleFtor,
|
||||
template <typename ModuleSetHandleT,
|
||||
typename AddModuleSetFtor,
|
||||
typename RemoveModuleSetFtor,
|
||||
typename FindSymbolFtor,
|
||||
typename FindSymbolInFtor>
|
||||
MockBaseLayer<ModuleHandleT, AddModuleFtor, RemoveModuleFtor,
|
||||
MockBaseLayer<ModuleSetHandleT, AddModuleSetFtor, RemoveModuleSetFtor,
|
||||
FindSymbolFtor, FindSymbolInFtor>
|
||||
createMockBaseLayer(AddModuleFtor &&AddModule,
|
||||
RemoveModuleFtor &&RemoveModule,
|
||||
createMockBaseLayer(AddModuleSetFtor &&AddModuleSet,
|
||||
RemoveModuleSetFtor &&RemoveModuleSet,
|
||||
FindSymbolFtor &&FindSymbol,
|
||||
FindSymbolInFtor &&FindSymbolIn) {
|
||||
return MockBaseLayer<ModuleHandleT, AddModuleFtor, RemoveModuleFtor,
|
||||
return MockBaseLayer<ModuleSetHandleT, AddModuleSetFtor, RemoveModuleSetFtor,
|
||||
FindSymbolFtor, FindSymbolInFtor>(
|
||||
std::forward<AddModuleFtor>(AddModule),
|
||||
std::forward<RemoveModuleFtor>(RemoveModule),
|
||||
std::forward<AddModuleSetFtor>(AddModuleSet),
|
||||
std::forward<RemoveModuleSetFtor>(RemoveModuleSet),
|
||||
std::forward<FindSymbolFtor>(FindSymbol),
|
||||
std::forward<FindSymbolInFtor>(FindSymbolIn));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue