diff options
Diffstat (limited to 'include/llvm/ExecutionEngine/Orc/IndirectionUtils.h')
-rw-r--r-- | include/llvm/ExecutionEngine/Orc/IndirectionUtils.h | 109 |
1 files changed, 55 insertions, 54 deletions
diff --git a/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h b/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h index e9d3d34..8ce1d4d 100644 --- a/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h +++ b/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h @@ -26,10 +26,34 @@ namespace orc { /// @brief Base class for JITLayer independent aspects of /// JITCompileCallbackManager. -template <typename TargetT> class JITCompileCallbackManagerBase { public: + typedef std::function<TargetAddress()> CompileFtor; + typedef std::function<void(TargetAddress)> UpdateFtor; + + /// @brief Handle to a newly created compile callback. Can be used to get an + /// IR constant representing the address of the trampoline, and to set + /// the compile and update actions for the callback. + class CompileCallbackInfo { + public: + CompileCallbackInfo(Constant *Addr, CompileFtor &Compile, + UpdateFtor &Update) + : Addr(Addr), Compile(Compile), Update(Update) {} + + Constant* getAddress() const { return Addr; } + void setCompileAction(CompileFtor Compile) { + this->Compile = std::move(Compile); + } + void setUpdateAction(UpdateFtor Update) { + this->Update = std::move(Update); + } + private: + Constant *Addr; + CompileFtor &Compile; + UpdateFtor &Update; + }; + /// @brief Construct a JITCompileCallbackManagerBase. /// @param ErrorHandlerAddress The address of an error handler in the target /// process to be used if a compile callback fails. @@ -41,10 +65,12 @@ public: : ErrorHandlerAddress(ErrorHandlerAddress), NumTrampolinesPerBlock(NumTrampolinesPerBlock) {} + virtual ~JITCompileCallbackManagerBase() {} + /// @brief Execute the callback for the given trampoline id. Called by the JIT /// to compile functions on demand. TargetAddress executeCompileCallback(TargetAddress TrampolineID) { - typename TrampolineMapT::iterator I = ActiveTrampolines.find(TrampolineID); + TrampolineMapT::iterator I = ActiveTrampolines.find(TrampolineID); // FIXME: Also raise an error in the Orc error-handler when we finally have // one. if (I == ActiveTrampolines.end()) @@ -56,7 +82,7 @@ public: // Moving the trampoline ID back to the available list first means there's at // least one available trampoline if the compile action triggers a request for // a new one. - AvailableTrampolines.push_back(I->first - TargetT::CallSize); + AvailableTrampolines.push_back(I->first); auto CallbackHandler = std::move(I->second); ActiveTrampolines.erase(I); @@ -67,14 +93,14 @@ public: return ErrorHandlerAddress; } -protected: + /// @brief Get/create a compile callback with the given signature. + virtual CompileCallbackInfo getCompileCallback(FunctionType &FT) = 0; - typedef std::function<TargetAddress()> CompileFtorT; - typedef std::function<void(TargetAddress)> UpdateFtorT; +protected: struct CallbackHandler { - CompileFtorT Compile; - UpdateFtorT Update; + CompileFtor Compile; + UpdateFtor Update; }; TargetAddress ErrorHandlerAddress; @@ -87,15 +113,9 @@ protected: /// @brief Manage compile callbacks. template <typename JITLayerT, typename TargetT> -class JITCompileCallbackManager : - public JITCompileCallbackManagerBase<TargetT> { +class JITCompileCallbackManager : public JITCompileCallbackManagerBase { public: - typedef typename JITCompileCallbackManagerBase<TargetT>::CompileFtorT - CompileFtorT; - typedef typename JITCompileCallbackManagerBase<TargetT>::UpdateFtorT - UpdateFtorT; - /// @brief Construct a JITCompileCallbackManager. /// @param JIT JIT layer to emit callback trampolines, etc. into. /// @param Context LLVMContext to use for trampoline & resolve block modules. @@ -108,39 +128,17 @@ public: JITCompileCallbackManager(JITLayerT &JIT, LLVMContext &Context, TargetAddress ErrorHandlerAddress, unsigned NumTrampolinesPerBlock) - : JITCompileCallbackManagerBase<TargetT>(ErrorHandlerAddress, - NumTrampolinesPerBlock), + : JITCompileCallbackManagerBase(ErrorHandlerAddress, + NumTrampolinesPerBlock), JIT(JIT) { emitResolverBlock(Context); } - /// @brief Handle to a newly created compile callback. Can be used to get an - /// IR constant representing the address of the trampoline, and to set - /// the compile and update actions for the callback. - class CompileCallbackInfo { - public: - CompileCallbackInfo(Constant *Addr, CompileFtorT &Compile, - UpdateFtorT &Update) - : Addr(Addr), Compile(Compile), Update(Update) {} - - Constant* getAddress() const { return Addr; } - void setCompileAction(CompileFtorT Compile) { - this->Compile = std::move(Compile); - } - void setUpdateAction(UpdateFtorT Update) { - this->Update = std::move(Update); - } - private: - Constant *Addr; - CompileFtorT &Compile; - UpdateFtorT &Update; - }; - /// @brief Get/create a compile callback with the given signature. - CompileCallbackInfo getCompileCallback(FunctionType &FT) { + CompileCallbackInfo getCompileCallback(FunctionType &FT) final { TargetAddress TrampolineAddr = getAvailableTrampolineAddr(FT.getContext()); auto &CallbackHandler = - this->ActiveTrampolines[TrampolineAddr + TargetT::CallSize]; + this->ActiveTrampolines[TrampolineAddr]; Constant *AddrIntVal = ConstantInt::get(Type::getInt64Ty(FT.getContext()), TrampolineAddr); Constant *AddrPtrVal = @@ -151,19 +149,6 @@ public: CallbackHandler.Update); } - /// @brief Get a functor for updating the value of a named function pointer. - UpdateFtorT getLocalFPUpdater(typename JITLayerT::ModuleSetHandleT H, - std::string Name) { - // FIXME: Move-capture Name once we can use C++14. - return [=](TargetAddress Addr) { - auto FPSym = JIT.findSymbolIn(H, Name, true); - assert(FPSym && "Cannot find function pointer to update."); - void *FPAddr = reinterpret_cast<void*>( - static_cast<uintptr_t>(FPSym.getAddress())); - memcpy(FPAddr, &Addr, sizeof(uintptr_t)); - }; - } - private: std::vector<std::unique_ptr<Module>> @@ -216,6 +201,22 @@ private: TargetAddress ResolverBlockAddr; }; +/// @brief Get an update functor for updating the value of a named function +/// pointer. +template <typename JITLayerT> +JITCompileCallbackManagerBase::UpdateFtor +getLocalFPUpdater(JITLayerT &JIT, typename JITLayerT::ModuleSetHandleT H, + std::string Name) { + // FIXME: Move-capture Name once we can use C++14. + return [=,&JIT](TargetAddress Addr) { + auto FPSym = JIT.findSymbolIn(H, Name, true); + assert(FPSym && "Cannot find function pointer to update."); + void *FPAddr = reinterpret_cast<void*>( + static_cast<uintptr_t>(FPSym.getAddress())); + memcpy(FPAddr, &Addr, sizeof(uintptr_t)); + }; + } + GlobalVariable* createImplPointer(Function &F, const Twine &Name, Constant *Initializer); |