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:
Rafael Espindola 2017-06-23 22:50:24 +00:00
parent 33d501f7d1
commit f6242c3e90
21 changed files with 330 additions and 369 deletions

View File

@ -44,7 +44,7 @@ private:
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer; IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
public: public:
using ModuleHandle = decltype(CompileLayer)::ModuleHandleT; using ModuleHandle = decltype(CompileLayer)::ModuleSetHandleT;
KaleidoscopeJIT() KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()), : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
@ -72,11 +72,15 @@ public:
return JITSymbol(nullptr); 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 // Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager. // created SectionMemoryManager.
return CompileLayer.addModule(std::move(M), return CompileLayer.addModuleSet(std::move(Ms),
make_unique<SectionMemoryManager>(), make_unique<SectionMemoryManager>(),
std::move(Resolver)); std::move(Resolver));
} }
JITSymbol findSymbol(const std::string Name) { JITSymbol findSymbol(const std::string Name) {
@ -87,7 +91,7 @@ public:
} }
void removeModule(ModuleHandle H) { void removeModule(ModuleHandle H) {
CompileLayer.removeModule(H); CompileLayer.removeModuleSet(H);
} }
}; };

View File

@ -48,18 +48,18 @@ private:
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer; IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
using OptimizeFunction = 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; IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
public: public:
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT; using ModuleHandle = decltype(OptimizeLayer)::ModuleSetHandleT;
KaleidoscopeJIT() KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()), : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)), CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer, OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) { [this](std::unique_ptr<Module> M) {
return optimizeModule(std::move(M)); return optimizeModule(std::move(M));
}) { }) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr); llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
@ -85,11 +85,15 @@ public:
return JITSymbol(nullptr); 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 // Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager. // created SectionMemoryManager.
return OptimizeLayer.addModule(std::move(M), return OptimizeLayer.addModuleSet(std::move(Ms),
make_unique<SectionMemoryManager>(), make_unique<SectionMemoryManager>(),
std::move(Resolver)); std::move(Resolver));
} }
JITSymbol findSymbol(const std::string Name) { JITSymbol findSymbol(const std::string Name) {
@ -100,11 +104,11 @@ public:
} }
void removeModule(ModuleHandle H) { void removeModule(ModuleHandle H) {
OptimizeLayer.removeModule(H); OptimizeLayer.removeModuleSet(H);
} }
private: 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. // Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get()); auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());

View File

@ -51,7 +51,7 @@ private:
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer; IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
using OptimizeFunction = 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; IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
@ -59,13 +59,13 @@ private:
CompileOnDemandLayer<decltype(OptimizeLayer)> CODLayer; CompileOnDemandLayer<decltype(OptimizeLayer)> CODLayer;
public: public:
using ModuleHandle = decltype(CODLayer)::ModuleHandleT; using ModuleHandle = decltype(CODLayer)::ModuleSetHandleT;
KaleidoscopeJIT() KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()), : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)), CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer, OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) { [this](std::unique_ptr<Module> M) {
return optimizeModule(std::move(M)); return optimizeModule(std::move(M));
}), }),
CompileCallbackManager( CompileCallbackManager(
@ -98,11 +98,15 @@ public:
return JITSymbol(nullptr); 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 // Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager. // created SectionMemoryManager.
return CODLayer.addModule(std::move(M), return CODLayer.addModuleSet(std::move(Ms),
make_unique<SectionMemoryManager>(), make_unique<SectionMemoryManager>(),
std::move(Resolver)); std::move(Resolver));
} }
JITSymbol findSymbol(const std::string Name) { JITSymbol findSymbol(const std::string Name) {
@ -113,11 +117,11 @@ public:
} }
void removeModule(ModuleHandle H) { void removeModule(ModuleHandle H) {
CODLayer.removeModule(H); CODLayer.removeModuleSet(H);
} }
private: 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. // Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get()); auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());

View File

@ -77,7 +77,7 @@ private:
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer; IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
using OptimizeFunction = 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; IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
@ -85,14 +85,14 @@ private:
std::unique_ptr<IndirectStubsManager> IndirectStubsMgr; std::unique_ptr<IndirectStubsManager> IndirectStubsMgr;
public: public:
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT; using ModuleHandle = decltype(OptimizeLayer)::ModuleSetHandleT;
KaleidoscopeJIT() KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), : TM(EngineBuilder().selectTarget()),
DL(TM->createDataLayout()), DL(TM->createDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)), CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer, OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) { [this](std::unique_ptr<Module> M) {
return optimizeModule(std::move(M)); return optimizeModule(std::move(M));
}), }),
CompileCallbackMgr( CompileCallbackMgr(
@ -125,11 +125,15 @@ public:
return JITSymbol(nullptr); 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 // Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager. // created SectionMemoryManager.
return OptimizeLayer.addModule(std::move(M), return OptimizeLayer.addModuleSet(std::move(Ms),
make_unique<SectionMemoryManager>(), make_unique<SectionMemoryManager>(),
std::move(Resolver)); std::move(Resolver));
} }
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) { Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
@ -195,7 +199,7 @@ public:
} }
void removeModule(ModuleHandle H) { void removeModule(ModuleHandle H) {
OptimizeLayer.removeModule(H); OptimizeLayer.removeModuleSet(H);
} }
private: private:
@ -206,7 +210,7 @@ private:
return MangledNameStream.str(); 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. // Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get()); auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());

View File

@ -82,7 +82,7 @@ private:
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer; IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
using OptimizeFunction = 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; IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
@ -91,7 +91,7 @@ private:
MyRemote &Remote; MyRemote &Remote;
public: public:
using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT; using ModuleHandle = decltype(OptimizeLayer)::ModuleSetHandleT;
KaleidoscopeJIT(MyRemote &Remote) KaleidoscopeJIT(MyRemote &Remote)
: TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "", : TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "",
@ -99,7 +99,7 @@ public:
DL(TM->createDataLayout()), DL(TM->createDataLayout()),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)), CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer, OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) { [this](std::unique_ptr<Module> M) {
return optimizeModule(std::move(M)); return optimizeModule(std::move(M));
}), }),
Remote(Remote) { Remote(Remote) {
@ -153,11 +153,15 @@ public:
exit(1); 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 // Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager. // created SectionMemoryManager.
return OptimizeLayer.addModule(std::move(M), return OptimizeLayer.addModuleSet(std::move(Ms),
std::move(MemMgr), std::move(MemMgr),
std::move(Resolver)); std::move(Resolver));
} }
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) { Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
@ -227,7 +231,7 @@ public:
} }
void removeModule(ModuleHandle H) { void removeModule(ModuleHandle H) {
OptimizeLayer.removeModule(H); OptimizeLayer.removeModuleSet(H);
} }
private: private:
@ -238,7 +242,7 @@ private:
return MangledNameStream.str(); 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. // Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get()); auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());

View File

@ -41,7 +41,7 @@ class KaleidoscopeJIT {
public: public:
using ObjLayerT = RTDyldObjectLinkingLayer; using ObjLayerT = RTDyldObjectLinkingLayer;
using CompileLayerT = IRCompileLayer<ObjLayerT, SimpleCompiler>; using CompileLayerT = IRCompileLayer<ObjLayerT, SimpleCompiler>;
using ModuleHandleT = CompileLayerT::ModuleHandleT; using ModuleHandleT = CompileLayerT::ModuleSetHandleT;
KaleidoscopeJIT() KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()), : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
@ -62,9 +62,9 @@ public:
return JITSymbol(nullptr); return JITSymbol(nullptr);
}, },
[](const std::string &S) { return nullptr; }); [](const std::string &S) { return nullptr; });
auto H = CompileLayer.addModule(std::move(M), auto H = CompileLayer.addModuleSet(singletonSet(std::move(M)),
make_unique<SectionMemoryManager>(), make_unique<SectionMemoryManager>(),
std::move(Resolver)); std::move(Resolver));
ModuleHandles.push_back(H); ModuleHandles.push_back(H);
return H; return H;
@ -72,7 +72,7 @@ public:
void removeModule(ModuleHandleT H) { void removeModule(ModuleHandleT H) {
ModuleHandles.erase(find(ModuleHandles, H)); ModuleHandles.erase(find(ModuleHandles, H));
CompileLayer.removeModule(H); CompileLayer.removeModuleSet(H);
} }
JITSymbol findSymbol(const std::string Name) { JITSymbol findSymbol(const std::string Name) {
@ -89,6 +89,12 @@ private:
return MangledName; 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) { JITSymbol findMangledSymbol(const std::string &Name) {
#ifdef LLVM_ON_WIN32 #ifdef LLVM_ON_WIN32
// The symbol lookup of ObjectLinkingLayer uses the SymbolRef::SF_Exported // The symbol lookup of ObjectLinkingLayer uses the SymbolRef::SF_Exported

View File

@ -29,8 +29,6 @@
extern "C" { extern "C" {
#endif #endif
typedef struct LLVMOpaqueSharedModule *LLVMSharedModuleRef;
typedef struct LLVMOpaqueSharedObjectBuffer *LLVMSharedObjectBufferRef;
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef; typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
typedef uint32_t LLVMOrcModuleHandle; typedef uint32_t LLVMOrcModuleHandle;
typedef uint64_t LLVMOrcTargetAddress; typedef uint64_t LLVMOrcTargetAddress;
@ -40,45 +38,6 @@ typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode; 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. * Create an ORC JIT stack.
* *
@ -136,8 +95,7 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
* Add module to be eagerly compiled. * Add module to be eagerly compiled.
*/ */
LLVMOrcModuleHandle LLVMOrcModuleHandle
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
LLVMSharedModuleRef Mod,
LLVMOrcSymbolResolverFn SymbolResolver, LLVMOrcSymbolResolverFn SymbolResolver,
void *SymbolResolverCtx); void *SymbolResolverCtx);
@ -145,8 +103,7 @@ LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
* Add module to be lazily compiled one function at a time. * Add module to be lazily compiled one function at a time.
*/ */
LLVMOrcModuleHandle LLVMOrcModuleHandle
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
LLVMSharedModuleRef Mod,
LLVMOrcSymbolResolverFn SymbolResolver, LLVMOrcSymbolResolverFn SymbolResolver,
void *SymbolResolverCtx); void *SymbolResolverCtx);
@ -154,7 +111,7 @@ LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
* Add an object file. * Add an object file.
*/ */
LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
LLVMSharedObjectBufferRef Obj, LLVMObjectFileRef Obj,
LLVMOrcSymbolResolverFn SymbolResolver, LLVMOrcSymbolResolverFn SymbolResolver,
void *SymbolResolverCtx); void *SymbolResolverCtx);

View File

@ -84,7 +84,7 @@ private:
return LambdaMaterializer<MaterializerFtor>(std::move(M)); return LambdaMaterializer<MaterializerFtor>(std::move(M));
} }
using BaseLayerModuleHandleT = typename BaseLayerT::ModuleHandleT; using BaseLayerModuleSetHandleT = typename BaseLayerT::ModuleSetHandleT;
// Provide type-erasure for the Modules and MemoryManagers. // Provide type-erasure for the Modules and MemoryManagers.
template <typename ResourceT> template <typename ResourceT>
@ -139,11 +139,9 @@ private:
struct LogicalDylib { struct LogicalDylib {
using SymbolResolverFtor = std::function<JITSymbol(const std::string&)>; using SymbolResolverFtor = std::function<JITSymbol(const std::string&)>;
using ModuleAdderFtor = using ModuleAdderFtor = std::function<typename BaseLayerT::ModuleSetHandleT(
std::function<typename BaseLayerT::ModuleHandleT( BaseLayerT &, std::unique_ptr<Module>,
BaseLayerT&, std::unique_ptr<JITSymbolResolver>)>;
std::unique_ptr<Module>,
std::unique_ptr<JITSymbolResolver>)>;
struct SourceModuleEntry { struct SourceModuleEntry {
std::unique_ptr<ResourceOwner<Module>> SourceMod; std::unique_ptr<ResourceOwner<Module>> SourceMod;
@ -181,7 +179,7 @@ private:
void removeModulesFromBaseLayer(BaseLayerT &BaseLayer) { void removeModulesFromBaseLayer(BaseLayerT &BaseLayer) {
for (auto &BLH : BaseLayerHandles) for (auto &BLH : BaseLayerHandles)
BaseLayer.removeModule(BLH); BaseLayer.removeModuleSet(BLH);
} }
std::unique_ptr<JITSymbolResolver> ExternalSymbolResolver; std::unique_ptr<JITSymbolResolver> ExternalSymbolResolver;
@ -190,14 +188,14 @@ private:
StaticGlobalRenamer StaticRenamer; StaticGlobalRenamer StaticRenamer;
ModuleAdderFtor ModuleAdder; ModuleAdderFtor ModuleAdder;
SourceModulesList SourceModules; SourceModulesList SourceModules;
std::vector<BaseLayerModuleHandleT> BaseLayerHandles; std::vector<BaseLayerModuleSetHandleT> BaseLayerHandles;
}; };
using LogicalDylibList = std::list<LogicalDylib>; using LogicalDylibList = std::list<LogicalDylib>;
public: public:
/// @brief Handle to loaded module. /// @brief Handle to a set of loaded modules.
using ModuleHandleT = typename LogicalDylibList::iterator; using ModuleSetHandleT = typename LogicalDylibList::iterator;
/// @brief Module partitioning functor. /// @brief Module partitioning functor.
using PartitioningFtor = std::function<std::set<Function*>(Function&)>; using PartitioningFtor = std::function<std::set<Function*>(Function&)>;
@ -218,15 +216,15 @@ public:
~CompileOnDemandLayer() { ~CompileOnDemandLayer() {
while (!LogicalDylibs.empty()) while (!LogicalDylibs.empty())
removeModule(LogicalDylibs.begin()); removeModuleSet(LogicalDylibs.begin());
} }
/// @brief Add a module to the compile-on-demand layer. /// @brief Add a module to the compile-on-demand layer.
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT> template <typename ModuleSetT, typename MemoryManagerPtrT,
ModuleHandleT addModule(std::shared_ptr<Module> M, typename SymbolResolverPtrT>
MemoryManagerPtrT MemMgr, ModuleSetHandleT addModuleSet(ModuleSetT Ms,
SymbolResolverPtrT Resolver) { MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver) {
LogicalDylibs.push_back(LogicalDylib()); LogicalDylibs.push_back(LogicalDylib());
auto &LD = LogicalDylibs.back(); auto &LD = LogicalDylibs.back();
LD.ExternalSymbolResolver = std::move(Resolver); LD.ExternalSymbolResolver = std::move(Resolver);
@ -238,25 +236,23 @@ public:
LD.ModuleAdder = LD.ModuleAdder =
[&MemMgrRef](BaseLayerT &B, std::unique_ptr<Module> M, [&MemMgrRef](BaseLayerT &B, std::unique_ptr<Module> M,
std::unique_ptr<JITSymbolResolver> R) { 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. // 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()); 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. /// @brief Remove the module represented by the given handle.
/// ///
/// This will remove all modules in the layers below that were derived from /// This will remove all modules in the layers below that were derived from
/// the module represented by H. /// the module represented by H.
void removeModule(ModuleHandleT H) { void removeModuleSet(ModuleSetHandleT H) {
H->removeModulesFromBaseLayer(BaseLayer); H->removeModulesFromBaseLayer(BaseLayer);
LogicalDylibs.erase(H); LogicalDylibs.erase(H);
} }
@ -278,7 +274,7 @@ public:
/// @brief Get the address of a symbol provided by this layer, or some layer /// @brief Get the address of a symbol provided by this layer, or some layer
/// below this one. /// below this one.
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name, JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
bool ExportedSymbolsOnly) { bool ExportedSymbolsOnly) {
return H->findSymbol(BaseLayer, Name, ExportedSymbolsOnly); return H->findSymbol(BaseLayer, Name, ExportedSymbolsOnly);
} }
@ -502,7 +498,7 @@ private:
} }
template <typename PartitionT> template <typename PartitionT>
BaseLayerModuleHandleT BaseLayerModuleSetHandleT
emitPartition(LogicalDylib &LD, emitPartition(LogicalDylib &LD,
typename LogicalDylib::SourceModuleHandle LMId, typename LogicalDylib::SourceModuleHandle LMId,
const PartitionT &Part) { const PartitionT &Part) {

View File

@ -94,7 +94,7 @@ public:
/// @brief Construct a CtorDtorRunner for the given range using the given /// @brief Construct a CtorDtorRunner for the given range using the given
/// name mangling function. /// name mangling function.
CtorDtorRunner(std::vector<std::string> CtorDtorNames, CtorDtorRunner(std::vector<std::string> CtorDtorNames,
typename JITLayerT::ModuleHandleT H) typename JITLayerT::ModuleSetHandleT H)
: CtorDtorNames(std::move(CtorDtorNames)), H(H) {} : CtorDtorNames(std::move(CtorDtorNames)), H(H) {}
/// @brief Run the recorded constructors/destructors through the given JIT /// @brief Run the recorded constructors/destructors through the given JIT
@ -116,7 +116,7 @@ public:
private: private:
std::vector<std::string> CtorDtorNames; 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 /// @brief Support class for static dtor execution. For hosted (in-process) JITs

View File

@ -28,15 +28,15 @@ namespace orc {
/// @brief Eager IR compiling layer. /// @brief Eager IR compiling layer.
/// ///
/// This layer immediately compiles each IR module added via addModule to an /// This layer accepts sets of LLVM IR Modules (via addModuleSet). It
/// object file and adds this module file to the layer below, which must /// immediately compiles each IR module to an object file (each IR Module is
/// implement the object layer concept. /// 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> template <typename BaseLayerT, typename CompileFtor>
class IRCompileLayer { class IRCompileLayer {
public: public:
/// @brief Handle to a set of compiled modules.
/// @brief Handle to a compiled module. using ModuleSetHandleT = typename BaseLayerT::ObjHandleT;
using ModuleHandleT = typename BaseLayerT::ObjHandleT;
/// @brief Construct an IRCompileLayer with the given BaseLayer, which must /// @brief Construct an IRCompileLayer with the given BaseLayer, which must
/// implement the ObjectLayer concept. /// implement the ObjectLayer concept.
@ -46,22 +46,25 @@ public:
/// @brief Get a reference to the compiler functor. /// @brief Get a reference to the compiler functor.
CompileFtor& getCompiler() { return Compile; } CompileFtor& getCompiler() { return Compile; }
/// @brief Compile the module, and add the resulting object to the base layer /// @brief Compile each module in the given module set, then add the resulting
/// along with the given memory manager and symbol resolver. /// set of objects to the base layer along with the memory manager and
/// symbol resolver.
/// ///
/// @return A handle for the added module. /// @return A handle for the added modules.
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT> template <typename ModuleSetT, typename MemoryManagerPtrT,
ModuleHandleT addModule(std::shared_ptr<Module> M, typename SymbolResolverPtrT>
MemoryManagerPtrT MemMgr, ModuleSetHandleT addModuleSet(ModuleSetT Ms,
SymbolResolverPtrT Resolver) { MemoryManagerPtrT MemMgr,
using CompileResult = decltype(Compile(*M)); SymbolResolverPtrT Resolver) {
auto Obj = std::make_shared<CompileResult>(Compile(*M)); 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), return BaseLayer.addObject(std::move(Obj), std::move(MemMgr),
std::move(Resolver)); std::move(Resolver));
} }
/// @brief Remove the module associated with the handle H. /// @brief Remove the module set associated with the handle H.
void removeModule(ModuleHandleT H) { BaseLayer.removeObject(H); } void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeObject(H); }
/// @brief Search for the given named symbol. /// @brief Search for the given named symbol.
/// @param Name The name of the symbol to search for. /// @param Name The name of the symbol to search for.
@ -71,23 +74,23 @@ public:
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly); return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
} }
/// @brief Get the address of the given symbol in compiled module represented /// @brief Get the address of the given symbol in the context of the set of
/// by the handle H. This call is forwarded to the base layer's /// compiled modules represented by the handle H. This call is
/// implementation. /// forwarded to the base layer's implementation.
/// @param H The handle for the module to search in. /// @param H The handle for the module set to search in.
/// @param Name The name of the symbol to search for. /// @param Name The name of the symbol to search for.
/// @param ExportedSymbolsOnly If true, search only for exported symbols. /// @param ExportedSymbolsOnly If true, search only for exported symbols.
/// @return A handle for the given named symbol, if it is found in the /// @return A handle for the given named symbol, if it is found in the
/// given module. /// given module set.
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name, JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
bool ExportedSymbolsOnly) { bool ExportedSymbolsOnly) {
return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly); return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
} }
/// @brief Immediately emit and finalize the module represented by the given /// @brief Immediately emit and finalize the moduleOB set represented by the
/// handle. /// given handle.
/// @param H Handle for module to emit/finalize. /// @param H Handle for module set to emit/finalize.
void emitAndFinalize(ModuleHandleT H) { void emitAndFinalize(ModuleSetHandleT H) {
BaseLayer.emitAndFinalize(H); BaseLayer.emitAndFinalize(H);
} }

View File

@ -22,34 +22,39 @@ namespace orc {
/// @brief IR mutating layer. /// @brief IR mutating layer.
/// ///
/// This layer applies a user supplied transform to each module that is added, /// This layer accepts sets of LLVM IR Modules (via addModuleSet). It
/// then adds the transformed module to the layer below. /// 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> template <typename BaseLayerT, typename TransformFtor>
class IRTransformLayer { class IRTransformLayer {
public: public:
/// @brief Handle to a set of added modules. /// @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 /// @brief Construct an IRTransformLayer with the given BaseLayer
IRTransformLayer(BaseLayerT &BaseLayer, IRTransformLayer(BaseLayerT &BaseLayer,
TransformFtor Transform = TransformFtor()) TransformFtor Transform = TransformFtor())
: BaseLayer(BaseLayer), Transform(std::move(Transform)) {} : BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
/// @brief Apply the transform functor to the module, then add the module to /// @brief Apply the transform functor to each module in the module set, then
/// the layer below, along with the memory manager and symbol resolver. /// 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. /// @return A handle for the added modules.
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT> template <typename ModuleSetT, typename MemoryManagerPtrT,
ModuleHandleT addModule(std::shared_ptr<Module> M, typename SymbolResolverPtrT>
MemoryManagerPtrT MemMgr, ModuleSetHandleT addModuleSet(ModuleSetT Ms,
SymbolResolverPtrT Resolver) { MemoryManagerPtrT MemMgr,
return BaseLayer.addModule(Transform(std::move(M)), std::move(MemMgr), SymbolResolverPtrT Resolver) {
std::move(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. /// @brief Remove the module set associated with the handle H.
void removeModule(ModuleHandleT H) { BaseLayer.removeModule(H); } void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeModuleSet(H); }
/// @brief Search for the given named symbol. /// @brief Search for the given named symbol.
/// @param Name The name of the symbol to search for. /// @param Name The name of the symbol to search for.
@ -59,23 +64,23 @@ public:
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly); return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
} }
/// @brief Get the address of the given symbol in the context of the module /// @brief Get the address of the given symbol in the context of the set of
/// represented by the handle H. This call is forwarded to the base /// modules represented by the handle H. This call is forwarded to the
/// layer's implementation. /// base layer's implementation.
/// @param H The handle for the module to search in. /// @param H The handle for the module set to search in.
/// @param Name The name of the symbol to search for. /// @param Name The name of the symbol to search for.
/// @param ExportedSymbolsOnly If true, search only for exported symbols. /// @param ExportedSymbolsOnly If true, search only for exported symbols.
/// @return A handle for the given named symbol, if it is found in the /// @return A handle for the given named symbol, if it is found in the
/// given module. /// given module set.
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name, JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
bool ExportedSymbolsOnly) { bool ExportedSymbolsOnly) {
return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly); return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
} }
/// @brief Immediately emit and finalize the module represented by the given /// @brief Immediately emit and finalize the module set represented by the
/// handle. /// given handle.
/// @param H Handle for module to emit/finalize. /// @param H Handle for module set to emit/finalize.
void emitAndFinalize(ModuleHandleT H) { void emitAndFinalize(ModuleSetHandleT H) {
BaseLayer.emitAndFinalize(H); BaseLayer.emitAndFinalize(H);
} }

View File

@ -34,20 +34,19 @@ namespace orc {
/// @brief Lazy-emitting IR layer. /// @brief Lazy-emitting IR layer.
/// ///
/// This layer accepts LLVM IR Modules (via addModule), but does not /// This layer accepts sets of LLVM IR Modules (via addModuleSet), but does
/// immediately emit them the layer below. Instead, emissing to the base layer /// not immediately emit them the layer below. Instead, emissing to the base
/// is deferred until the first time the client requests the address (via /// layer is deferred until the first time the client requests the address
/// JITSymbol::getAddress) for a symbol contained in this layer. /// (via JITSymbol::getAddress) for a symbol contained in this layer.
template <typename BaseLayerT> class LazyEmittingLayer { template <typename BaseLayerT> class LazyEmittingLayer {
public: public:
using BaseLayerHandleT = typename BaseLayerT::ModuleSetHandleT;
using BaseLayerHandleT = typename BaseLayerT::ModuleHandleT;
private: private:
class EmissionDeferredModule { class EmissionDeferredSet {
public: public:
EmissionDeferredModule() = default; EmissionDeferredSet() = default;
virtual ~EmissionDeferredModule() = default; virtual ~EmissionDeferredSet() = default;
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) { JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
switch (EmitState) { switch (EmitState) {
@ -85,9 +84,9 @@ private:
llvm_unreachable("Invalid emit-state."); llvm_unreachable("Invalid emit-state.");
} }
void removeModuleFromBaseLayer(BaseLayerT &BaseLayer) { void removeModulesFromBaseLayer(BaseLayerT &BaseLayer) {
if (EmitState != NotEmitted) if (EmitState != NotEmitted)
BaseLayer.removeModule(Handle); BaseLayer.removeModuleSet(Handle);
} }
void emitAndFinalize(BaseLayerT &BaseLayer) { void emitAndFinalize(BaseLayerT &BaseLayer) {
@ -101,9 +100,10 @@ private:
BaseLayer.emitAndFinalize(Handle); BaseLayer.emitAndFinalize(Handle);
} }
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT> template <typename ModuleSetT, typename MemoryManagerPtrT,
static std::unique_ptr<EmissionDeferredModule> typename SymbolResolverPtrT>
create(BaseLayerT &B, std::shared_ptr<Module> M, MemoryManagerPtrT MemMgr, static std::unique_ptr<EmissionDeferredSet>
create(BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver); SymbolResolverPtrT Resolver);
protected: protected:
@ -116,13 +116,14 @@ private:
BaseLayerHandleT Handle; BaseLayerHandleT Handle;
}; };
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT> template <typename ModuleSetT, typename MemoryManagerPtrT,
class EmissionDeferredModuleImpl : public EmissionDeferredModule { typename SymbolResolverPtrT>
class EmissionDeferredSetImpl : public EmissionDeferredSet {
public: public:
EmissionDeferredModuleImpl(std::shared_ptr<Module> M, EmissionDeferredSetImpl(ModuleSetT Ms,
MemoryManagerPtrT MemMgr, MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver) SymbolResolverPtrT Resolver)
: M(std::move(M)), MemMgr(std::move(MemMgr)), : Ms(std::move(Ms)), MemMgr(std::move(MemMgr)),
Resolver(std::move(Resolver)) {} Resolver(std::move(Resolver)) {}
protected: protected:
@ -153,8 +154,8 @@ private:
// We don't need the mangled names set any more: Once we've emitted this // 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. // to the base layer we'll just look for symbols there.
MangledSymbols.reset(); MangledSymbols.reset();
return BaseLayer.addModule(std::move(M), std::move(MemMgr), return BaseLayer.addModuleSet(std::move(Ms), std::move(MemMgr),
std::move(Resolver)); std::move(Resolver));
} }
private: private:
@ -196,54 +197,56 @@ private:
auto Symbols = llvm::make_unique<StringMap<const GlobalValue*>>(); 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, if (auto GV = addGlobalValue(*Symbols, GO, Mang, SearchName,
ExportedSymbolsOnly)) ExportedSymbolsOnly))
return GV; return GV;
}
MangledSymbols = std::move(Symbols); MangledSymbols = std::move(Symbols);
return nullptr; return nullptr;
} }
std::shared_ptr<Module> M; ModuleSetT Ms;
MemoryManagerPtrT MemMgr; MemoryManagerPtrT MemMgr;
SymbolResolverPtrT Resolver; SymbolResolverPtrT Resolver;
mutable std::unique_ptr<StringMap<const GlobalValue*>> MangledSymbols; 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; BaseLayerT &BaseLayer;
ModuleListT ModuleList; ModuleSetListT ModuleSetList;
public: public:
/// @brief Handle to a loaded module. /// @brief Handle to a set of loaded modules.
using ModuleHandleT = typename ModuleListT::iterator; using ModuleSetHandleT = typename ModuleSetListT::iterator;
/// @brief Construct a lazy emitting layer. /// @brief Construct a lazy emitting layer.
LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {} LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
/// @brief Add the given module to the lazy emitting layer. /// @brief Add the given set of modules to the lazy emitting layer.
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT> template <typename ModuleSetT, typename MemoryManagerPtrT,
ModuleHandleT addModule(std::shared_ptr<Module> M, typename SymbolResolverPtrT>
MemoryManagerPtrT MemMgr, ModuleSetHandleT addModuleSet(ModuleSetT Ms,
SymbolResolverPtrT Resolver) { MemoryManagerPtrT MemMgr,
return ModuleList.insert( SymbolResolverPtrT Resolver) {
ModuleList.end(), return ModuleSetList.insert(
EmissionDeferredModule::create(BaseLayer, std::move(M), ModuleSetList.end(),
std::move(MemMgr), EmissionDeferredSet::create(BaseLayer, std::move(Ms), std::move(MemMgr),
std::move(Resolver))); 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 /// This method will free the memory associated with the given module set,
/// in this layer, and the base layer. /// both in this layer, and the base layer.
void removeModule(ModuleHandleT H) { void removeModuleSet(ModuleSetHandleT H) {
(*H)->removeModuleFromBaseLayer(BaseLayer); (*H)->removeModulesFromBaseLayer(BaseLayer);
ModuleList.erase(H); ModuleSetList.erase(H);
} }
/// @brief Search for the given named symbol. /// @brief Search for the given named symbol.
@ -255,40 +258,42 @@ public:
if (auto Symbol = BaseLayer.findSymbol(Name, ExportedSymbolsOnly)) if (auto Symbol = BaseLayer.findSymbol(Name, ExportedSymbolsOnly))
return Symbol; 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 // definition of 'Name' then they will return a JITSymbol that will emit
// the corresponding module when the symbol address is requested. // the corresponding module when the symbol address is requested.
for (auto &DeferredMod : ModuleList) for (auto &DeferredSet : ModuleSetList)
if (auto Symbol = DeferredMod->find(Name, ExportedSymbolsOnly, BaseLayer)) if (auto Symbol = DeferredSet->find(Name, ExportedSymbolsOnly, BaseLayer))
return Symbol; return Symbol;
// If no definition found anywhere return a null symbol. // If no definition found anywhere return a null symbol.
return nullptr; 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. /// 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) { bool ExportedSymbolsOnly) {
return (*H)->find(Name, ExportedSymbolsOnly, BaseLayer); return (*H)->find(Name, ExportedSymbolsOnly, BaseLayer);
} }
/// @brief Immediately emit and finalize the module represented by the given /// @brief Immediately emit and finalize the moduleOB set represented by the
/// handle. /// given handle.
/// @param H Handle for module to emit/finalize. /// @param H Handle for module set to emit/finalize.
void emitAndFinalize(ModuleHandleT H) { void emitAndFinalize(ModuleSetHandleT H) {
(*H)->emitAndFinalize(BaseLayer); (*H)->emitAndFinalize(BaseLayer);
} }
}; };
template <typename BaseLayerT> template <typename BaseLayerT>
template <typename MemoryManagerPtrT, typename SymbolResolverPtrT> template <typename ModuleSetT, typename MemoryManagerPtrT,
std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>::EmissionDeferredModule> typename SymbolResolverPtrT>
LazyEmittingLayer<BaseLayerT>::EmissionDeferredModule::create( std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet>
BaseLayerT &B, std::shared_ptr<Module> M, MemoryManagerPtrT MemMgr, LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet::create(
BaseLayerT &B, ModuleSetT Ms, MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver) { SymbolResolverPtrT Resolver) {
using EDS = EmissionDeferredModuleImpl<MemoryManagerPtrT, SymbolResolverPtrT>; using EDS = EmissionDeferredSetImpl<ModuleSetT, MemoryManagerPtrT,
return llvm::make_unique<EDS>(std::move(M), std::move(MemMgr), SymbolResolverPtrT>;
return llvm::make_unique<EDS>(std::move(Ms), std::move(MemMgr),
std::move(Resolver)); std::move(Resolver));
} }

View File

@ -12,24 +12,6 @@
using namespace llvm; 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) { LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) {
TargetMachine *TM2(unwrap(TM)); TargetMachine *TM2(unwrap(TM));
@ -83,23 +65,21 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
} }
LLVMOrcModuleHandle LLVMOrcModuleHandle
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
LLVMSharedModuleRef Mod,
LLVMOrcSymbolResolverFn SymbolResolver, LLVMOrcSymbolResolverFn SymbolResolver,
void *SymbolResolverCtx) { void *SymbolResolverCtx) {
OrcCBindingsStack &J = *unwrap(JITStack); OrcCBindingsStack &J = *unwrap(JITStack);
std::shared_ptr<Module> *M(unwrap(Mod)); Module *M(unwrap(Mod));
return J.addIRModuleEager(*M, SymbolResolver, SymbolResolverCtx); return J.addIRModuleEager(M, SymbolResolver, SymbolResolverCtx);
} }
LLVMOrcModuleHandle LLVMOrcModuleHandle
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
LLVMSharedModuleRef Mod,
LLVMOrcSymbolResolverFn SymbolResolver, LLVMOrcSymbolResolverFn SymbolResolver,
void *SymbolResolverCtx) { void *SymbolResolverCtx) {
OrcCBindingsStack &J = *unwrap(JITStack); OrcCBindingsStack &J = *unwrap(JITStack);
std::shared_ptr<Module> *M(unwrap(Mod)); Module *M(unwrap(Mod));
return J.addIRModuleLazy(*M, SymbolResolver, SymbolResolverCtx); return J.addIRModuleLazy(M, SymbolResolver, SymbolResolverCtx);
} }
void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H) { void LLVMOrcRemoveModule(LLVMOrcJITStackRef JITStack, LLVMOrcModuleHandle H) {

View File

@ -42,10 +42,6 @@ namespace llvm {
class OrcCBindingsStack; 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(OrcCBindingsStack, LLVMOrcJITStackRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
@ -75,7 +71,7 @@ private:
template <typename LayerT> class GenericHandleImpl : public GenericHandle { template <typename LayerT> class GenericHandleImpl : public GenericHandle {
public: public:
GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleHandleT Handle) GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleSetHandleT Handle)
: Layer(Layer), Handle(std::move(Handle)) {} : Layer(Layer), Handle(std::move(Handle)) {}
JITSymbol findSymbolIn(const std::string &Name, JITSymbol findSymbolIn(const std::string &Name,
@ -83,21 +79,24 @@ private:
return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly); return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly);
} }
void removeModule() override { return Layer.removeModule(Handle); } void removeModule() override { return Layer.removeModuleSet(Handle); }
private: private:
LayerT &Layer; LayerT &Layer;
typename LayerT::ModuleHandleT Handle; typename LayerT::ModuleSetHandleT Handle;
}; };
template <typename LayerT> template <typename LayerT>
std::unique_ptr<GenericHandleImpl<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, return llvm::make_unique<GenericHandleImpl<LayerT>>(Layer,
std::move(Handle)); std::move(Handle));
} }
public: public:
// We need a 'ModuleSetHandleT' to conform to the layer concept.
using ModuleSetHandleT = unsigned;
using ModuleHandleT = unsigned; using ModuleHandleT = unsigned;
OrcCBindingsStack(TargetMachine &TM, OrcCBindingsStack(TargetMachine &TM,
@ -184,7 +183,7 @@ public:
} }
template <typename LayerT> template <typename LayerT>
ModuleHandleT addIRModule(LayerT &Layer, std::shared_ptr<Module> M, ModuleHandleT addIRModule(LayerT &Layer, Module *M,
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr, std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
LLVMOrcSymbolResolverFn ExternalResolver, LLVMOrcSymbolResolverFn ExternalResolver,
void *ExternalResolverCtx) { void *ExternalResolverCtx) {
@ -204,8 +203,11 @@ public:
auto Resolver = createResolver(ExternalResolver, ExternalResolverCtx); auto Resolver = createResolver(ExternalResolver, ExternalResolverCtx);
// Add the module to the JIT. // Add the module to the JIT.
auto LH = Layer.addModule(std::move(M), std::move(MemMgr), std::vector<Module *> S;
std::move(Resolver)); S.push_back(std::move(M));
auto LH = Layer.addModuleSet(std::move(S), std::move(MemMgr),
std::move(Resolver));
ModuleHandleT H = createHandle(Layer, LH); ModuleHandleT H = createHandle(Layer, LH);
// Run the static constructors, and save the static destructor runner for // Run the static constructors, and save the static destructor runner for
@ -218,7 +220,7 @@ public:
return H; return H;
} }
ModuleHandleT addIRModuleEager(std::shared_ptr<Module> M, ModuleHandleT addIRModuleEager(Module *M,
LLVMOrcSymbolResolverFn ExternalResolver, LLVMOrcSymbolResolverFn ExternalResolver,
void *ExternalResolverCtx) { void *ExternalResolverCtx) {
return addIRModule(CompileLayer, std::move(M), return addIRModule(CompileLayer, std::move(M),
@ -226,7 +228,7 @@ public:
std::move(ExternalResolver), ExternalResolverCtx); std::move(ExternalResolver), ExternalResolverCtx);
} }
ModuleHandleT addIRModuleLazy(std::shared_ptr<Module> M, ModuleHandleT addIRModuleLazy(Module *M,
LLVMOrcSymbolResolverFn ExternalResolver, LLVMOrcSymbolResolverFn ExternalResolver,
void *ExternalResolverCtx) { void *ExternalResolverCtx) {
return addIRModule(CODLayer, std::move(M), return addIRModule(CODLayer, std::move(M),
@ -255,7 +257,8 @@ public:
private: private:
template <typename LayerT> template <typename LayerT>
unsigned createHandle(LayerT &Layer, typename LayerT::ModuleHandleT Handle) { unsigned createHandle(LayerT &Layer,
typename LayerT::ModuleSetHandleT Handle) {
unsigned NewHandle; unsigned NewHandle;
if (!FreeHandleIndexes.empty()) { if (!FreeHandleIndexes.empty()) {
NewHandle = FreeHandleIndexes.back(); NewHandle = FreeHandleIndexes.back();

View File

@ -191,15 +191,10 @@ public:
} else { } else {
assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch"); assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
} }
auto *MPtr = M.release(); Modules.push_back(std::move(M));
Retain[MPtr] = false; std::vector<Module *> Ms;
auto Deleter = Ms.push_back(&*Modules.back());
[this](Module *Mod) { LazyEmitLayer.addModuleSet(std::move(Ms), &MemMgr, &Resolver);
if (!Retain[Mod])
delete Mod;
};
LocalModules.push_back(std::shared_ptr<Module>(MPtr, std::move(Deleter)));
LazyEmitLayer.addModule(LocalModules.back(), &MemMgr, &Resolver);
} }
void addObjectFile(std::unique_ptr<object::ObjectFile> O) override { void addObjectFile(std::unique_ptr<object::ObjectFile> O) override {
@ -386,8 +381,6 @@ private:
std::map<ObjectLayerT::ObjHandleT, SectionAddrSet, ObjHandleCompare> std::map<ObjectLayerT::ObjHandleT, SectionAddrSet, ObjHandleCompare>
UnfinalizedSections; UnfinalizedSections;
std::map<Module*, bool> Retain;
std::vector<std::shared_ptr<Module>> LocalModules;
std::vector<object::OwningBinary<object::Archive>> Archives; std::vector<object::OwningBinary<object::Archive>> Archives;
}; };

View File

@ -54,10 +54,10 @@ static cl::opt<bool> OrcInlineStubs("orc-lazy-inline-stubs",
OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() { OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
switch (OrcDumpKind) { switch (OrcDumpKind) {
case DumpKind::NoDump: case DumpKind::NoDump:
return [](std::shared_ptr<Module> M) { return M; }; return [](std::unique_ptr<Module> M) { return M; };
case DumpKind::DumpFuncsToStdOut: case DumpKind::DumpFuncsToStdOut:
return [](std::shared_ptr<Module> M) { return [](std::unique_ptr<Module> M) {
printf("[ "); printf("[ ");
for (const auto &F : *M) { for (const auto &F : *M) {
@ -76,7 +76,7 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
}; };
case DumpKind::DumpModsToStdOut: case DumpKind::DumpModsToStdOut:
return [](std::shared_ptr<Module> M) { return [](std::unique_ptr<Module> M) {
outs() << "----- Module Start -----\n" << *M outs() << "----- Module Start -----\n" << *M
<< "----- Module End -----\n"; << "----- Module End -----\n";
@ -84,7 +84,7 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
}; };
case DumpKind::DumpModsToDisk: case DumpKind::DumpModsToDisk:
return [](std::shared_ptr<Module> M) { return [](std::unique_ptr<Module> M) {
std::error_code EC; std::error_code EC;
raw_fd_ostream Out(M->getModuleIdentifier() + ".ll", EC, raw_fd_ostream Out(M->getModuleIdentifier() + ".ll", EC,
sys::fs::F_Text); sys::fs::F_Text);
@ -147,8 +147,7 @@ int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,
OrcInlineStubs); OrcInlineStubs);
// Add the module, look up main and run it. // Add the module, look up main and run it.
for (auto &M : Ms) J.addModuleSet(std::move(Ms));
J.addModule(std::shared_ptr<Module>(std::move(M)));
auto MainSym = J.findSymbol("main"); auto MainSym = J.findSymbol("main");
if (!MainSym) { if (!MainSym) {

View File

@ -50,11 +50,11 @@ public:
using ObjLayerT = orc::RTDyldObjectLinkingLayer; using ObjLayerT = orc::RTDyldObjectLinkingLayer;
using CompileLayerT = orc::IRCompileLayer<ObjLayerT, orc::SimpleCompiler>; using CompileLayerT = orc::IRCompileLayer<ObjLayerT, orc::SimpleCompiler>;
using TransformFtor = 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 IRDumpLayerT = orc::IRTransformLayer<CompileLayerT, TransformFtor>;
using CODLayerT = orc::CompileOnDemandLayer<IRDumpLayerT, CompileCallbackMgr>; using CODLayerT = orc::CompileOnDemandLayer<IRDumpLayerT, CompileCallbackMgr>;
using IndirectStubsManagerBuilder = CODLayerT::IndirectStubsManagerBuilderT; using IndirectStubsManagerBuilder = CODLayerT::IndirectStubsManagerBuilderT;
using ModuleHandleT = CODLayerT::ModuleHandleT; using ModuleSetHandleT = CODLayerT::ModuleSetHandleT;
OrcLazyJIT(std::unique_ptr<TargetMachine> TM, OrcLazyJIT(std::unique_ptr<TargetMachine> TM,
std::unique_ptr<CompileCallbackMgr> CCMgr, std::unique_ptr<CompileCallbackMgr> CCMgr,
@ -77,9 +77,11 @@ public:
DtorRunner.runViaLayer(CODLayer); DtorRunner.runViaLayer(CODLayer);
} }
void addModule(std::shared_ptr<Module> M) { ModuleSetHandleT addModuleSet(std::vector<std::unique_ptr<Module>> Ms) {
if (M->getDataLayout().isDefault()) // Attach a data-layouts if they aren't already present.
M->setDataLayout(DL); for (auto &M : Ms)
if (M->getDataLayout().isDefault())
M->setDataLayout(DL);
// Rename, bump linkage and record static constructors and destructors. // Rename, bump linkage and record static constructors and destructors.
// We have to do this before we hand over ownership of the module to the // 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; std::vector<std::string> CtorNames, DtorNames;
{ {
unsigned CtorId = 0, DtorId = 0; unsigned CtorId = 0, DtorId = 0;
for (auto Ctor : orc::getConstructors(*M)) { for (auto &M : Ms) {
std::string NewCtorName = ("$static_ctor." + Twine(CtorId++)).str(); for (auto Ctor : orc::getConstructors(*M)) {
Ctor.Func->setName(NewCtorName); std::string NewCtorName = ("$static_ctor." + Twine(CtorId++)).str();
Ctor.Func->setLinkage(GlobalValue::ExternalLinkage); Ctor.Func->setName(NewCtorName);
Ctor.Func->setVisibility(GlobalValue::HiddenVisibility); Ctor.Func->setLinkage(GlobalValue::ExternalLinkage);
CtorNames.push_back(mangle(NewCtorName)); Ctor.Func->setVisibility(GlobalValue::HiddenVisibility);
} CtorNames.push_back(mangle(NewCtorName));
for (auto Dtor : orc::getDestructors(*M)) { }
std::string NewDtorName = ("$static_dtor." + Twine(DtorId++)).str(); for (auto Dtor : orc::getDestructors(*M)) {
Dtor.Func->setLinkage(GlobalValue::ExternalLinkage); std::string NewDtorName = ("$static_dtor." + Twine(DtorId++)).str();
Dtor.Func->setVisibility(GlobalValue::HiddenVisibility); Dtor.Func->setLinkage(GlobalValue::ExternalLinkage);
DtorNames.push_back(mangle(Dtor.Func->getName())); Dtor.Func->setVisibility(GlobalValue::HiddenVisibility);
Dtor.Func->setName(NewDtorName); DtorNames.push_back(mangle(Dtor.Func->getName()));
Dtor.Func->setName(NewDtorName);
}
} }
} }
@ -107,45 +111,41 @@ public:
// 1) Search the JIT symbols. // 1) Search the JIT symbols.
// 2) Check for C++ runtime overrides. // 2) Check for C++ runtime overrides.
// 3) Search the host process (LLI)'s symbol table. // 3) Search the host process (LLI)'s symbol table.
if (ModulesHandle == CODLayerT::ModuleHandleT()) { auto Resolver =
auto Resolver = orc::createLambdaResolver(
orc::createLambdaResolver( [this](const std::string &Name) -> JITSymbol {
[this](const std::string &Name) -> JITSymbol { if (auto Sym = CODLayer.findSymbol(Name, true))
if (auto Sym = CODLayer.findSymbol(Name, true)) return Sym;
return Sym; return CXXRuntimeOverrides.searchOverrides(Name);
return CXXRuntimeOverrides.searchOverrides(Name); },
}, [](const std::string &Name) {
[](const std::string &Name) { if (auto Addr =
if (auto Addr = RTDyldMemoryManager::getSymbolAddressInProcess(Name))
RTDyldMemoryManager::getSymbolAddressInProcess(Name)) return JITSymbol(Addr, JITSymbolFlags::Exported);
return JITSymbol(Addr, JITSymbolFlags::Exported); return JITSymbol(nullptr);
return JITSymbol(nullptr); }
} );
);
// Add the module to the JIT. // Add the module to the JIT.
ModulesHandle = auto H = CODLayer.addModuleSet(std::move(Ms),
CODLayer.addModule(std::move(M), llvm::make_unique<SectionMemoryManager>(),
llvm::make_unique<SectionMemoryManager>(), std::move(Resolver));
std::move(Resolver));
} else
CODLayer.addExtraModule(ModulesHandle, std::move(M));
// Run the static constructors, and save the static destructor runner for // Run the static constructors, and save the static destructor runner for
// execution when the JIT is torn down. // execution when the JIT is torn down.
orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames), orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames), H);
ModulesHandle);
CtorRunner.runViaLayer(CODLayer); CtorRunner.runViaLayer(CODLayer);
IRStaticDestructorRunners.emplace_back(std::move(DtorNames), IRStaticDestructorRunners.emplace_back(std::move(DtorNames), H);
ModulesHandle);
return H;
} }
JITSymbol findSymbol(const std::string &Name) { JITSymbol findSymbol(const std::string &Name) {
return CODLayer.findSymbol(mangle(Name), true); 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); return CODLayer.findSymbolIn(H, mangle(Name), true);
} }
@ -179,7 +179,6 @@ private:
orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides; orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;
std::vector<orc::CtorDtorRunner<CODLayerT>> IRStaticDestructorRunners; std::vector<orc::CtorDtorRunner<CODLayerT>> IRStaticDestructorRunners;
CODLayerT::ModuleHandleT ModulesHandle;
}; };
int runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms, int runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,

View File

@ -14,9 +14,9 @@
namespace { namespace {
struct MockBaseLayer { struct MockBaseLayer {
typedef int ModuleHandleT; typedef int ModuleSetHandleT;
ModuleHandleT addModule( ModuleSetHandleT addModuleSet(
std::shared_ptr<llvm::Module>, std::list<std::unique_ptr<llvm::Module>>,
std::unique_ptr<llvm::RuntimeDyld::MemoryManager> MemMgr, std::unique_ptr<llvm::RuntimeDyld::MemoryManager> MemMgr,
std::unique_ptr<llvm::JITSymbolResolver> Resolver) { std::unique_ptr<llvm::JITSymbolResolver> Resolver) {
EXPECT_FALSE(MemMgr); EXPECT_FALSE(MemMgr);
@ -27,7 +27,7 @@ struct MockBaseLayer {
TEST(LazyEmittingLayerTest, Empty) { TEST(LazyEmittingLayerTest, Empty) {
MockBaseLayer M; MockBaseLayer M;
llvm::orc::LazyEmittingLayer<MockBaseLayer> L(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);
} }
} }

View File

@ -314,7 +314,7 @@ TEST(ObjectTransformLayerTest, Main) {
// compile. // compile.
NullResolver Resolver; NullResolver Resolver;
NullManager Manager; 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 // Make sure that the calls from ObjectTransformLayer to ObjectLinkingLayer
// compile. // compile.

View File

@ -65,9 +65,8 @@ protected:
CompileContext *CCtx = static_cast<CompileContext*>(Ctx); CompileContext *CCtx = static_cast<CompileContext*>(Ctx);
auto *ET = CCtx->APIExecTest; auto *ET = CCtx->APIExecTest;
CCtx->M = ET->createTestModule(ET->TM->getTargetTriple()); CCtx->M = ET->createTestModule(ET->TM->getTargetTriple());
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(CCtx->M.release())); CCtx->H = LLVMOrcAddEagerlyCompiledIR(JITStack, wrap(CCtx->M.get()),
CCtx->H = LLVMOrcAddEagerlyCompiledIR(JITStack, SM, myResolver, nullptr); myResolver, nullptr);
LLVMOrcDisposeSharedModuleRef(SM);
CCtx->Compiled = true; CCtx->Compiled = true;
LLVMOrcTargetAddress MainAddr = LLVMOrcGetSymbolAddress(JITStack, "main"); LLVMOrcTargetAddress MainAddr = LLVMOrcGetSymbolAddress(JITStack, "main");
LLVMOrcSetIndirectStubPointer(JITStack, "foo", MainAddr); LLVMOrcSetIndirectStubPointer(JITStack, "foo", MainAddr);
@ -88,10 +87,8 @@ TEST_F(OrcCAPIExecutionTest, TestEagerIRCompilation) {
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc"); LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M.release()));
LLVMOrcModuleHandle H = LLVMOrcModuleHandle H =
LLVMOrcAddEagerlyCompiledIR(JIT, SM, myResolver, nullptr); LLVMOrcAddEagerlyCompiledIR(JIT, wrap(M.get()), myResolver, nullptr);
LLVMOrcDisposeSharedModuleRef(SM);
MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddress(JIT, "main"); MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddress(JIT, "main");
int Result = MainFn(); int Result = MainFn();
EXPECT_EQ(Result, 42) EXPECT_EQ(Result, 42)
@ -114,10 +111,8 @@ TEST_F(OrcCAPIExecutionTest, TestLazyIRCompilation) {
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc"); LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M.release()));
LLVMOrcModuleHandle H = LLVMOrcModuleHandle H =
LLVMOrcAddLazilyCompiledIR(JIT, SM, myResolver, nullptr); LLVMOrcAddLazilyCompiledIR(JIT, wrap(M.get()), myResolver, nullptr);
LLVMOrcDisposeSharedModuleRef(SM);
MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddress(JIT, "main"); MainFnTy MainFn = (MainFnTy)LLVMOrcGetSymbolAddress(JIT, "main");
int Result = MainFn(); int Result = MainFn();
EXPECT_EQ(Result, 42) EXPECT_EQ(Result, 42)

View File

@ -106,65 +106,65 @@ public:
}; };
template <typename HandleT, template <typename HandleT,
typename AddModuleFtor, typename AddModuleSetFtor,
typename RemoveModuleFtor, typename RemoveModuleSetFtor,
typename FindSymbolFtor, typename FindSymbolFtor,
typename FindSymbolInFtor> typename FindSymbolInFtor>
class MockBaseLayer { class MockBaseLayer {
public: public:
typedef HandleT ModuleHandleT; typedef HandleT ModuleSetHandleT;
MockBaseLayer(AddModuleFtor &&AddModule, MockBaseLayer(AddModuleSetFtor &&AddModuleSet,
RemoveModuleFtor &&RemoveModule, RemoveModuleSetFtor &&RemoveModuleSet,
FindSymbolFtor &&FindSymbol, FindSymbolFtor &&FindSymbol,
FindSymbolInFtor &&FindSymbolIn) FindSymbolInFtor &&FindSymbolIn)
: AddModule(AddModule), RemoveModule(RemoveModule), : AddModuleSet(AddModuleSet), RemoveModuleSet(RemoveModuleSet),
FindSymbol(FindSymbol), FindSymbolIn(FindSymbolIn) FindSymbol(FindSymbol), FindSymbolIn(FindSymbolIn)
{} {}
template <typename ModuleT, typename MemoryManagerPtrT, template <typename ModuleSetT, typename MemoryManagerPtrT,
typename SymbolResolverPtrT> typename SymbolResolverPtrT>
ModuleHandleT addModule(ModuleT Ms, MemoryManagerPtrT MemMgr, ModuleSetHandleT addModuleSet(ModuleSetT Ms, MemoryManagerPtrT MemMgr,
SymbolResolverPtrT Resolver) { SymbolResolverPtrT Resolver) {
return AddModule(std::move(Ms), std::move(MemMgr), std::move(Resolver)); return AddModuleSet(std::move(Ms), std::move(MemMgr), std::move(Resolver));
} }
void removeModule(ModuleHandleT H) { void removeModuleSet(ModuleSetHandleT H) {
RemoveModule(H); RemoveModuleSet(H);
} }
JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) { JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
return FindSymbol(Name, ExportedSymbolsOnly); return FindSymbol(Name, ExportedSymbolsOnly);
} }
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name, JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
bool ExportedSymbolsOnly) { bool ExportedSymbolsOnly) {
return FindSymbolIn(H, Name, ExportedSymbolsOnly); return FindSymbolIn(H, Name, ExportedSymbolsOnly);
} }
private: private:
AddModuleFtor AddModule; AddModuleSetFtor AddModuleSet;
RemoveModuleFtor RemoveModule; RemoveModuleSetFtor RemoveModuleSet;
FindSymbolFtor FindSymbol; FindSymbolFtor FindSymbol;
FindSymbolInFtor FindSymbolIn; FindSymbolInFtor FindSymbolIn;
}; };
template <typename ModuleHandleT, template <typename ModuleSetHandleT,
typename AddModuleFtor, typename AddModuleSetFtor,
typename RemoveModuleFtor, typename RemoveModuleSetFtor,
typename FindSymbolFtor, typename FindSymbolFtor,
typename FindSymbolInFtor> typename FindSymbolInFtor>
MockBaseLayer<ModuleHandleT, AddModuleFtor, RemoveModuleFtor, MockBaseLayer<ModuleSetHandleT, AddModuleSetFtor, RemoveModuleSetFtor,
FindSymbolFtor, FindSymbolInFtor> FindSymbolFtor, FindSymbolInFtor>
createMockBaseLayer(AddModuleFtor &&AddModule, createMockBaseLayer(AddModuleSetFtor &&AddModuleSet,
RemoveModuleFtor &&RemoveModule, RemoveModuleSetFtor &&RemoveModuleSet,
FindSymbolFtor &&FindSymbol, FindSymbolFtor &&FindSymbol,
FindSymbolInFtor &&FindSymbolIn) { FindSymbolInFtor &&FindSymbolIn) {
return MockBaseLayer<ModuleHandleT, AddModuleFtor, RemoveModuleFtor, return MockBaseLayer<ModuleSetHandleT, AddModuleSetFtor, RemoveModuleSetFtor,
FindSymbolFtor, FindSymbolInFtor>( FindSymbolFtor, FindSymbolInFtor>(
std::forward<AddModuleFtor>(AddModule), std::forward<AddModuleSetFtor>(AddModuleSet),
std::forward<RemoveModuleFtor>(RemoveModule), std::forward<RemoveModuleSetFtor>(RemoveModuleSet),
std::forward<FindSymbolFtor>(FindSymbol), std::forward<FindSymbolFtor>(FindSymbol),
std::forward<FindSymbolInFtor>(FindSymbolIn)); std::forward<FindSymbolInFtor>(FindSymbolIn));
} }