Index: llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h =================================================================== --- llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +++ llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -447,6 +447,9 @@ public LLLazyJITBuilderSetters {}; +/// Configure the LLJIT instance to use orc runtime support. +Error setUpOrcPlatform(LLJIT& J); + /// Configure the LLJIT instance to scrape modules for llvm.global_ctors and /// llvm.global_dtors variables and (if present) build initialization and /// deinitialization functions. Platform specific initialization configurations Index: llvm/lib/ExecutionEngine/Orc/LLJIT.cpp =================================================================== --- llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -81,6 +81,53 @@ return WrapperFn; } +class ORCPlatformSupport : public LLJIT::PlatformSupport { +public: + ORCPlatformSupport(orc::LLJIT &J) : J(J) {} + + Error initialize(orc::JITDylib &JD) override { + using llvm::orc::shared::SPSExecutorAddr; + using llvm::orc::shared::SPSString; + using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t); + enum dlopen_mode : int32_t { + ORC_RT_RTLD_LAZY = 0x1, + ORC_RT_RTLD_NOW = 0x2, + ORC_RT_RTLD_LOCAL = 0x4, + ORC_RT_RTLD_GLOBAL = 0x8 + }; + + if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlopen_wrapper")) { + return J.getExecutionSession().callSPSWrapper( + *WrapperAddr, DSOHandles[&JD], JD.getName(), + int32_t(ORC_RT_RTLD_LAZY)); + } else + return WrapperAddr.takeError(); + } + + Error deinitialize(orc::JITDylib &JD) override { + using llvm::orc::shared::SPSExecutorAddr; + using SPSDLCloseSig = int32_t(SPSExecutorAddr); + + if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlclose_wrapper")) { + int32_t result; + auto E = J.getExecutionSession().callSPSWrapper( + *WrapperAddr, result, DSOHandles[&JD]); + if (E) + return E; + else if (result) + return make_error("dlclose failed", + inconvertibleErrorCode()); + DSOHandles.erase(&JD); + } else + return WrapperAddr.takeError(); + return Error::success(); + } + +private: + orc::LLJIT &J; + DenseMap DSOHandles; +}; + class GenericLLVMIRPlatformSupport; /// orc::Platform component of Generic LLVM IR Platform support. @@ -880,6 +927,13 @@ return Error::success(); } +Error setUpOrcPlatform(LLJIT& J) { + LLVM_DEBUG( + { dbgs() << "Setting up orc platform support for LLJIT\n"; }); + J.setPlatformSupport(std::make_unique(J)); + return Error::success(); +} + void setUpGenericLLVMIRPlatform(LLJIT &J) { LLVM_DEBUG( { dbgs() << "Setting up GenericLLVMIRPlatform support for LLJIT\n"; }); Index: llvm/tools/lli/lli.cpp =================================================================== --- llvm/tools/lli/lli.cpp +++ llvm/tools/lli/lli.cpp @@ -373,53 +373,6 @@ } }; -class ORCPlatformSupport : public orc::LLJIT::PlatformSupport { -public: - ORCPlatformSupport(orc::LLJIT &J) : J(J) {} - - Error initialize(orc::JITDylib &JD) override { - using llvm::orc::shared::SPSExecutorAddr; - using llvm::orc::shared::SPSString; - using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t); - enum dlopen_mode : int32_t { - ORC_RT_RTLD_LAZY = 0x1, - ORC_RT_RTLD_NOW = 0x2, - ORC_RT_RTLD_LOCAL = 0x4, - ORC_RT_RTLD_GLOBAL = 0x8 - }; - - if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlopen_wrapper")) { - return J.getExecutionSession().callSPSWrapper( - *WrapperAddr, DSOHandles[&JD], JD.getName(), - int32_t(ORC_RT_RTLD_LAZY)); - } else - return WrapperAddr.takeError(); - } - - Error deinitialize(orc::JITDylib &JD) override { - using llvm::orc::shared::SPSExecutorAddr; - using SPSDLCloseSig = int32_t(SPSExecutorAddr); - - if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlclose_wrapper")) { - int32_t result; - auto E = J.getExecutionSession().callSPSWrapper( - *WrapperAddr, result, DSOHandles[&JD]); - if (E) - return E; - else if (result) - return make_error("dlclose failed", - inconvertibleErrorCode()); - DSOHandles.erase(&JD); - } else - return WrapperAddr.takeError(); - return Error::success(); - } - -private: - orc::LLJIT &J; - DenseMap DSOHandles; -}; - // On Mingw and Cygwin, an external symbol named '__main' is called from the // generated 'main' function to allow static initialization. To avoid linking // problems with remote targets (because lli's remote target support does not @@ -969,10 +922,7 @@ } switch (P) { case LLJITPlatform::ORC: - Builder.setPlatformSetUp([](llvm::orc::LLJIT &J) -> llvm::Error { - J.setPlatformSupport(std::make_unique(J)); - return Error::success(); - }); + Builder.setPlatformSetUp(orc::setUpOrcPlatform); break; case LLJITPlatform::GenericIR: // Nothing to do: LLJITBuilder will use this by default.