LLVM API Documentation
#include <MCJIT.h>
Classes | |
class | OwningModuleContainer |
Public Member Functions | |
~MCJIT () | |
uint64_t | getSymbolAddress (const std::string &Name, bool CheckFunctionsOnly) |
ExecutionEngine interface implementation | |
void | addModule (std::unique_ptr< Module > M) override |
Add a Module to the list of modules that we can JIT from. | |
void | addObjectFile (std::unique_ptr< object::ObjectFile > O) override |
void | addObjectFile (object::OwningBinary< object::ObjectFile > O) override |
void | addArchive (object::OwningBinary< object::Archive > O) override |
bool | removeModule (Module *M) override |
Function * | FindFunctionNamed (const char *FnName) override |
void | setObjectCache (ObjectCache *manager) override |
Sets the object manager that MCJIT should use to avoid compilation. | |
void | setProcessAllSections (bool ProcessAllSections) override |
void | generateCodeForModule (Module *M) override |
void | finalizeObject () override |
virtual void | finalizeModule (Module *) |
void | finalizeLoadedModules () |
void | runStaticConstructorsDestructors (bool isDtors) override |
void * | getPointerToFunction (Function *F) override |
GenericValue | runFunction (Function *F, const std::vector< GenericValue > &ArgValues) override |
void * | getPointerToNamedFunction (StringRef Name, bool AbortOnFailure=true) override |
void | mapSectionAddress (const void *LocalAddress, uint64_t TargetAddress) override |
void | RegisterJITEventListener (JITEventListener *L) override |
void | UnregisterJITEventListener (JITEventListener *L) override |
uint64_t | getGlobalValueAddress (const std::string &Name) override |
uint64_t | getFunctionAddress (const std::string &Name) override |
TargetMachine * | getTargetMachine () override |
Return the target machine (if available). | |
Static Public Member Functions | |
static void | Register () |
static ExecutionEngine * | createJIT (std::unique_ptr< Module > M, std::string *ErrorStr, RTDyldMemoryManager *MemMgr, std::unique_ptr< TargetMachine > TM) |
Protected Member Functions | |
std::unique_ptr < ObjectBufferStream > | emitObject (Module *M) |
void | NotifyObjectEmitted (const ObjectImage &Obj) |
void | NotifyFreeingObject (const ObjectImage &Obj) |
uint64_t | getExistingSymbolAddress (const std::string &Name) |
Module * | findModuleForSymbol (const std::string &Name, bool CheckFunctionsOnly) |
Definition at line 103 of file lib/ExecutionEngine/MCJIT/MCJIT.h.
MCJIT::~MCJIT | ( | ) |
Definition at line 80 of file MCJIT.cpp.
References llvm::SmallVectorImpl< T >::clear(), llvm::RuntimeDyld::deregisterEHFrames(), llvm::ExecutionEngine::lock, and NotifyFreeingObject().
void MCJIT::addArchive | ( | object::OwningBinary< object::Archive > | A | ) | [override, virtual] |
addArchive - Add an Archive to the execution engine.
This method is only supported by MCJIT. MCJIT will use the archive to resolve external symbols in objects it is loading. If a symbol is found in the Archive the contained object file will be extracted (in memory) and loaded for possible execution.
Reimplemented from llvm::ExecutionEngine.
Definition at line 117 of file MCJIT.cpp.
References llvm::SmallVectorTemplateBase< T, isPodLike >::push_back().
void MCJIT::addModule | ( | std::unique_ptr< Module > | M | ) | [override, virtual] |
Add a Module to the list of modules that we can JIT from.
Reimplemented from llvm::ExecutionEngine.
Definition at line 92 of file MCJIT.cpp.
References llvm::ExecutionEngine::lock.
void MCJIT::addObjectFile | ( | std::unique_ptr< object::ObjectFile > | O | ) | [override, virtual] |
addObjectFile - Add an ObjectFile to the execution engine.
This method is only supported by MCJIT. MCJIT will immediately load the object into memory and adds its symbols to the list used to resolve external symbols while preparing other objects for execution.
Objects added using this function will not be made executable until needed by another object.
MCJIT will take ownership of the ObjectFile.
Reimplemented from llvm::ExecutionEngine.
Definition at line 102 of file MCJIT.cpp.
References llvm::RuntimeDyld::getErrorString(), llvm::RuntimeDyld::hasError(), llvm::RuntimeDyld::loadObject(), NotifyObjectEmitted(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), and llvm::report_fatal_error().
Referenced by addObjectFile(), and getSymbolAddress().
void MCJIT::addObjectFile | ( | object::OwningBinary< object::ObjectFile > | O | ) | [override, virtual] |
Reimplemented from llvm::ExecutionEngine.
Definition at line 112 of file MCJIT.cpp.
References addObjectFile(), llvm::object::OwningBinary< T >::getBinary(), llvm::object::OwningBinary< T >::getBuffer(), and llvm::SmallVectorTemplateBase< T, isPodLike >::push_back().
ExecutionEngine * MCJIT::createJIT | ( | std::unique_ptr< Module > | M, |
std::string * | ErrorStr, | ||
RTDyldMemoryManager * | MemMgr, | ||
std::unique_ptr< TargetMachine > | TM | ||
) | [static] |
Definition at line 46 of file MCJIT.cpp.
References llvm::sys::DynamicLibrary::LoadLibraryPermanently().
Referenced by Register().
std::unique_ptr< ObjectBufferStream > MCJIT::emitObject | ( | Module * | M | ) | [protected] |
emitObject -- Generate a JITed object in memory from the specified module Currently, MCJIT only supports a single module and the module passed to this function call is expected to be the contained module. The module is passed as a parameter here to prepare for multiple module support in the future.
Definition at line 126 of file MCJIT.cpp.
References llvm::ExecutionEngine::getVerifyModules(), llvm::ExecutionEngine::lock, llvm::ObjectCache::notifyObjectCompiled(), llvm::report_fatal_error(), and llvm::Module::setDataLayout().
Referenced by generateCodeForModule().
void MCJIT::finalizeLoadedModules | ( | ) |
Definition at line 209 of file MCJIT.cpp.
References llvm::LinkingMemoryManager::finalizeMemory(), llvm::ExecutionEngine::lock, llvm::RuntimeDyld::registerEHFrames(), and llvm::RuntimeDyld::resolveRelocations().
Referenced by finalizeModule(), finalizeObject(), getFunctionAddress(), and getGlobalValueAddress().
void MCJIT::finalizeModule | ( | Module * | M | ) | [virtual] |
Definition at line 240 of file MCJIT.cpp.
References finalizeLoadedModules(), generateCodeForModule(), and llvm::ExecutionEngine::lock.
void MCJIT::finalizeObject | ( | ) | [override, virtual] |
finalizeObject - ensure the module is fully processed and is usable.
It is the user-level function for completing the process of making the object usable for execution. It should be called after sections within an object have been relocated using mapSectionAddress. When this method is called the MCJIT execution engine will reapply relocations for a loaded object. Is it OK to finalize a set of modules, add modules and finalize again.
Reimplemented from llvm::ExecutionEngine.
Definition at line 225 of file MCJIT.cpp.
References finalizeLoadedModules(), generateCodeForModule(), llvm::ExecutionEngine::lock, and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
Function * MCJIT::FindFunctionNamed | ( | const char * | FnName | ) | [override, virtual] |
FindFunctionNamed - Search all of the active modules to find the one that defines FnName. This is very slow operation and shouldn't be used for general code.
Reimplemented from llvm::ExecutionEngine.
Definition at line 408 of file MCJIT.cpp.
References F().
Module * MCJIT::findModuleForSymbol | ( | const std::string & | Name, |
bool | CheckFunctionsOnly | ||
) | [protected] |
Definition at line 260 of file MCJIT.cpp.
References F(), G, llvm::Module::getFunction(), llvm::Module::getGlobalVariable(), I, llvm::GlobalValue::isDeclaration(), and llvm::ExecutionEngine::lock.
Referenced by getSymbolAddress().
void MCJIT::generateCodeForModule | ( | Module * | M | ) | [override, virtual] |
generateCodeForModule - Run code generation for the specified module and load it into memory.
When this function has completed, all code and data for the specified module, and any module on which this module depends, will be generated and loaded into memory, but relocations will not yet have been applied and all memory will be readable and writable but not executable.
This function is primarily useful when generating code for an external target, allowing the client an opportunity to remap section addresses before relocations are applied. Clients that intend to execute code locally can use the getFunctionAddress call, which will generate code and apply final preparations all in one step.
This method has no effect for the interpeter.
Reimplemented from llvm::ExecutionEngine.
Definition at line 165 of file MCJIT.cpp.
References emitObject(), llvm::RuntimeDyld::getErrorString(), llvm::ObjectCache::getObject(), llvm::RuntimeDyld::loadObject(), llvm::ExecutionEngine::lock, NotifyObjectEmitted(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), and llvm::report_fatal_error().
Referenced by finalizeModule(), finalizeObject(), getPointerToFunction(), and getSymbolAddress().
uint64_t MCJIT::getExistingSymbolAddress | ( | const std::string & | Name | ) | [protected] |
Definition at line 253 of file MCJIT.cpp.
References llvm::RuntimeDyld::getSymbolLoadAddress().
Referenced by getSymbolAddress().
uint64_t MCJIT::getFunctionAddress | ( | const std::string & | Name | ) | [override, virtual] |
getFunctionAddress - Return the address of the specified function. This may involve code generation.
Reimplemented from llvm::ExecutionEngine.
Definition at line 342 of file MCJIT.cpp.
References finalizeLoadedModules(), getSymbolAddress(), and llvm::ExecutionEngine::lock.
uint64_t MCJIT::getGlobalValueAddress | ( | const std::string & | Name | ) | [override, virtual] |
getGlobalValueAddress - Return the address of the specified global value. This may involve code generation.
This function should not be called with the interpreter engine.
Reimplemented from llvm::ExecutionEngine.
Definition at line 334 of file MCJIT.cpp.
References finalizeLoadedModules(), getSymbolAddress(), and llvm::ExecutionEngine::lock.
void * MCJIT::getPointerToFunction | ( | Function * | F | ) | [override, virtual] |
getPointerToFunction - The different EE's represent function bodies in different ways. They should each implement this to say what a function pointer should look like. When F is destroyed, the ExecutionEngine will remove its global mapping and free any machine code. Be sure no threads are running inside F when that happens.
This function is deprecated for the MCJIT execution engine. Use getFunctionAddress instead.
Implements llvm::ExecutionEngine.
Definition at line 351 of file MCJIT.cpp.
References llvm::ExecutionEngine::addGlobalMapping(), generateCodeForModule(), llvm::Value::getName(), llvm::GlobalValue::getParent(), getPointerToNamedFunction(), llvm::RuntimeDyld::getSymbolLoadAddress(), llvm::GlobalValue::hasAvailableExternallyLinkage(), llvm::GlobalValue::hasExternalWeakLinkage(), llvm::GlobalValue::isDeclaration(), llvm::ExecutionEngine::lock, and Name.
Referenced by runFunction().
void * MCJIT::getPointerToNamedFunction | ( | StringRef | Name, |
bool | AbortOnFailure = true |
||
) | [override, virtual] |
getPointerToNamedFunction - This method returns the address of the specified function by using the dlsym function call. As such it is only useful for resolving library symbols, not code generated symbols.
If AbortOnFailure is false and no function with the given name is found, this function silently returns a null pointer. Otherwise, it prints a message to stderr and aborts.
If a LazyFunctionCreator is installed, use it to get/create the function.
Implements llvm::ExecutionEngine.
Definition at line 520 of file MCJIT.cpp.
References llvm::RTDyldMemoryManager::getPointerToNamedFunction(), llvm::ExecutionEngine::isSymbolSearchingDisabled(), llvm::ExecutionEngine::LazyFunctionCreator, llvm::report_fatal_error(), and llvm::NVPTX::PTXCvtMode::RP.
Referenced by getPointerToFunction().
uint64_t MCJIT::getSymbolAddress | ( | const std::string & | Name, |
bool | CheckFunctionsOnly | ||
) |
Definition at line 283 of file MCJIT.cpp.
References llvm::ARM_PROC::A, addObjectFile(), llvm::object::Archive::child_end(), findModuleForSymbol(), llvm::object::Archive::findSym(), generateCodeForModule(), llvm::ErrorOr< T >::get(), llvm::object::Archive::Child::getAsBinary(), llvm::ErrorOr< T >::getError(), getExistingSymbolAddress(), llvm::ExecutionEngine::LazyFunctionCreator, llvm::ExecutionEngine::lock, and llvm::X86II::OB.
Referenced by getFunctionAddress(), getGlobalValueAddress(), and llvm::LinkingMemoryManager::getSymbolAddress().
TargetMachine* llvm::MCJIT::getTargetMachine | ( | ) | [inline, override, virtual] |
Return the target machine (if available).
Reimplemented from llvm::ExecutionEngine.
Definition at line 316 of file lib/ExecutionEngine/MCJIT/MCJIT.h.
void llvm::MCJIT::mapSectionAddress | ( | const void * | LocalAddress, |
uint64_t | TargetAddress | ||
) | [inline, override, virtual] |
mapSectionAddress - map a section to its target address space value. Map the address of a JIT section as returned from the memory manager to the address in the target process as the running code will see it. This is the address which will be used for relocation resolution.
Reimplemented from llvm::ExecutionEngine.
Definition at line 303 of file lib/ExecutionEngine/MCJIT/MCJIT.h.
References llvm::RuntimeDyld::mapSectionAddress().
void MCJIT::NotifyFreeingObject | ( | const ObjectImage & | Obj | ) | [protected] |
Definition at line 562 of file MCJIT.cpp.
References llvm::ExecutionEngine::lock.
Referenced by ~MCJIT().
void MCJIT::NotifyObjectEmitted | ( | const ObjectImage & | Obj | ) | [protected] |
Definition at line 555 of file MCJIT.cpp.
References I, llvm::ExecutionEngine::lock, and llvm::LinkingMemoryManager::notifyObjectLoaded().
Referenced by addObjectFile(), and generateCodeForModule().
static void llvm::MCJIT::Register | ( | ) | [inline, static] |
Definition at line 320 of file lib/ExecutionEngine/MCJIT/MCJIT.h.
References createJIT(), and llvm::ExecutionEngine::MCJITCtor.
void MCJIT::RegisterJITEventListener | ( | JITEventListener * | ) | [override, virtual] |
Registers a listener to be called back on various events within the JIT. See JITEventListener.h for more details. Does not take ownership of the argument. The argument may be NULL, in which case these functions do nothing.
Reimplemented from llvm::ExecutionEngine.
Definition at line 539 of file MCJIT.cpp.
References llvm::ExecutionEngine::lock.
bool MCJIT::removeModule | ( | Module * | M | ) | [override, virtual] |
removeModule - Remove a Module from the list of modules. Returns true if M is found.
Reimplemented from llvm::ExecutionEngine.
Definition at line 97 of file MCJIT.cpp.
References llvm::ExecutionEngine::lock.
GenericValue MCJIT::runFunction | ( | Function * | F, |
const std::vector< GenericValue > & | ArgValues | ||
) | [override, virtual] |
runFunction - Execute the specified function with the specified arguments, and return the result.
Implements llvm::ExecutionEngine.
Definition at line 420 of file MCJIT.cpp.
References llvm::Type::DoubleTyID, llvm::GenericValue::DoubleVal, llvm::Type::FloatTyID, llvm::GenericValue::FloatVal, llvm::Type::FP128TyID, getBitWidth(), llvm::Function::getFunctionType(), llvm::FunctionType::getNumParams(), llvm::FunctionType::getParamType(), getPointerToFunction(), llvm::FunctionType::getReturnType(), llvm::Type::getTypeID(), llvm::GVTOP(), llvm::Type::IntegerTyID, llvm::GenericValue::IntVal, llvm::tgtok::IntVal, llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), llvm::FunctionType::isVarArg(), llvm::Type::isVoidTy(), llvm_unreachable, llvm::Type::PointerTyID, llvm::Type::PPC_FP128TyID, llvm::PTOGV(), llvm::Type::VoidTyID, and llvm::Type::X86_FP80TyID.
void MCJIT::runStaticConstructorsDestructors | ( | bool | isDtors | ) | [override, virtual] |
runStaticConstructorsDestructors - This method is used to execute all of the static constructors or destructors for a program.
isDtors | - Run the destructors instead of constructors. |
Reimplemented from llvm::ExecutionEngine.
void MCJIT::setObjectCache | ( | ObjectCache * | manager | ) | [override, virtual] |
Sets the object manager that MCJIT should use to avoid compilation.
Reimplemented from llvm::ExecutionEngine.
Definition at line 121 of file MCJIT.cpp.
References llvm::ExecutionEngine::lock.
void llvm::MCJIT::setProcessAllSections | ( | bool | ProcessAllSections | ) | [inline, override, virtual] |
setProcessAllSections (MCJIT Only): By default, only sections that are "required for execution" are passed to the RTDyldMemoryManager, and other sections are discarded. Passing 'true' to this method will cause RuntimeDyld to pass all sections to its RTDyldMemoryManager regardless of whether they are "required to execute" in the usual sense.
Rationale: Some MCJIT clients want to be able to inspect metadata sections (e.g. Dwarf, Stack-maps) to enable functionality or analyze performance. Passing these sections to the memory manager allows the client to make policy about the relevant sections, rather than having MCJIT do it.
Reimplemented from llvm::ExecutionEngine.
Definition at line 258 of file lib/ExecutionEngine/MCJIT/MCJIT.h.
References llvm::RuntimeDyld::setProcessAllSections().
void MCJIT::UnregisterJITEventListener | ( | JITEventListener * | L | ) | [override, virtual] |
Reimplemented from llvm::ExecutionEngine.
Definition at line 545 of file MCJIT.cpp.
References llvm::ExecutionEngine::lock, and std::swap().