mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Revert "[ORC] Switch from shared_ptr to unique_ptr for addModule methods."
This reverts commit r327566, it breaks test/ExecutionEngine/OrcMCJIT/test-global-ctors.ll. The test doesn't crash with a stack trace, unfortunately. It merely returns 1 as the exit code. ASan didn't produce a report, and I reproduced this on my Linux machine and Windows box. llvm-svn: 327576
This commit is contained in:
parent
7475763bc6
commit
f02357933a
@ -51,7 +51,7 @@ private:
|
|||||||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||||
|
|
||||||
using OptimizeFunction =
|
using OptimizeFunction =
|
||||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||||
|
|
||||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ public:
|
|||||||
std::make_shared<SectionMemoryManager>(), Resolver};
|
std::make_shared<SectionMemoryManager>(), Resolver};
|
||||||
}),
|
}),
|
||||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||||
OptimizeLayer(CompileLayer, [this](std::unique_ptr<Module> M) {
|
OptimizeLayer(CompileLayer, [this](std::shared_ptr<Module> M) {
|
||||||
return optimizeModule(std::move(M));
|
return optimizeModule(std::move(M));
|
||||||
}) {
|
}) {
|
||||||
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
|
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
|
||||||
@ -104,7 +104,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
std::shared_ptr<Module> optimizeModule(std::shared_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());
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ private:
|
|||||||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||||
|
|
||||||
using OptimizeFunction =
|
using OptimizeFunction =
|
||||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||||
|
|
||||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public:
|
|||||||
}),
|
}),
|
||||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||||
OptimizeLayer(CompileLayer,
|
OptimizeLayer(CompileLayer,
|
||||||
[this](std::unique_ptr<Module> M) {
|
[this](std::shared_ptr<Module> M) {
|
||||||
return optimizeModule(std::move(M));
|
return optimizeModule(std::move(M));
|
||||||
}),
|
}),
|
||||||
CompileCallbackManager(
|
CompileCallbackManager(
|
||||||
@ -127,7 +127,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
std::shared_ptr<Module> optimizeModule(std::shared_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());
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ private:
|
|||||||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||||
|
|
||||||
using OptimizeFunction =
|
using OptimizeFunction =
|
||||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||||
|
|
||||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ public:
|
|||||||
}),
|
}),
|
||||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||||
OptimizeLayer(CompileLayer,
|
OptimizeLayer(CompileLayer,
|
||||||
[this](std::unique_ptr<Module> M) {
|
[this](std::shared_ptr<Module> M) {
|
||||||
return optimizeModule(std::move(M));
|
return optimizeModule(std::move(M));
|
||||||
}),
|
}),
|
||||||
CompileCallbackMgr(
|
CompileCallbackMgr(
|
||||||
@ -207,7 +207,7 @@ private:
|
|||||||
return MangledNameStream.str();
|
return MangledNameStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
std::shared_ptr<Module> optimizeModule(std::shared_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());
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ private:
|
|||||||
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer;
|
||||||
|
|
||||||
using OptimizeFunction =
|
using OptimizeFunction =
|
||||||
std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>;
|
||||||
|
|
||||||
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer;
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ public:
|
|||||||
}),
|
}),
|
||||||
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
|
||||||
OptimizeLayer(CompileLayer,
|
OptimizeLayer(CompileLayer,
|
||||||
[this](std::unique_ptr<Module> M) {
|
[this](std::shared_ptr<Module> M) {
|
||||||
return optimizeModule(std::move(M));
|
return optimizeModule(std::move(M));
|
||||||
}),
|
}),
|
||||||
Remote(Remote) {
|
Remote(Remote) {
|
||||||
@ -223,7 +223,7 @@ private:
|
|||||||
return MangledNameStream.str();
|
return MangledNameStream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
|
std::shared_ptr<Module> optimizeModule(std::shared_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());
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct LLVMOpaqueSharedModule *LLVMSharedModuleRef;
|
||||||
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
|
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
|
||||||
typedef uint64_t LLVMOrcModuleHandle;
|
typedef uint64_t LLVMOrcModuleHandle;
|
||||||
typedef uint64_t LLVMOrcTargetAddress;
|
typedef uint64_t LLVMOrcTargetAddress;
|
||||||
@ -38,6 +39,33 @@ 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an ORC JIT stack.
|
* Create an ORC JIT stack.
|
||||||
*
|
*
|
||||||
@ -98,7 +126,7 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
|
|||||||
LLVMOrcErrorCode
|
LLVMOrcErrorCode
|
||||||
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||||
LLVMOrcModuleHandle *RetHandle,
|
LLVMOrcModuleHandle *RetHandle,
|
||||||
LLVMModuleRef Mod,
|
LLVMSharedModuleRef Mod,
|
||||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||||
void *SymbolResolverCtx);
|
void *SymbolResolverCtx);
|
||||||
|
|
||||||
@ -108,7 +136,7 @@ LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
|||||||
LLVMOrcErrorCode
|
LLVMOrcErrorCode
|
||||||
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||||
LLVMOrcModuleHandle *RetHandle,
|
LLVMOrcModuleHandle *RetHandle,
|
||||||
LLVMModuleRef Mod,
|
LLVMSharedModuleRef Mod,
|
||||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||||
void *SymbolResolverCtx);
|
void *SymbolResolverCtx);
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ private:
|
|||||||
|
|
||||||
struct LogicalDylib {
|
struct LogicalDylib {
|
||||||
struct SourceModuleEntry {
|
struct SourceModuleEntry {
|
||||||
std::unique_ptr<Module> SourceMod;
|
std::shared_ptr<Module> SourceMod;
|
||||||
std::set<Function*> StubsToClone;
|
std::set<Function*> StubsToClone;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ private:
|
|||||||
StubsMgr(std::move(StubsMgr)) {}
|
StubsMgr(std::move(StubsMgr)) {}
|
||||||
|
|
||||||
SourceModuleHandle
|
SourceModuleHandle
|
||||||
addSourceModule(std::unique_ptr<Module> M) {
|
addSourceModule(std::shared_ptr<Module> M) {
|
||||||
SourceModuleHandle H = SourceModules.size();
|
SourceModuleHandle H = SourceModules.size();
|
||||||
SourceModules.push_back(SourceModuleEntry());
|
SourceModules.push_back(SourceModuleEntry());
|
||||||
SourceModules.back().SourceMod = std::move(M);
|
SourceModules.back().SourceMod = std::move(M);
|
||||||
@ -232,7 +232,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Add a module to the compile-on-demand layer.
|
/// @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");
|
assert(!LogicalDylibs.count(K) && "VModuleKey K already in use");
|
||||||
auto I = LogicalDylibs.insert(
|
auto I = LogicalDylibs.insert(
|
||||||
@ -244,7 +244,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Add extra modules to an existing logical module.
|
/// @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));
|
return addLogicalModule(LogicalDylibs[K], std::move(M));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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 :
|
// Rename all static functions / globals to $static.X :
|
||||||
// This will unique the names across all modules in the logical dylib,
|
// This will unique the names across all modules in the logical dylib,
|
||||||
|
@ -36,33 +36,18 @@ template <typename BaseLayerT, typename CompileFtor>
|
|||||||
class IRCompileLayer {
|
class IRCompileLayer {
|
||||||
public:
|
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
|
/// @brief Construct an IRCompileLayer with the given BaseLayer, which must
|
||||||
/// implement the ObjectLayer concept.
|
/// implement the ObjectLayer concept.
|
||||||
IRCompileLayer(BaseLayerT &BaseLayer, CompileFtor Compile,
|
IRCompileLayer(BaseLayerT &BaseLayer, CompileFtor Compile)
|
||||||
NotifyCompiledCallback NotifyCompiled = NotifyCompiledCallback())
|
: BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
|
||||||
: BaseLayer(BaseLayer), Compile(std::move(Compile)),
|
|
||||||
NotifyCompiled(std::move(NotifyCompiled)) {}
|
|
||||||
|
|
||||||
/// @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 (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
|
/// @brief Compile the module, and add the resulting object to the base layer
|
||||||
/// along with the given memory manager and symbol resolver.
|
/// along with the given memory manager and symbol resolver.
|
||||||
Error addModule(VModuleKey K, std::unique_ptr<Module> M) {
|
Error addModule(VModuleKey K, std::shared_ptr<Module> M) {
|
||||||
if (auto Err = BaseLayer.addObject(std::move(K), Compile(*M)))
|
return BaseLayer.addObject(std::move(K), Compile(*M));
|
||||||
return Err;
|
|
||||||
if (NotifyCompiled)
|
|
||||||
NotifyCompiled(std::move(K), std::move(M));
|
|
||||||
return Error::success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Remove the module associated with the VModuleKey K.
|
/// @brief Remove the module associated with the VModuleKey K.
|
||||||
@ -97,7 +82,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
BaseLayerT &BaseLayer;
|
BaseLayerT &BaseLayer;
|
||||||
CompileFtor Compile;
|
CompileFtor Compile;
|
||||||
NotifyCompiledCallback NotifyCompiled;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace orc
|
} // end namespace orc
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
/// the layer below, along with the memory manager and symbol resolver.
|
/// the layer below, along with the memory manager and symbol resolver.
|
||||||
///
|
///
|
||||||
/// @return A handle for the added modules.
|
/// @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)));
|
return BaseLayer.addModule(std::move(K), Transform(std::move(M)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,9 @@ namespace orc {
|
|||||||
/// JITSymbol::getAddress) for a symbol contained in this layer.
|
/// JITSymbol::getAddress) for a symbol contained in this layer.
|
||||||
template <typename BaseLayerT> class LazyEmittingLayer {
|
template <typename BaseLayerT> class LazyEmittingLayer {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
class EmissionDeferredModule {
|
class EmissionDeferredModule {
|
||||||
public:
|
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)) {}
|
: K(std::move(K)), M(std::move(M)) {}
|
||||||
|
|
||||||
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
|
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
|
||||||
@ -188,7 +187,7 @@ private:
|
|||||||
|
|
||||||
enum { NotEmitted, Emitting, Emitted } EmitState = NotEmitted;
|
enum { NotEmitted, Emitting, Emitted } EmitState = NotEmitted;
|
||||||
VModuleKey K;
|
VModuleKey K;
|
||||||
std::unique_ptr<Module> M;
|
std::shared_ptr<Module> M;
|
||||||
mutable std::unique_ptr<StringMap<const GlobalValue*>> MangledSymbols;
|
mutable std::unique_ptr<StringMap<const GlobalValue*>> MangledSymbols;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -201,7 +200,7 @@ public:
|
|||||||
LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
|
LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
|
||||||
|
|
||||||
/// @brief Add the given module to the lazy emitting layer.
|
/// @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");
|
assert(!ModuleMap.count(K) && "VModuleKey K already in use");
|
||||||
ModuleMap[K] =
|
ModuleMap[K] =
|
||||||
llvm::make_unique<EmissionDeferredModule>(std::move(K), std::move(M));
|
llvm::make_unique<EmissionDeferredModule>(std::move(K), std::move(M));
|
||||||
|
@ -12,6 +12,14 @@
|
|||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) {
|
LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) {
|
||||||
TargetMachine *TM2(unwrap(TM));
|
TargetMachine *TM2(unwrap(TM));
|
||||||
|
|
||||||
@ -68,25 +76,23 @@ LLVMOrcErrorCode LLVMOrcSetIndirectStubPointer(LLVMOrcJITStackRef JITStack,
|
|||||||
LLVMOrcErrorCode
|
LLVMOrcErrorCode
|
||||||
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
LLVMOrcAddEagerlyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||||
LLVMOrcModuleHandle *RetHandle,
|
LLVMOrcModuleHandle *RetHandle,
|
||||||
LLVMModuleRef Mod,
|
LLVMSharedModuleRef Mod,
|
||||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||||
void *SymbolResolverCtx) {
|
void *SymbolResolverCtx) {
|
||||||
OrcCBindingsStack &J = *unwrap(JITStack);
|
OrcCBindingsStack &J = *unwrap(JITStack);
|
||||||
std::unique_ptr<Module> M(unwrap(Mod));
|
std::shared_ptr<Module> *M(unwrap(Mod));
|
||||||
return J.addIRModuleEager(*RetHandle, std::move(M), SymbolResolver,
|
return J.addIRModuleEager(*RetHandle, *M, SymbolResolver, SymbolResolverCtx);
|
||||||
SymbolResolverCtx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMOrcErrorCode
|
LLVMOrcErrorCode
|
||||||
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack,
|
||||||
LLVMOrcModuleHandle *RetHandle,
|
LLVMOrcModuleHandle *RetHandle,
|
||||||
LLVMModuleRef Mod,
|
LLVMSharedModuleRef Mod,
|
||||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||||
void *SymbolResolverCtx) {
|
void *SymbolResolverCtx) {
|
||||||
OrcCBindingsStack &J = *unwrap(JITStack);
|
OrcCBindingsStack &J = *unwrap(JITStack);
|
||||||
std::unique_ptr<Module> M(unwrap(Mod));
|
std::shared_ptr<Module> *M(unwrap(Mod));
|
||||||
return J.addIRModuleLazy(*RetHandle, std::move(M), SymbolResolver,
|
return J.addIRModuleLazy(*RetHandle, *M, SymbolResolver, SymbolResolverCtx);
|
||||||
SymbolResolverCtx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMOrcErrorCode
|
LLVMOrcErrorCode
|
||||||
|
@ -43,6 +43,8 @@ namespace llvm {
|
|||||||
|
|
||||||
class OrcCBindingsStack;
|
class OrcCBindingsStack;
|
||||||
|
|
||||||
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::shared_ptr<Module>,
|
||||||
|
LLVMSharedModuleRef)
|
||||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcCBindingsStack, LLVMOrcJITStackRef)
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcCBindingsStack, LLVMOrcJITStackRef)
|
||||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
||||||
|
|
||||||
@ -282,7 +284,7 @@ public:
|
|||||||
}
|
}
|
||||||
template <typename LayerT>
|
template <typename LayerT>
|
||||||
LLVMOrcErrorCode
|
LLVMOrcErrorCode
|
||||||
addIRModule(orc::VModuleKey &RetKey, LayerT &Layer, std::unique_ptr<Module> M,
|
addIRModule(orc::VModuleKey &RetKey, LayerT &Layer, std::shared_ptr<Module> M,
|
||||||
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
|
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
|
||||||
LLVMOrcSymbolResolverFn ExternalResolver,
|
LLVMOrcSymbolResolverFn ExternalResolver,
|
||||||
void *ExternalResolverCtx) {
|
void *ExternalResolverCtx) {
|
||||||
@ -321,7 +323,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
LLVMOrcErrorCode addIRModuleEager(orc::VModuleKey &RetKey,
|
LLVMOrcErrorCode addIRModuleEager(orc::VModuleKey &RetKey,
|
||||||
std::unique_ptr<Module> M,
|
std::shared_ptr<Module> M,
|
||||||
LLVMOrcSymbolResolverFn ExternalResolver,
|
LLVMOrcSymbolResolverFn ExternalResolver,
|
||||||
void *ExternalResolverCtx) {
|
void *ExternalResolverCtx) {
|
||||||
return addIRModule(RetKey, CompileLayer, std::move(M),
|
return addIRModule(RetKey, CompileLayer, std::move(M),
|
||||||
@ -330,7 +332,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
LLVMOrcErrorCode addIRModuleLazy(orc::VModuleKey &RetKey,
|
LLVMOrcErrorCode addIRModuleLazy(orc::VModuleKey &RetKey,
|
||||||
std::unique_ptr<Module> M,
|
std::shared_ptr<Module> M,
|
||||||
LLVMOrcSymbolResolverFn ExternalResolver,
|
LLVMOrcSymbolResolverFn ExternalResolver,
|
||||||
void *ExternalResolverCtx) {
|
void *ExternalResolverCtx) {
|
||||||
return addIRModule(RetKey, CODLayer, std::move(M),
|
return addIRModule(RetKey, CODLayer, std::move(M),
|
||||||
|
@ -125,7 +125,7 @@ OrcMCJITReplacement::runFunction(Function *F,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OrcMCJITReplacement::runStaticConstructorsDestructors(bool isDtors) {
|
void OrcMCJITReplacement::runStaticConstructorsDestructors(bool isDtors) {
|
||||||
for (auto &M : Modules)
|
for (auto &M : LocalModules)
|
||||||
ExecutionEngine::runStaticConstructorsDestructors(*M, isDtors);
|
ExecutionEngine::runStaticConstructorsDestructors(*M, isDtors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ class ObjectCache;
|
|||||||
namespace orc {
|
namespace orc {
|
||||||
|
|
||||||
class OrcMCJITReplacement : public ExecutionEngine {
|
class OrcMCJITReplacement : public ExecutionEngine {
|
||||||
|
|
||||||
// OrcMCJITReplacement needs to do a little extra book-keeping to ensure that
|
// OrcMCJITReplacement needs to do a little extra book-keeping to ensure that
|
||||||
// Orc's automatic finalization doesn't kick in earlier than MCJIT clients are
|
// Orc's automatic finalization doesn't kick in earlier than MCJIT clients are
|
||||||
// expecting - see finalizeMemory.
|
// expecting - see finalizeMemory.
|
||||||
@ -236,10 +235,7 @@ public:
|
|||||||
return ObjectLayerT::Resources{this->MemMgr, this->Resolver};
|
return ObjectLayerT::Resources{this->MemMgr, this->Resolver};
|
||||||
},
|
},
|
||||||
NotifyObjectLoaded, NotifyFinalized),
|
NotifyObjectLoaded, NotifyFinalized),
|
||||||
CompileLayer(ObjectLayer, SimpleCompiler(*this->TM),
|
CompileLayer(ObjectLayer, SimpleCompiler(*this->TM)),
|
||||||
[this](VModuleKey K, std::unique_ptr<Module> M) {
|
|
||||||
Modules.push_back(std::move(M));
|
|
||||||
}),
|
|
||||||
LazyEmitLayer(CompileLayer) {}
|
LazyEmitLayer(CompileLayer) {}
|
||||||
|
|
||||||
static void Register() {
|
static void Register() {
|
||||||
@ -254,7 +250,16 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
|
assert(M->getDataLayout() == getDataLayout() && "DataLayout Mismatch");
|
||||||
}
|
}
|
||||||
cantFail(LazyEmitLayer.addModule(ES.allocateVModule(), std::move(M)));
|
auto *MPtr = M.release();
|
||||||
|
ShouldDelete[MPtr] = true;
|
||||||
|
auto Deleter = [this](Module *Mod) {
|
||||||
|
auto I = ShouldDelete.find(Mod);
|
||||||
|
if (I != ShouldDelete.end() && I->second)
|
||||||
|
delete Mod;
|
||||||
|
};
|
||||||
|
LocalModules.push_back(std::shared_ptr<Module>(MPtr, std::move(Deleter)));
|
||||||
|
cantFail(
|
||||||
|
LazyEmitLayer.addModule(ES.allocateVModule(), LocalModules.back()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addObjectFile(std::unique_ptr<object::ObjectFile> O) override {
|
void addObjectFile(std::unique_ptr<object::ObjectFile> O) override {
|
||||||
@ -274,14 +279,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool removeModule(Module *M) override {
|
bool removeModule(Module *M) override {
|
||||||
auto I = Modules.begin();
|
for (auto I = LocalModules.begin(), E = LocalModules.end(); I != E; ++I) {
|
||||||
for (auto E = Modules.end(); I != E; ++I)
|
if (I->get() == M) {
|
||||||
if (I->get() == M)
|
ShouldDelete[M] = false;
|
||||||
break;
|
LocalModules.erase(I);
|
||||||
if (I == Modules.end())
|
return true;
|
||||||
return false;
|
}
|
||||||
Modules.erase(I);
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t getSymbolAddress(StringRef Name) {
|
uint64_t getSymbolAddress(StringRef Name) {
|
||||||
@ -433,6 +438,7 @@ private:
|
|||||||
// delete blocks in LocalModules refer to the ShouldDelete map, so
|
// delete blocks in LocalModules refer to the ShouldDelete map, so
|
||||||
// LocalModules needs to be destructed before ShouldDelete.
|
// LocalModules needs to be destructed before ShouldDelete.
|
||||||
std::map<Module*, bool> ShouldDelete;
|
std::map<Module*, bool> ShouldDelete;
|
||||||
|
std::vector<std::shared_ptr<Module>> LocalModules;
|
||||||
|
|
||||||
NotifyObjectLoadedT NotifyObjectLoaded;
|
NotifyObjectLoadedT NotifyObjectLoaded;
|
||||||
NotifyFinalizedT NotifyFinalized;
|
NotifyFinalizedT NotifyFinalized;
|
||||||
|
@ -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::unique_ptr<Module> M) { return M; };
|
return [](std::shared_ptr<Module> M) { return M; };
|
||||||
|
|
||||||
case DumpKind::DumpFuncsToStdOut:
|
case DumpKind::DumpFuncsToStdOut:
|
||||||
return [](std::unique_ptr<Module> M) {
|
return [](std::shared_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::unique_ptr<Module> M) {
|
return [](std::shared_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::unique_ptr<Module> M) {
|
return [](std::shared_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);
|
||||||
@ -148,7 +148,7 @@ int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms,
|
|||||||
|
|
||||||
// Add the module, look up main and run it.
|
// Add the module, look up main and run it.
|
||||||
for (auto &M : Ms)
|
for (auto &M : Ms)
|
||||||
cantFail(J.addModule(std::move(M)));
|
cantFail(J.addModule(std::shared_ptr<Module>(std::move(M))));
|
||||||
|
|
||||||
if (auto MainSym = J.findSymbol("main")) {
|
if (auto MainSym = J.findSymbol("main")) {
|
||||||
typedef int (*MainFnPtr)(int, const char*[]);
|
typedef int (*MainFnPtr)(int, const char*[]);
|
||||||
|
@ -51,7 +51,7 @@ 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::unique_ptr<Module>(std::unique_ptr<Module>)>;
|
std::function<std::shared_ptr<Module>(std::shared_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;
|
||||||
@ -106,7 +106,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Error addModule(std::unique_ptr<Module> M) {
|
Error addModule(std::shared_ptr<Module> M) {
|
||||||
if (M->getDataLayout().isDefault())
|
if (M->getDataLayout().isDefault())
|
||||||
M->setDataLayout(DL);
|
M->setDataLayout(DL);
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#include "llvm/ExecutionEngine/Orc/NullResolver.h"
|
#include "llvm/ExecutionEngine/Orc/NullResolver.h"
|
||||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||||
#include "llvm/IR/Module.h"
|
|
||||||
#include "llvm/Object/ObjectFile.h"
|
#include "llvm/Object/ObjectFile.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
@ -303,7 +302,7 @@ TEST(ObjectTransformLayerTest, Main) {
|
|||||||
// Make sure that the calls from IRCompileLayer to ObjectTransformLayer
|
// Make sure that the calls from IRCompileLayer to ObjectTransformLayer
|
||||||
// compile.
|
// compile.
|
||||||
cantFail(CompileLayer.addModule(ES.allocateVModule(),
|
cantFail(CompileLayer.addModule(ES.allocateVModule(),
|
||||||
std::unique_ptr<llvm::Module>()));
|
std::shared_ptr<llvm::Module>()));
|
||||||
|
|
||||||
// Make sure that the calls from ObjectTransformLayer to ObjectLinkingLayer
|
// Make sure that the calls from ObjectTransformLayer to ObjectLinkingLayer
|
||||||
// compile.
|
// compile.
|
||||||
|
@ -73,8 +73,9 @@ 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());
|
||||||
LLVMOrcAddEagerlyCompiledIR(JITStack, &CCtx->H, wrap(CCtx->M.release()),
|
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(CCtx->M.release()));
|
||||||
myResolver, nullptr);
|
LLVMOrcAddEagerlyCompiledIR(JITStack, &CCtx->H, SM, myResolver, nullptr);
|
||||||
|
LLVMOrcDisposeSharedModuleRef(SM);
|
||||||
CCtx->Compiled = true;
|
CCtx->Compiled = true;
|
||||||
LLVMOrcTargetAddress MainAddr;
|
LLVMOrcTargetAddress MainAddr;
|
||||||
LLVMOrcGetSymbolAddress(JITStack, &MainAddr, "main");
|
LLVMOrcGetSymbolAddress(JITStack, &MainAddr, "main");
|
||||||
@ -96,8 +97,10 @@ TEST_F(OrcCAPIExecutionTest, TestEagerIRCompilation) {
|
|||||||
|
|
||||||
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
|
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
|
||||||
|
|
||||||
|
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M.release()));
|
||||||
LLVMOrcModuleHandle H;
|
LLVMOrcModuleHandle H;
|
||||||
LLVMOrcAddEagerlyCompiledIR(JIT, &H, wrap(M.release()), myResolver, nullptr);
|
LLVMOrcAddEagerlyCompiledIR(JIT, &H, SM, myResolver, nullptr);
|
||||||
|
LLVMOrcDisposeSharedModuleRef(SM);
|
||||||
LLVMOrcTargetAddress MainAddr;
|
LLVMOrcTargetAddress MainAddr;
|
||||||
LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
|
LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
|
||||||
MainFnTy MainFn = (MainFnTy)MainAddr;
|
MainFnTy MainFn = (MainFnTy)MainAddr;
|
||||||
@ -122,8 +125,10 @@ TEST_F(OrcCAPIExecutionTest, TestLazyIRCompilation) {
|
|||||||
|
|
||||||
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
|
LLVMOrcGetMangledSymbol(JIT, &testFuncName, "testFunc");
|
||||||
|
|
||||||
|
LLVMSharedModuleRef SM = LLVMOrcMakeSharedModule(wrap(M.release()));
|
||||||
LLVMOrcModuleHandle H;
|
LLVMOrcModuleHandle H;
|
||||||
LLVMOrcAddLazilyCompiledIR(JIT, &H, wrap(M.release()), myResolver, nullptr);
|
LLVMOrcAddLazilyCompiledIR(JIT, &H, SM, myResolver, nullptr);
|
||||||
|
LLVMOrcDisposeSharedModuleRef(SM);
|
||||||
LLVMOrcTargetAddress MainAddr;
|
LLVMOrcTargetAddress MainAddr;
|
||||||
LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
|
LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
|
||||||
MainFnTy MainFn = (MainFnTy)MainAddr;
|
MainFnTy MainFn = (MainFnTy)MainAddr;
|
||||||
|
Loading…
Reference in New Issue
Block a user