diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h b/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h index 03306985a3e4..fe7a85ba0201 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h @@ -328,6 +328,20 @@ private: StringMap> StubIndexes; }; +/// @brief Create a local compile callback manager. +/// +/// The given target triple will determine the ABI, and the given +/// ErrorHandlerAddress will be used by the resulting compile callback +/// manager if a compile callback fails. +std::unique_ptr +createLocalCompileCallbackManager(Triple T, TargetAddress ErrorHandlerAddress); + +/// @brief Create a local indriect stubs manager builder. +/// +/// The given target triple will determine the ABI. +std::function()> +createLocalIndirectStubsManagerBuilder(Triple T); + /// @brief Build a function pointer of FunctionType with the given constant /// address. /// diff --git a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt index a312f8f93804..76720a7c52ec 100644 --- a/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt +++ b/llvm/lib/ExecutionEngine/Orc/CMakeLists.txt @@ -4,7 +4,6 @@ add_llvm_library(LLVMOrcJIT NullResolver.cpp OrcABISupport.cpp OrcCBindings.cpp - OrcCBindingsStack.cpp OrcError.cpp OrcMCJITReplacement.cpp OrcRemoteTargetRPCAPI.cpp diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index a386aeefde39..34a0ddf00c85 100644 --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -10,6 +10,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/ExecutionEngine/Orc/IndirectionUtils.h" +#include "llvm/ExecutionEngine/Orc/OrcABISupport.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/IRBuilder.h" #include "llvm/Transforms/Utils/Cloning.h" @@ -21,6 +22,54 @@ namespace orc { void JITCompileCallbackManager::anchor() {} void IndirectStubsManager::anchor() {} +std::unique_ptr +createLocalCompileCallbackManager(Triple T, TargetAddress ErrorHandlerAddress) { + switch (T.getArch()) { + default: return nullptr; + + case Triple::x86: { + typedef orc::LocalJITCompileCallbackManager CCMgrT; + return llvm::make_unique(ErrorHandlerAddress); + } + + case Triple::x86_64: { + if ( T.getOS() == Triple::OSType::Win32 ) { + typedef orc::LocalJITCompileCallbackManager CCMgrT; + return llvm::make_unique(ErrorHandlerAddress); + } else { + typedef orc::LocalJITCompileCallbackManager CCMgrT; + return llvm::make_unique(ErrorHandlerAddress); + } + } + } +} + +std::function()> +createLocalIndirectStubsManagerBuilder(Triple T) { + switch (T.getArch()) { + default: return nullptr; + + case Triple::x86: + return [](){ + return llvm::make_unique< + orc::LocalIndirectStubsManager>(); + }; + + case Triple::x86_64: + if (T.getOS() == Triple::OSType::Win32) { + return [](){ + return llvm::make_unique< + orc::LocalIndirectStubsManager>(); + }; + } else { + return [](){ + return llvm::make_unique< + orc::LocalIndirectStubsManager>(); + }; + } + } +} + Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr) { Constant *AddrIntVal = ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr); diff --git a/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp index 4153f7f0cc9e..8dcd49aaab5b 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp @@ -17,9 +17,9 @@ LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) { Triple T(TM2->getTargetTriple()); - auto CompileCallbackMgr = OrcCBindingsStack::createCompileCallbackMgr(T); + auto CompileCallbackMgr = orc::createLocalCompileCallbackManager(T, 0); auto IndirectStubsMgrBuilder = - OrcCBindingsStack::createIndirectStubsMgrBuilder(T); + orc::createLocalIndirectStubsManagerBuilder(T); OrcCBindingsStack *JITStack = new OrcCBindingsStack( *TM2, std::move(CompileCallbackMgr), IndirectStubsMgrBuilder); diff --git a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp b/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp deleted file mode 100644 index ddc7d7126feb..000000000000 --- a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===-------- OrcCBindingsStack.cpp - Orc JIT stack for C bindings --------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "OrcCBindingsStack.h" - -#include "llvm/ExecutionEngine/Orc/OrcABISupport.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/DynamicLibrary.h" -#include -#include - -using namespace llvm; - -std::unique_ptr -OrcCBindingsStack::createCompileCallbackMgr(Triple T) { - switch (T.getArch()) { - default: - return nullptr; - - case Triple::x86: { - typedef orc::LocalJITCompileCallbackManager CCMgrT; - return llvm::make_unique(0); - }; - - case Triple::x86_64: { - if ( T.getOS() == Triple::OSType::Win32 ) { - typedef orc::LocalJITCompileCallbackManager CCMgrT; - return llvm::make_unique(0); - } else { - typedef orc::LocalJITCompileCallbackManager CCMgrT; - return llvm::make_unique(0); - } - } - } -} - -OrcCBindingsStack::IndirectStubsManagerBuilder -OrcCBindingsStack::createIndirectStubsMgrBuilder(Triple T) { - switch (T.getArch()) { - default: - return nullptr; - - case Triple::x86: - return []() { - return llvm::make_unique>(); - }; - - case Triple::x86_64: - if (T.getOS() == Triple::OSType::Win32) { - return [](){ - return llvm::make_unique< - orc::LocalIndirectStubsManager>(); - }; - } else { - return [](){ - return llvm::make_unique< - orc::LocalIndirectStubsManager>(); - }; - } - } -} diff --git a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h b/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h index dd14a14a4313..f49d49115e5d 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h +++ b/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h @@ -79,9 +79,6 @@ public: typedef unsigned ModuleHandleT; - static std::unique_ptr createCompileCallbackMgr(Triple T); - static IndirectStubsManagerBuilder createIndirectStubsMgrBuilder(Triple T); - OrcCBindingsStack(TargetMachine &TM, std::unique_ptr CCMgr, IndirectStubsManagerBuilder IndirectStubsMgrBuilder) diff --git a/llvm/tools/lli/OrcLazyJIT.cpp b/llvm/tools/lli/OrcLazyJIT.cpp index dc9d6486b6eb..b13e7696627f 100644 --- a/llvm/tools/lli/OrcLazyJIT.cpp +++ b/llvm/tools/lli/OrcLazyJIT.cpp @@ -46,54 +46,6 @@ namespace { cl::init(true), cl::Hidden); } -std::unique_ptr -OrcLazyJIT::createCompileCallbackMgr(Triple T) { - switch (T.getArch()) { - default: return nullptr; - - case Triple::x86: { - typedef orc::LocalJITCompileCallbackManager CCMgrT; - return llvm::make_unique(0); - } - - case Triple::x86_64: { - if ( T.getOS() == Triple::OSType::Win32 ) { - typedef orc::LocalJITCompileCallbackManager CCMgrT; - return llvm::make_unique(0); - } else { - typedef orc::LocalJITCompileCallbackManager CCMgrT; - return llvm::make_unique(0); - } - } - } -} - -OrcLazyJIT::IndirectStubsManagerBuilder -OrcLazyJIT::createIndirectStubsMgrBuilder(Triple T) { - switch (T.getArch()) { - default: return nullptr; - - case Triple::x86: - return [](){ - return llvm::make_unique< - orc::LocalIndirectStubsManager>(); - }; - - case Triple::x86_64: - if (T.getOS() == Triple::OSType::Win32) { - return [](){ - return llvm::make_unique< - orc::LocalIndirectStubsManager>(); - }; - } else { - return [](){ - return llvm::make_unique< - orc::LocalIndirectStubsManager>(); - }; - } - } -} - OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() { switch (OrcDumpKind) { @@ -165,8 +117,8 @@ int llvm::runOrcLazyJIT(std::unique_ptr M, int ArgC, char* ArgV[]) { EngineBuilder EB; EB.setOptLevel(getOptLevel()); auto TM = std::unique_ptr(EB.selectTarget()); - auto CompileCallbackMgr = - OrcLazyJIT::createCompileCallbackMgr(Triple(TM->getTargetTriple())); + Triple T(TM->getTargetTriple()); + auto CompileCallbackMgr = orc::createLocalCompileCallbackManager(T, 0); // If we couldn't build the factory function then there must not be a callback // manager for this target. Bail out. @@ -176,8 +128,7 @@ int llvm::runOrcLazyJIT(std::unique_ptr M, int ArgC, char* ArgV[]) { return 1; } - auto IndirectStubsMgrBuilder = - OrcLazyJIT::createIndirectStubsMgrBuilder(Triple(TM->getTargetTriple())); + auto IndirectStubsMgrBuilder = orc::createLocalIndirectStubsManagerBuilder(T); // If we couldn't build a stubs-manager-builder for this target then bail out. if (!IndirectStubsMgrBuilder) { diff --git a/llvm/tools/lli/OrcLazyJIT.h b/llvm/tools/lli/OrcLazyJIT.h index 6409ebfec61f..69aaa4be80bc 100644 --- a/llvm/tools/lli/OrcLazyJIT.h +++ b/llvm/tools/lli/OrcLazyJIT.h @@ -62,9 +62,6 @@ public: DtorRunner.runViaLayer(CODLayer); } - static std::unique_ptr createCompileCallbackMgr(Triple T); - static IndirectStubsManagerBuilder createIndirectStubsMgrBuilder(Triple T); - ModuleHandleT addModule(std::unique_ptr M) { // Attach a data-layout if one isn't already present. if (M->getDataLayout().isDefault())