forked from OSchip/llvm-project
[Orc] Separate callback manager selection from callback manager construction for
OrcLazyJIT in lli. Separating these concerns enables more natural error handling. llvm-svn: 233579
This commit is contained in:
parent
1facf7a13d
commit
3c9e20de2e
|
@ -12,31 +12,36 @@
|
|||
|
||||
using namespace llvm;
|
||||
|
||||
std::unique_ptr<OrcLazyJIT::CompileCallbackMgr>
|
||||
OrcLazyJIT::createCallbackMgr(Triple T, LLVMContext &Context) {
|
||||
OrcLazyJIT::CallbackManagerBuilder
|
||||
OrcLazyJIT::createCallbackManagerBuilder(Triple T) {
|
||||
switch (T.getArch()) {
|
||||
default:
|
||||
// Flag error.
|
||||
Error = true;
|
||||
return nullptr;
|
||||
default: return nullptr;
|
||||
|
||||
case Triple::x86_64: {
|
||||
typedef orc::JITCompileCallbackManager<CompileLayerT,
|
||||
orc::OrcX86_64> CCMgrT;
|
||||
return make_unique<CCMgrT>(CompileLayer, CCMgrMemMgr, Context, 0, 64);
|
||||
return [](CompileLayerT &CompileLayer, RuntimeDyld::MemoryManager &MemMgr,
|
||||
LLVMContext &Context) {
|
||||
return make_unique<CCMgrT>(CompileLayer, MemMgr, Context, 0, 64);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) {
|
||||
OrcLazyJIT J(std::unique_ptr<TargetMachine>(EngineBuilder().selectTarget()),
|
||||
getGlobalContext());
|
||||
auto TM = std::unique_ptr<TargetMachine>(EngineBuilder().selectTarget());
|
||||
auto &Context = getGlobalContext();
|
||||
auto CallbackMgrBuilder =
|
||||
OrcLazyJIT::createCallbackManagerBuilder(Triple(TM->getTargetTriple()));
|
||||
|
||||
if (!J.Ok()) {
|
||||
errs() << "Could not construct JIT.\n";
|
||||
if (!CallbackMgrBuilder) {
|
||||
errs() << "No callback manager available for target '"
|
||||
<< TM->getTargetTriple() << "'.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
OrcLazyJIT J(std::move(TM), Context, CallbackMgrBuilder);
|
||||
|
||||
auto MainHandle = J.addModule(std::move(M));
|
||||
auto MainSym = J.findSymbolIn(MainHandle, "main");
|
||||
|
||||
|
|
|
@ -36,17 +36,24 @@ public:
|
|||
CompileCallbackMgr> CODLayerT;
|
||||
typedef CODLayerT::ModuleSetHandleT ModuleHandleT;
|
||||
|
||||
OrcLazyJIT(std::unique_ptr<TargetMachine> TM, LLVMContext &Context)
|
||||
: Error(false), TM(std::move(TM)),
|
||||
typedef std::function<
|
||||
std::unique_ptr<CompileCallbackMgr>(CompileLayerT&,
|
||||
RuntimeDyld::MemoryManager&,
|
||||
LLVMContext&)>
|
||||
CallbackManagerBuilder;
|
||||
|
||||
static CallbackManagerBuilder createCallbackManagerBuilder(Triple T);
|
||||
|
||||
OrcLazyJIT(std::unique_ptr<TargetMachine> TM, LLVMContext &Context,
|
||||
CallbackManagerBuilder &BuildCallbackMgr)
|
||||
: TM(std::move(TM)),
|
||||
Mang(this->TM->getDataLayout()),
|
||||
ObjectLayer(),
|
||||
CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
|
||||
LazyEmitLayer(CompileLayer),
|
||||
CCMgr(createCallbackMgr(Triple(this->TM->getTargetTriple()), Context)),
|
||||
CCMgr(BuildCallbackMgr(CompileLayer, CCMgrMemMgr, Context)),
|
||||
CODLayer(LazyEmitLayer, *CCMgr) { }
|
||||
|
||||
bool Ok() const { return !Error; }
|
||||
|
||||
ModuleHandleT addModule(std::unique_ptr<Module> M) {
|
||||
// Attach a data-layout if one isn't already present.
|
||||
if (M->getDataLayout().isDefault())
|
||||
|
@ -67,9 +74,6 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
std::unique_ptr<CompileCallbackMgr>
|
||||
createCallbackMgr(Triple T, LLVMContext &Context);
|
||||
|
||||
std::string mangle(const std::string &Name) {
|
||||
std::string MangledName;
|
||||
{
|
||||
|
@ -79,7 +83,6 @@ private:
|
|||
return MangledName;
|
||||
}
|
||||
|
||||
bool Error;
|
||||
std::unique_ptr<TargetMachine> TM;
|
||||
Mangler Mang;
|
||||
SectionMemoryManager CCMgrMemMgr;
|
||||
|
|
Loading…
Reference in New Issue