summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm-c/OrcBindings.h32
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h10
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h24
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h2
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h7
5 files changed, 43 insertions, 32 deletions
diff --git a/llvm/include/llvm-c/OrcBindings.h b/llvm/include/llvm-c/OrcBindings.h
index fda43edd7bb..95bdef81593 100644
--- a/llvm/include/llvm-c/OrcBindings.h
+++ b/llvm/include/llvm-c/OrcBindings.h
@@ -29,6 +29,7 @@
extern "C" {
#endif
+typedef struct LLVMOpaqueSharedModule *LLVMSharedModuleRef;
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
typedef uint64_t LLVMOrcModuleHandle;
typedef uint64_t LLVMOrcTargetAddress;
@@ -39,6 +40,33 @@ 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);
+
+/**
* Create an ORC JIT stack.
*
* The client owns the resulting stack, and must call OrcDisposeInstance(...)
@@ -98,7 +126,7 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
LLVMOrcErrorCode
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
LLVMOrcModuleHandle *RetHandle,
- LLVMModuleRef Mod,
+ LLVMSharedModuleRef Mod,
LLVMOrcSymbolResolverFn SymbolResolver,
void *SymbolResolverCtx);
@@ -108,7 +136,7 @@ LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
LLVMOrcErrorCode
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
LLVMOrcModuleHandle *RetHandle,
- LLVMModuleRef Mod,
+ LLVMSharedModuleRef Mod,
LLVMOrcSymbolResolverFn SymbolResolver,
void *SymbolResolverCtx);
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
index b393c66d842..f0e9be9fd28 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
@@ -138,7 +138,7 @@ private:
struct LogicalDylib {
struct SourceModuleEntry {
- std::unique_ptr<Module> SourceMod;
+ std::shared_ptr<Module> SourceMod;
std::set<Function*> StubsToClone;
};
@@ -153,7 +153,7 @@ private:
StubsMgr(std::move(StubsMgr)) {}
SourceModuleHandle
- addSourceModule(std::unique_ptr<Module> M) {
+ addSourceModule(std::shared_ptr<Module> M) {
SourceModuleHandle H = SourceModules.size();
SourceModules.push_back(SourceModuleEntry());
SourceModules.back().SourceMod = std::move(M);
@@ -232,7 +232,7 @@ public:
}
/// @brief Add a module to the compile-on-demand layer.
- Error addModule(VModuleKey K, std::unique_ptr<Module> M) {
+ Error addModule(VModuleKey K, std::shared_ptr<Module> M) {
assert(!LogicalDylibs.count(K) && "VModuleKey K already in use");
auto I = LogicalDylibs.insert(
@@ -244,7 +244,7 @@ public:
}
/// @brief Add extra modules to an existing logical module.
- Error addExtraModule(VModuleKey K, std::unique_ptr<Module> M) {
+ Error addExtraModule(VModuleKey K, std::shared_ptr<Module> M) {
return addLogicalModule(LogicalDylibs[K], std::move(M));
}
@@ -311,7 +311,7 @@ public:
private:
- Error addLogicalModule(LogicalDylib &LD, std::unique_ptr<Module> SrcMPtr) {
+ Error addLogicalModule(LogicalDylib &LD, std::shared_ptr<Module> SrcMPtr) {
// Rename all static functions / globals to $static.X :
// This will unique the names across all modules in the logical dylib,
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
index 56ad57b0176..045dfc16b74 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
@@ -36,33 +36,18 @@ template <typename BaseLayerT, typename CompileFtor>
class IRCompileLayer {
public:
- /// @brief Callback type for notifications when modules are compiled.
- using NotifyCompiledCallback = std::function<void(VModuleKey K,
- std::unique_ptr<Module>)>;
-
/// @brief Construct an IRCompileLayer with the given BaseLayer, which must
/// implement the ObjectLayer concept.
- IRCompileLayer(BaseLayerT &BaseLayer, CompileFtor Compile,
- NotifyCompiledCallback NotifyCompiled = NotifyCompiledCallback())
- : BaseLayer(BaseLayer), Compile(std::move(Compile)),
- NotifyCompiled(std::move(NotifyCompiled)) {}
+ IRCompileLayer(BaseLayerT &BaseLayer, CompileFtor Compile)
+ : BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
/// @brief Get a reference to the compiler functor.
CompileFtor& getCompiler() { return Compile; }
- /// @brief (Re)set the NotifyCompiled callback.
- void setNotifyCompiled(NotifyCompiledCallback NotifyCompiled) {
- this->NotifyCompiled = std::move(NotifyCompiled);
- }
-
/// @brief Compile the module, and add the resulting object to the base layer
/// along with the given memory manager and symbol resolver.
- Error addModule(VModuleKey K, std::unique_ptr<Module> M) {
- if (auto Err = BaseLayer.addObject(std::move(K), Compile(*M)))
- return Err;
- if (NotifyCompiled)
- NotifyCompiled(std::move(K), std::move(M));
- return Error::success();
+ Error addModule(VModuleKey K, std::shared_ptr<Module> M) {
+ return BaseLayer.addObject(std::move(K), Compile(*M));
}
/// @brief Remove the module associated with the VModuleKey K.
@@ -97,7 +82,6 @@ public:
private:
BaseLayerT &BaseLayer;
CompileFtor Compile;
- NotifyCompiledCallback NotifyCompiled;
};
} // end namespace orc
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h
index 4f1fe7ba0f5..2158ca9ac4c 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h
@@ -40,7 +40,7 @@ public:
/// the layer below, along with the memory manager and symbol resolver.
///
/// @return A handle for the added modules.
- Error addModule(VModuleKey K, std::unique_ptr<Module> M) {
+ Error addModule(VModuleKey K, std::shared_ptr<Module> M) {
return BaseLayer.addModule(std::move(K), Transform(std::move(M)));
}
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h
index d218b0542ce..35792eab6f9 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h
@@ -41,10 +41,9 @@ namespace orc {
/// JITSymbol::getAddress) for a symbol contained in this layer.
template <typename BaseLayerT> class LazyEmittingLayer {
private:
-
class EmissionDeferredModule {
public:
- EmissionDeferredModule(VModuleKey K, std::unique_ptr<Module> M)
+ EmissionDeferredModule(VModuleKey K, std::shared_ptr<Module> M)
: K(std::move(K)), M(std::move(M)) {}
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
@@ -188,7 +187,7 @@ private:
enum { NotEmitted, Emitting, Emitted } EmitState = NotEmitted;
VModuleKey K;
- std::unique_ptr<Module> M;
+ std::shared_ptr<Module> M;
mutable std::unique_ptr<StringMap<const GlobalValue*>> MangledSymbols;
};
@@ -201,7 +200,7 @@ public:
LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
/// @brief Add the given module to the lazy emitting layer.
- Error addModule(VModuleKey K, std::unique_ptr<Module> M) {
+ Error addModule(VModuleKey K, std::shared_ptr<Module> M) {
assert(!ModuleMap.count(K) && "VModuleKey K already in use");
ModuleMap[K] =
llvm::make_unique<EmissionDeferredModule>(std::move(K), std::move(M));
OpenPOWER on IntegriCloud