diff options
Diffstat (limited to 'contrib/llvm/tools/lli/OrcLazyJIT.cpp')
-rw-r--r-- | contrib/llvm/tools/lli/OrcLazyJIT.cpp | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/contrib/llvm/tools/lli/OrcLazyJIT.cpp b/contrib/llvm/tools/lli/OrcLazyJIT.cpp index ae276e6..4235145 100644 --- a/contrib/llvm/tools/lli/OrcLazyJIT.cpp +++ b/contrib/llvm/tools/lli/OrcLazyJIT.cpp @@ -38,26 +38,39 @@ namespace { "Dump modules to the current " "working directory. (WARNING: " "will overwrite existing files)."), - clEnumValEnd)); + clEnumValEnd), + cl::Hidden); + + cl::opt<bool> OrcInlineStubs("orc-lazy-inline-stubs", + cl::desc("Try to inline stubs"), + cl::init(true), cl::Hidden); } -OrcLazyJIT::CallbackManagerBuilder -OrcLazyJIT::createCallbackManagerBuilder(Triple T) { +std::unique_ptr<OrcLazyJIT::CompileCallbackMgr> +OrcLazyJIT::createCompileCallbackMgr(Triple T) { switch (T.getArch()) { default: return nullptr; case Triple::x86_64: { - typedef orc::JITCompileCallbackManager<IRDumpLayerT, - orc::OrcX86_64> CCMgrT; - return [](IRDumpLayerT &IRDumpLayer, RuntimeDyld::MemoryManager &MemMgr, - LLVMContext &Context) { - return llvm::make_unique<CCMgrT>(IRDumpLayer, MemMgr, Context, 0, - 64); - }; + typedef orc::LocalJITCompileCallbackManager<orc::OrcX86_64> CCMgrT; + return llvm::make_unique<CCMgrT>(0); } } } +OrcLazyJIT::IndirectStubsManagerBuilder +OrcLazyJIT::createIndirectStubsMgrBuilder(Triple T) { + switch (T.getArch()) { + default: return nullptr; + + case Triple::x86_64: + return [](){ + return llvm::make_unique< + orc::LocalIndirectStubsManager<orc::OrcX86_64>>(); + }; + } +} + OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() { switch (OrcDumpKind) { @@ -111,6 +124,12 @@ OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() { // Defined in lli.cpp. CodeGenOpt::Level getOptLevel(); + +template <typename PtrTy> +static PtrTy fromTargetAddress(orc::TargetAddress Addr) { + return reinterpret_cast<PtrTy>(static_cast<uintptr_t>(Addr)); +} + int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) { // Add the program's symbols into the JIT's search space. if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) { @@ -123,20 +142,31 @@ int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) { EngineBuilder EB; EB.setOptLevel(getOptLevel()); auto TM = std::unique_ptr<TargetMachine>(EB.selectTarget()); - auto &Context = getGlobalContext(); - auto CallbackMgrBuilder = - OrcLazyJIT::createCallbackManagerBuilder(Triple(TM->getTargetTriple())); + auto CompileCallbackMgr = + OrcLazyJIT::createCompileCallbackMgr(Triple(TM->getTargetTriple())); // If we couldn't build the factory function then there must not be a callback // manager for this target. Bail out. - if (!CallbackMgrBuilder) { + if (!CompileCallbackMgr) { errs() << "No callback manager available for target '" << TM->getTargetTriple().str() << "'.\n"; return 1; } + auto IndirectStubsMgrBuilder = + OrcLazyJIT::createIndirectStubsMgrBuilder(Triple(TM->getTargetTriple())); + + // If we couldn't build a stubs-manager-builder for this target then bail out. + if (!IndirectStubsMgrBuilder) { + errs() << "No indirect stubs manager available for target '" + << TM->getTargetTriple().str() << "'.\n"; + return 1; + } + // Everything looks good. Build the JIT. - OrcLazyJIT J(std::move(TM), Context, CallbackMgrBuilder); + OrcLazyJIT J(std::move(TM), std::move(CompileCallbackMgr), + std::move(IndirectStubsMgrBuilder), + OrcInlineStubs); // Add the module, look up main and run it. auto MainHandle = J.addModule(std::move(M)); @@ -148,6 +178,6 @@ int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) { } typedef int (*MainFnPtr)(int, char*[]); - auto Main = OrcLazyJIT::fromTargetAddress<MainFnPtr>(MainSym.getAddress()); + auto Main = fromTargetAddress<MainFnPtr>(MainSym.getAddress()); return Main(ArgC, ArgV); } |