2017-06-20 07:37:52 +08:00
|
|
|
//===- OrcCBindingsStack.h - Orc JIT stack for C bindings -----*- C++ -*---===//
|
2015-10-28 10:40:04 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_EXECUTIONENGINE_ORC_ORCCBINDINGSSTACK_H
|
|
|
|
#define LLVM_LIB_EXECUTIONENGINE_ORC_ORCCBINDINGSSTACK_H
|
|
|
|
|
2016-04-26 05:21:20 +08:00
|
|
|
#include "llvm-c/OrcBindings.h"
|
2017-06-20 07:37:52 +08:00
|
|
|
#include "llvm-c/TargetMachine.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ExecutionEngine/JITSymbol.h"
|
2015-10-28 10:40:04 +08:00
|
|
|
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
|
|
|
|
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
|
|
|
|
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
|
|
|
|
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
|
2017-06-20 07:37:52 +08:00
|
|
|
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
|
2017-02-20 13:45:14 +08:00
|
|
|
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
2017-06-20 07:37:52 +08:00
|
|
|
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
|
|
|
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Mangler.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/Support/CBindingWrapping.h"
|
2016-04-26 03:56:45 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
2017-06-20 07:37:52 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-10-30 11:20:21 +08:00
|
|
|
class OrcCBindingsStack;
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2017-06-24 07:25:28 +08:00
|
|
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::shared_ptr<Module>,
|
|
|
|
LLVMSharedModuleRef)
|
2015-10-30 11:20:21 +08:00
|
|
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcCBindingsStack, LLVMOrcJITStackRef)
|
|
|
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2017-09-17 11:25:03 +08:00
|
|
|
namespace detail {
|
2017-06-23 05:06:54 +08:00
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
class GenericHandle {
|
|
|
|
public:
|
2017-06-20 07:37:52 +08:00
|
|
|
virtual ~GenericHandle() = default;
|
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
virtual JITSymbol findSymbolIn(const std::string &Name,
|
|
|
|
bool ExportedSymbolsOnly) = 0;
|
2017-07-07 10:59:13 +08:00
|
|
|
virtual Error removeModule() = 0;
|
2015-10-28 10:40:04 +08:00
|
|
|
};
|
|
|
|
|
2016-04-26 05:21:20 +08:00
|
|
|
template <typename LayerT> class GenericHandleImpl : public GenericHandle {
|
2015-10-28 10:40:04 +08:00
|
|
|
public:
|
2017-06-24 07:25:28 +08:00
|
|
|
GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleHandleT Handle)
|
2016-04-26 05:21:20 +08:00
|
|
|
: Layer(Layer), Handle(std::move(Handle)) {}
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol findSymbolIn(const std::string &Name,
|
|
|
|
bool ExportedSymbolsOnly) override {
|
2015-10-28 10:40:04 +08:00
|
|
|
return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly);
|
|
|
|
}
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
Error removeModule() override { return Layer.removeModule(Handle); }
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
LayerT &Layer;
|
2017-06-24 07:25:28 +08:00
|
|
|
typename LayerT::ModuleHandleT Handle;
|
2015-10-28 10:40:04 +08:00
|
|
|
};
|
|
|
|
|
2017-09-17 11:25:03 +08:00
|
|
|
template <>
|
|
|
|
class GenericHandleImpl<orc::RTDyldObjectLinkingLayer>
|
|
|
|
: public GenericHandle {
|
|
|
|
private:
|
|
|
|
using LayerT = orc::RTDyldObjectLinkingLayer;
|
|
|
|
public:
|
|
|
|
|
|
|
|
GenericHandleImpl(LayerT &Layer, typename LayerT::ObjHandleT Handle)
|
|
|
|
: Layer(Layer), Handle(std::move(Handle)) {}
|
|
|
|
|
|
|
|
JITSymbol findSymbolIn(const std::string &Name,
|
|
|
|
bool ExportedSymbolsOnly) override {
|
|
|
|
return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly);
|
|
|
|
}
|
|
|
|
|
|
|
|
Error removeModule() override { return Layer.removeObject(Handle); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
LayerT &Layer;
|
|
|
|
typename LayerT::ObjHandleT Handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename LayerT, typename HandleT>
|
2015-10-28 10:40:04 +08:00
|
|
|
std::unique_ptr<GenericHandleImpl<LayerT>>
|
2017-09-17 11:25:03 +08:00
|
|
|
createGenericHandle(LayerT &Layer, HandleT Handle) {
|
2015-10-28 10:40:04 +08:00
|
|
|
return llvm::make_unique<GenericHandleImpl<LayerT>>(Layer,
|
|
|
|
std::move(Handle));
|
|
|
|
}
|
|
|
|
|
2017-09-17 11:25:03 +08:00
|
|
|
} // end namespace detail
|
|
|
|
|
|
|
|
class OrcCBindingsStack {
|
|
|
|
public:
|
|
|
|
|
|
|
|
using CompileCallbackMgr = orc::JITCompileCallbackManager;
|
|
|
|
using ObjLayerT = orc::RTDyldObjectLinkingLayer;
|
|
|
|
using CompileLayerT = orc::IRCompileLayer<ObjLayerT, orc::SimpleCompiler>;
|
|
|
|
using CODLayerT =
|
|
|
|
orc::CompileOnDemandLayer<CompileLayerT, CompileCallbackMgr>;
|
|
|
|
|
|
|
|
using CallbackManagerBuilder =
|
|
|
|
std::function<std::unique_ptr<CompileCallbackMgr>()>;
|
|
|
|
|
|
|
|
using IndirectStubsManagerBuilder = CODLayerT::IndirectStubsManagerBuilderT;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
using OwningObject = object::OwningBinary<object::ObjectFile>;
|
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
public:
|
2017-06-20 07:37:52 +08:00
|
|
|
using ModuleHandleT = unsigned;
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2015-11-04 00:40:37 +08:00
|
|
|
OrcCBindingsStack(TargetMachine &TM,
|
2016-01-21 06:24:26 +08:00
|
|
|
std::unique_ptr<CompileCallbackMgr> CCMgr,
|
2015-10-28 10:40:04 +08:00
|
|
|
IndirectStubsManagerBuilder IndirectStubsMgrBuilder)
|
2016-01-21 06:24:26 +08:00
|
|
|
: DL(TM.createDataLayout()), IndirectStubsMgr(IndirectStubsMgrBuilder()),
|
2017-06-20 07:37:52 +08:00
|
|
|
CCMgr(std::move(CCMgr)),
|
2017-07-04 12:42:30 +08:00
|
|
|
ObjectLayer(
|
|
|
|
[]() {
|
|
|
|
return std::make_shared<SectionMemoryManager>();
|
|
|
|
}),
|
2016-01-21 06:24:26 +08:00
|
|
|
CompileLayer(ObjectLayer, orc::SimpleCompiler(TM)),
|
|
|
|
CODLayer(CompileLayer,
|
|
|
|
[](Function &F) { return std::set<Function *>({&F}); },
|
|
|
|
*this->CCMgr, std::move(IndirectStubsMgrBuilder), false),
|
|
|
|
CXXRuntimeOverrides(
|
|
|
|
[this](const std::string &S) { return mangle(S); }) {}
|
2015-10-28 10:40:04 +08:00
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
LLVMOrcErrorCode shutdown() {
|
2015-10-28 10:40:04 +08:00
|
|
|
// Run any destructors registered with __cxa_atexit.
|
|
|
|
CXXRuntimeOverrides.runDestructors();
|
|
|
|
// Run any IR destructors.
|
|
|
|
for (auto &DtorRunner : IRStaticDestructorRunners)
|
2017-07-07 10:59:13 +08:00
|
|
|
if (auto Err = DtorRunner.runViaLayer(*this))
|
|
|
|
return mapError(std::move(Err));
|
|
|
|
return LLVMOrcErrSuccess;
|
2015-10-28 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string mangle(StringRef Name) {
|
|
|
|
std::string MangledName;
|
|
|
|
{
|
|
|
|
raw_string_ostream MangledNameStream(MangledName);
|
|
|
|
Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
|
|
|
|
}
|
|
|
|
return MangledName;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename PtrTy>
|
2016-08-02 04:49:11 +08:00
|
|
|
static PtrTy fromTargetAddress(JITTargetAddress Addr) {
|
2015-10-28 10:40:04 +08:00
|
|
|
return reinterpret_cast<PtrTy>(static_cast<uintptr_t>(Addr));
|
|
|
|
}
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
|
|
|
|
LLVMOrcErrorCode
|
|
|
|
createLazyCompileCallback(JITTargetAddress &RetAddr,
|
|
|
|
LLVMOrcLazyCompileCallbackFn Callback,
|
2015-10-30 11:20:21 +08:00
|
|
|
void *CallbackCtx) {
|
2017-09-03 08:50:42 +08:00
|
|
|
if (auto CCInfoOrErr = CCMgr->getCompileCallback()) {
|
|
|
|
auto &CCInfo = *CCInfoOrErr;
|
|
|
|
CCInfo.setCompileAction([=]() -> JITTargetAddress {
|
|
|
|
return Callback(wrap(this), CallbackCtx);
|
|
|
|
});
|
|
|
|
RetAddr = CCInfo.getAddress();
|
|
|
|
return LLVMOrcErrSuccess;
|
|
|
|
} else
|
|
|
|
return mapError(CCInfoOrErr.takeError());
|
2015-10-30 11:20:21 +08:00
|
|
|
}
|
|
|
|
|
2016-04-26 05:21:20 +08:00
|
|
|
LLVMOrcErrorCode createIndirectStub(StringRef StubName,
|
2016-08-02 04:49:11 +08:00
|
|
|
JITTargetAddress Addr) {
|
2016-04-26 03:56:45 +08:00
|
|
|
return mapError(
|
2016-04-26 05:21:20 +08:00
|
|
|
IndirectStubsMgr->createStub(StubName, Addr, JITSymbolFlags::Exported));
|
2015-10-30 11:20:21 +08:00
|
|
|
}
|
|
|
|
|
2016-04-26 05:21:20 +08:00
|
|
|
LLVMOrcErrorCode setIndirectStubPointer(StringRef Name,
|
2016-08-02 04:49:11 +08:00
|
|
|
JITTargetAddress Addr) {
|
2016-04-26 03:56:45 +08:00
|
|
|
return mapError(IndirectStubsMgr->updatePointer(Name, Addr));
|
2015-10-30 11:20:21 +08:00
|
|
|
}
|
|
|
|
|
2018-01-20 06:24:13 +08:00
|
|
|
std::shared_ptr<LegacyJITSymbolResolver>
|
2015-10-30 11:20:21 +08:00
|
|
|
createResolver(LLVMOrcSymbolResolverFn ExternalResolver,
|
2015-10-28 10:40:04 +08:00
|
|
|
void *ExternalResolverCtx) {
|
2016-05-26 00:23:59 +08:00
|
|
|
return orc::createLambdaResolver(
|
2016-08-02 04:49:11 +08:00
|
|
|
[this, ExternalResolver, ExternalResolverCtx](const std::string &Name)
|
2017-07-07 10:59:13 +08:00
|
|
|
-> JITSymbol {
|
2016-04-26 05:21:20 +08:00
|
|
|
// Search order:
|
|
|
|
// 1. JIT'd symbols.
|
|
|
|
// 2. Runtime overrides.
|
|
|
|
// 3. External resolver (if present).
|
|
|
|
|
|
|
|
if (auto Sym = CODLayer.findSymbol(Name, true))
|
2016-08-02 04:49:11 +08:00
|
|
|
return Sym;
|
2017-07-07 10:59:13 +08:00
|
|
|
else if (auto Err = Sym.takeError())
|
|
|
|
return Sym.takeError();
|
|
|
|
|
2016-04-26 05:21:20 +08:00
|
|
|
if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name))
|
|
|
|
return Sym;
|
|
|
|
|
|
|
|
if (ExternalResolver)
|
2016-08-02 04:49:11 +08:00
|
|
|
return JITSymbol(
|
2016-04-26 05:21:20 +08:00
|
|
|
ExternalResolver(Name.c_str(), ExternalResolverCtx),
|
2017-06-20 07:37:52 +08:00
|
|
|
JITSymbolFlags::Exported);
|
2016-04-26 05:21:20 +08:00
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
return JITSymbol(nullptr);
|
2016-04-26 05:21:20 +08:00
|
|
|
},
|
2017-07-07 10:59:13 +08:00
|
|
|
[](const std::string &Name) -> JITSymbol {
|
2016-08-02 04:49:11 +08:00
|
|
|
return JITSymbol(nullptr);
|
2016-04-26 05:21:20 +08:00
|
|
|
});
|
2015-10-28 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename LayerT>
|
2017-07-07 10:59:13 +08:00
|
|
|
LLVMOrcErrorCode
|
|
|
|
addIRModule(ModuleHandleT &RetHandle, LayerT &Layer,
|
|
|
|
std::shared_ptr<Module> M,
|
|
|
|
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
|
|
|
|
LLVMOrcSymbolResolverFn ExternalResolver,
|
|
|
|
void *ExternalResolverCtx) {
|
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
// Attach a data-layout if one isn't already present.
|
|
|
|
if (M->getDataLayout().isDefault())
|
|
|
|
M->setDataLayout(DL);
|
|
|
|
|
|
|
|
// Record the static constructors and destructors. We have to do this before
|
|
|
|
// we hand over ownership of the module to the JIT.
|
|
|
|
std::vector<std::string> CtorNames, DtorNames;
|
|
|
|
for (auto Ctor : orc::getConstructors(*M))
|
|
|
|
CtorNames.push_back(mangle(Ctor.Func->getName()));
|
|
|
|
for (auto Dtor : orc::getDestructors(*M))
|
|
|
|
DtorNames.push_back(mangle(Dtor.Func->getName()));
|
|
|
|
|
|
|
|
// Create the resolver.
|
|
|
|
auto Resolver = createResolver(ExternalResolver, ExternalResolverCtx);
|
|
|
|
|
|
|
|
// Add the module to the JIT.
|
2017-07-07 10:59:13 +08:00
|
|
|
ModuleHandleT H;
|
|
|
|
if (auto LHOrErr = Layer.addModule(std::move(M), std::move(Resolver)))
|
|
|
|
H = createHandle(Layer, *LHOrErr);
|
|
|
|
else
|
|
|
|
return mapError(LHOrErr.takeError());
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
// Run the static constructors, and save the static destructor runner for
|
|
|
|
// execution when the JIT is torn down.
|
|
|
|
orc::CtorDtorRunner<OrcCBindingsStack> CtorRunner(std::move(CtorNames), H);
|
2017-07-07 10:59:13 +08:00
|
|
|
if (auto Err = CtorRunner.runViaLayer(*this))
|
|
|
|
return mapError(std::move(Err));
|
2015-10-28 10:40:04 +08:00
|
|
|
|
|
|
|
IRStaticDestructorRunners.emplace_back(std::move(DtorNames), H);
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
RetHandle = H;
|
|
|
|
return LLVMOrcErrSuccess;
|
2015-10-28 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
LLVMOrcErrorCode addIRModuleEager(ModuleHandleT &RetHandle,
|
|
|
|
std::shared_ptr<Module> M,
|
|
|
|
LLVMOrcSymbolResolverFn ExternalResolver,
|
|
|
|
void *ExternalResolverCtx) {
|
|
|
|
return addIRModule(RetHandle, CompileLayer, std::move(M),
|
2015-10-28 10:40:04 +08:00
|
|
|
llvm::make_unique<SectionMemoryManager>(),
|
|
|
|
std::move(ExternalResolver), ExternalResolverCtx);
|
|
|
|
}
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
LLVMOrcErrorCode addIRModuleLazy(ModuleHandleT &RetHandle,
|
|
|
|
std::shared_ptr<Module> M,
|
|
|
|
LLVMOrcSymbolResolverFn ExternalResolver,
|
|
|
|
void *ExternalResolverCtx) {
|
|
|
|
return addIRModule(RetHandle, CODLayer, std::move(M),
|
2016-04-26 05:21:20 +08:00
|
|
|
llvm::make_unique<SectionMemoryManager>(),
|
2015-10-28 10:40:04 +08:00
|
|
|
std::move(ExternalResolver), ExternalResolverCtx);
|
|
|
|
}
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
LLVMOrcErrorCode removeModule(ModuleHandleT H) {
|
|
|
|
if (auto Err = GenericHandles[H]->removeModule())
|
|
|
|
return mapError(std::move(Err));
|
2015-10-28 10:40:04 +08:00
|
|
|
GenericHandles[H] = nullptr;
|
|
|
|
FreeHandleIndexes.push_back(H);
|
2017-07-07 10:59:13 +08:00
|
|
|
return LLVMOrcErrSuccess;
|
2015-10-28 10:40:04 +08:00
|
|
|
}
|
|
|
|
|
2017-09-17 11:25:03 +08:00
|
|
|
LLVMOrcErrorCode addObject(ModuleHandleT &RetHandle,
|
|
|
|
std::unique_ptr<MemoryBuffer> ObjBuffer,
|
|
|
|
LLVMOrcSymbolResolverFn ExternalResolver,
|
|
|
|
void *ExternalResolverCtx) {
|
|
|
|
if (auto ObjOrErr =
|
|
|
|
object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef())) {
|
|
|
|
auto &Obj = *ObjOrErr;
|
|
|
|
auto OwningObj =
|
|
|
|
std::make_shared<OwningObject>(std::move(Obj), std::move(ObjBuffer));
|
|
|
|
|
|
|
|
// Create the resolver.
|
|
|
|
auto Resolver = createResolver(ExternalResolver, ExternalResolverCtx);
|
|
|
|
|
|
|
|
ModuleHandleT H;
|
|
|
|
if (auto HOrErr = ObjectLayer.addObject(std::move(OwningObj),
|
|
|
|
std::move(Resolver)))
|
|
|
|
H = createHandle(ObjectLayer, *HOrErr);
|
|
|
|
else
|
|
|
|
return mapError(HOrErr.takeError());
|
|
|
|
|
|
|
|
RetHandle = H;
|
|
|
|
|
|
|
|
return LLVMOrcErrSuccess;
|
|
|
|
} else
|
|
|
|
return mapError(ObjOrErr.takeError());
|
|
|
|
}
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
JITSymbol findSymbol(const std::string &Name,
|
|
|
|
bool ExportedSymbolsOnly) {
|
2015-10-30 11:20:21 +08:00
|
|
|
if (auto Sym = IndirectStubsMgr->findStub(Name, ExportedSymbolsOnly))
|
|
|
|
return Sym;
|
2015-10-28 10:40:04 +08:00
|
|
|
return CODLayer.findSymbol(mangle(Name), ExportedSymbolsOnly);
|
|
|
|
}
|
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
|
|
|
|
bool ExportedSymbolsOnly) {
|
2015-10-28 10:40:04 +08:00
|
|
|
return GenericHandles[H]->findSymbolIn(Name, ExportedSymbolsOnly);
|
|
|
|
}
|
|
|
|
|
2017-07-07 10:59:13 +08:00
|
|
|
LLVMOrcErrorCode findSymbolAddress(JITTargetAddress &RetAddr,
|
|
|
|
const std::string &Name,
|
|
|
|
bool ExportedSymbolsOnly) {
|
|
|
|
RetAddr = 0;
|
|
|
|
if (auto Sym = findSymbol(Name, ExportedSymbolsOnly)) {
|
|
|
|
// Successful lookup, non-null symbol:
|
|
|
|
if (auto AddrOrErr = Sym.getAddress()) {
|
|
|
|
RetAddr = *AddrOrErr;
|
|
|
|
return LLVMOrcErrSuccess;
|
|
|
|
} else
|
|
|
|
return mapError(AddrOrErr.takeError());
|
|
|
|
} else if (auto Err = Sym.takeError()) {
|
|
|
|
// Lookup failure - report error.
|
|
|
|
return mapError(std::move(Err));
|
|
|
|
}
|
|
|
|
// Otherwise we had a successful lookup but got a null result. We already
|
|
|
|
// set RetAddr to '0' above, so just return success.
|
|
|
|
return LLVMOrcErrSuccess;
|
|
|
|
}
|
|
|
|
|
2016-04-26 05:21:20 +08:00
|
|
|
const std::string &getErrorMessage() const { return ErrMsg; }
|
2016-04-26 03:56:45 +08:00
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
private:
|
2017-09-17 11:25:03 +08:00
|
|
|
template <typename LayerT, typename HandleT>
|
|
|
|
unsigned createHandle(LayerT &Layer, HandleT Handle) {
|
2015-10-28 10:40:04 +08:00
|
|
|
unsigned NewHandle;
|
|
|
|
if (!FreeHandleIndexes.empty()) {
|
|
|
|
NewHandle = FreeHandleIndexes.back();
|
|
|
|
FreeHandleIndexes.pop_back();
|
2017-09-17 11:25:03 +08:00
|
|
|
GenericHandles[NewHandle] =
|
|
|
|
detail::createGenericHandle(Layer, std::move(Handle));
|
2015-10-28 10:40:04 +08:00
|
|
|
return NewHandle;
|
|
|
|
} else {
|
|
|
|
NewHandle = GenericHandles.size();
|
2017-09-17 11:25:03 +08:00
|
|
|
GenericHandles.push_back(
|
|
|
|
detail::createGenericHandle(Layer, std::move(Handle)));
|
2015-10-28 10:40:04 +08:00
|
|
|
}
|
|
|
|
return NewHandle;
|
|
|
|
}
|
|
|
|
|
2016-04-26 03:56:45 +08:00
|
|
|
LLVMOrcErrorCode mapError(Error Err) {
|
|
|
|
LLVMOrcErrorCode Result = LLVMOrcErrSuccess;
|
2016-04-26 05:21:20 +08:00
|
|
|
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
|
|
|
|
// Handler of last resort.
|
|
|
|
Result = LLVMOrcErrGeneric;
|
|
|
|
ErrMsg = "";
|
|
|
|
raw_string_ostream ErrStream(ErrMsg);
|
|
|
|
EIB.log(ErrStream);
|
|
|
|
});
|
2016-04-26 03:56:45 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2015-10-28 10:40:04 +08:00
|
|
|
DataLayout DL;
|
|
|
|
SectionMemoryManager CCMgrMemMgr;
|
|
|
|
|
2016-01-21 01:39:52 +08:00
|
|
|
std::unique_ptr<orc::IndirectStubsManager> IndirectStubsMgr;
|
|
|
|
|
2015-11-04 00:40:37 +08:00
|
|
|
std::unique_ptr<CompileCallbackMgr> CCMgr;
|
2015-10-28 10:40:04 +08:00
|
|
|
ObjLayerT ObjectLayer;
|
|
|
|
CompileLayerT CompileLayer;
|
|
|
|
CODLayerT CODLayer;
|
|
|
|
|
2017-09-17 11:25:03 +08:00
|
|
|
std::vector<std::unique_ptr<detail::GenericHandle>> GenericHandles;
|
2015-10-28 10:40:04 +08:00
|
|
|
std::vector<unsigned> FreeHandleIndexes;
|
|
|
|
|
|
|
|
orc::LocalCXXRuntimeOverrides CXXRuntimeOverrides;
|
|
|
|
std::vector<orc::CtorDtorRunner<OrcCBindingsStack>> IRStaticDestructorRunners;
|
2016-04-26 03:56:45 +08:00
|
|
|
std::string ErrMsg;
|
2015-10-28 10:40:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_LIB_EXECUTIONENGINE_ORC_ORCCBINDINGSSTACK_H
|