14 #ifndef LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
15 #define LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
43 : Addr(Addr), Compile(Compile) {}
47 this->Compile = std::move(Compile);
62 : ErrorHandlerAddress(ErrorHandlerAddress),
63 NumTrampolinesPerBlock(NumTrampolinesPerBlock) {}
82 auto Compile = std::move(
I->second);
86 if (
auto Addr = Compile())
124 template <
typename JITLayerT,
typename TargetT>
142 NumTrampolinesPerBlock),
143 JIT(JIT), MemMgr(MemMgr) {
144 emitResolverBlock(Context);
149 TargetAddress TrampolineAddr = getAvailableTrampolineAddr(Context);
156 std::vector<std::unique_ptr<Module>>
157 SingletonSet(std::unique_ptr<Module> M) {
158 std::vector<std::unique_ptr<Module>> Ms;
159 Ms.push_back(std::move(M));
164 std::unique_ptr<Module> M(
new Module(
"resolver_block_module",
166 TargetT::insertResolverBlock(*M, *
this);
172 [](
const std::string &
Name) -> RuntimeDyld::SymbolInfo {
175 auto H = JIT.addModuleSet(SingletonSet(std::move(M)), &MemMgr,
176 std::move(NonResolver));
177 JIT.emitAndFinalize(H);
178 auto ResolverBlockSymbol =
179 JIT.findSymbolIn(H, TargetT::ResolverBlockName,
false);
180 assert(ResolverBlockSymbol &&
"Failed to insert resolver block");
181 ResolverBlockAddr = ResolverBlockSymbol.getAddress();
184 TargetAddress getAvailableTrampolineAddr(LLVMContext &Context) {
188 "Failed to grow available trampolines.");
191 return TrampolineAddr;
194 void grow(LLVMContext &Context) {
196 std::unique_ptr<Module> M(
new Module(
"trampoline_block", Context));
198 TargetT::insertCompileCallbackTrampolines(*M, ResolverBlockAddr,
203 [](
const std::string &Name) -> RuntimeDyld::SymbolInfo {
206 [](
const std::string &
Name) -> RuntimeDyld::SymbolInfo {
209 auto H = JIT.addModuleSet(SingletonSet(std::move(M)), &MemMgr,
210 std::move(NonResolver));
211 JIT.emitAndFinalize(H);
213 std::string Name = GetLabelName(
I);
214 auto TrampolineSymbol = JIT.findSymbolIn(H, Name,
false);
215 assert(TrampolineSymbol &&
"Failed to emit trampoline.");
221 RuntimeDyld::MemoryManager &MemMgr;
235 const Twine &Name, Constant *Initializer);
239 void makeStub(Function &
F, GlobalVariable &ImplPointer);
272 ValueMaterializer *Materializer =
nullptr,
273 Function *NewF =
nullptr);
289 ValueMaterializer *Materializer =
nullptr,
290 GlobalVariable *NewGV =
nullptr);
295 #endif // LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
virtual ~JITCompileCallbackManagerBase()
std::function< TargetAddress()> CompileFtor
std::vector< TargetAddress > AvailableTrampolines
A Module instance is used to store all the information related to an LLVM module. ...
void setCompileAction(CompileFtor Compile)
TargetAddress getAddress() const
Manage compile callbacks.
TargetAddress ErrorHandlerAddress
GlobalVariable * createImplPointer(PointerType &PT, Module &M, const Twine &Name, Constant *Initializer)
Create a function pointer with the given type, name, and initializer in the given Module...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Constant * createIRTypedAddress(FunctionType &FT, TargetAddress Addr)
Build a function pointer of FunctionType with the given constant address.
void moveGlobalVariableInitializer(GlobalVariable &OrigGV, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, GlobalVariable *NewGV=nullptr)
Move global variable GV from its parent module to cloned global declaration in a different module...
CompileCallbackInfo(TargetAddress Addr, CompileFtor &Compile)
GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
This is an important class for using LLVM in a threaded context.
CompileCallbackInfo getCompileCallback(LLVMContext &Context) final
Get/create a compile callback with the given signature.
void releaseCompileCallback(TargetAddress TrampolineAddr)
Release a compile callback.
Base class for JITLayer independent aspects of JITCompileCallbackManager.
TargetAddress executeCompileCallback(TargetAddress TrampolineAddr)
Execute the callback for the given trampoline id.
std::map< TargetAddress, CompileFtor > TrampolineMapT
ValueMap< const Value *, WeakVH > ValueToValueMapTy
Handle to a newly created compile callback.
virtual CompileCallbackInfo getCompileCallback(LLVMContext &Context)=0
Reserve a compile callback.
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
unsigned NumTrampolinesPerBlock
Module.h This file contains the declarations for the Module class.
uint64_t TargetAddress
Represents an address in the target process's address space.
std::unique_ptr< LambdaResolver< ExternalLookupFtorT, DylibLookupFtorT > > createLambdaResolver(ExternalLookupFtorT ExternalLookupFtor, DylibLookupFtorT DylibLookupFtor)
void makeAllSymbolsExternallyAccessible(Module &M)
Raise linkage types and rename as necessary to ensure that all symbols are accessible for other modul...
JITCompileCallbackManagerBase(TargetAddress ErrorHandlerAddress, unsigned NumTrampolinesPerBlock)
Construct a JITCompileCallbackManagerBase.
void makeStub(Function &F, GlobalVariable &ImplPointer)
Turn a function declaration into a stub function that makes an indirect call using the given function...
Information about a named symbol.
TrampolineMapT ActiveTrampolines
JITCompileCallbackManager(JITLayerT &JIT, RuntimeDyld::MemoryManager &MemMgr, LLVMContext &Context, TargetAddress ErrorHandlerAddress, unsigned NumTrampolinesPerBlock)
Construct a JITCompileCallbackManager.
CompileCallbackInfo getCompileCallbackInfo(TargetAddress TrampolineAddr)
Get a CompileCallbackInfo for an existing callback.
void moveFunctionBody(Function &OrigF, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, Function *NewF=nullptr)
Move the body of function 'F' to a cloned function declaration in a different module (See related clo...