LLVM  8.0.1
Classes | Public Member Functions | Protected Member Functions | List of all members
llvm::MCJIT Class Reference

#include "ExecutionEngine/MCJIT/MCJIT.h"

Inheritance diagram for llvm::MCJIT:
Inheritance graph
[legend]
Collaboration diagram for llvm::MCJIT:
Collaboration graph
[legend]

Public Member Functions

 ~MCJIT () override
 
JITSymbol findSymbol (const std::string &Name, bool CheckFunctionsOnly)
 
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. More...
 
void addObjectFile (std::unique_ptr< object::ObjectFile > O) override
 addObjectFile - Add an ObjectFile to the execution engine. More...
 
void addObjectFile (object::OwningBinary< object::ObjectFile > O) override
 
void addArchive (object::OwningBinary< object::Archive > O) override
 addArchive - Add an Archive to the execution engine. More...
 
bool removeModule (Module *M) override
 removeModule - Removes a Module from the list of modules, but does not free the module's memory. More...
 
FunctionFindFunctionNamed (StringRef FnName) override
 FindFunctionNamed - Search all of the active modules to find the function that defines FnName. More...
 
GlobalVariableFindGlobalVariableNamed (StringRef Name, bool AllowInternal=false) override
 FindGlobalVariableNamed - Search all of the active modules to find the global variable that defines Name. More...
 
void setObjectCache (ObjectCache *manager) override
 Sets the object manager that MCJIT should use to avoid compilation. More...
 
void setProcessAllSections (bool ProcessAllSections) override
 setProcessAllSections (MCJIT Only): By default, only sections that are "required for execution" are passed to the RTDyldMemoryManager, and other sections are discarded. More...
 
void generateCodeForModule (Module *M) override
 generateCodeForModule - Run code generation for the specified module and load it into memory. More...
 
void finalizeObject () override
 finalizeObject - ensure the module is fully processed and is usable. More...
 
virtual void finalizeModule (Module *)
 
void finalizeLoadedModules ()
 
void runStaticConstructorsDestructors (bool isDtors) override
 runStaticConstructorsDestructors - This method is used to execute all of the static constructors or destructors for a program. More...
 
void * getPointerToFunction (Function *F) override
 getPointerToFunction - The different EE's represent function bodies in different ways. More...
 
GenericValue runFunction (Function *F, ArrayRef< GenericValue > ArgValues) override
 runFunction - Execute the specified function with the specified arguments, and return the result. More...
 
void * getPointerToNamedFunction (StringRef Name, bool AbortOnFailure=true) override
 getPointerToNamedFunction - This method returns the address of the specified function by using the dlsym function call. More...
 
void mapSectionAddress (const void *LocalAddress, uint64_t TargetAddress) override
 mapSectionAddress - map a section to its target address space value. More...
 
void RegisterJITEventListener (JITEventListener *L) override
 Registers a listener to be called back on various events within the JIT. More...
 
void UnregisterJITEventListener (JITEventListener *L) override
 
uint64_t getGlobalValueAddress (const std::string &Name) override
 getGlobalValueAddress - Return the address of the specified global value. More...
 
uint64_t getFunctionAddress (const std::string &Name) override
 getFunctionAddress - Return the address of the specified function. More...
 
TargetMachinegetTargetMachine () override
 Return the target machine (if available). More...
 
- Public Member Functions inherited from llvm::ExecutionEngine
virtual ~ExecutionEngine ()
 
const DataLayoutgetDataLayout () const
 
void runStaticConstructorsDestructors (Module &module, bool isDtors)
 This method is used to execute all of the static constructors or destructors for a particular module. More...
 
int runFunctionAsMain (Function *Fn, const std::vector< std::string > &argv, const char *const *envp)
 runFunctionAsMain - This is a helper function which wraps runFunction to handle the common task of starting up main with the specified argc, argv, and envp parameters. More...
 
void addGlobalMapping (const GlobalValue *GV, void *Addr)
 addGlobalMapping - Tell the execution engine that the specified global is at the specified location. More...
 
void addGlobalMapping (StringRef Name, uint64_t Addr)
 
void clearAllGlobalMappings ()
 clearAllGlobalMappings - Clear all global mappings and start over again, for use in dynamic compilation scenarios to move globals. More...
 
void clearGlobalMappingsFromModule (Module *M)
 clearGlobalMappingsFromModule - Clear all global mappings that came from a particular module, because it has been removed from the JIT. More...
 
uint64_t updateGlobalMapping (const GlobalValue *GV, void *Addr)
 updateGlobalMapping - Replace an existing mapping for GV with a new address. More...
 
uint64_t updateGlobalMapping (StringRef Name, uint64_t Addr)
 
uint64_t getAddressToGlobalIfAvailable (StringRef S)
 getAddressToGlobalIfAvailable - This returns the address of the specified global symbol. More...
 
void * getPointerToGlobalIfAvailable (StringRef S)
 getPointerToGlobalIfAvailable - This returns the address of the specified global value if it is has already been codegen'd, otherwise it returns null. More...
 
void * getPointerToGlobalIfAvailable (const GlobalValue *GV)
 
void * getPointerToGlobal (const GlobalValue *GV)
 getPointerToGlobal - This returns the address of the specified global value. More...
 
virtual void * getPointerToFunctionOrStub (Function *F)
 getPointerToFunctionOrStub - If the specified function has been code-gen'd, return a pointer to the function. More...
 
const GlobalValuegetGlobalValueAtAddress (void *Addr)
 getGlobalValueAtAddress - Return the LLVM global value object that starts at the specified address. More...
 
void StoreValueToMemory (const GenericValue &Val, GenericValue *Ptr, Type *Ty)
 StoreValueToMemory - Stores the data in Val of type Ty at address Ptr. More...
 
void InitializeMemory (const Constant *Init, void *Addr)
 
virtual void * getOrEmitGlobalVariable (const GlobalVariable *GV)
 getOrEmitGlobalVariable - Return the address of the specified global variable, possibly emitting it to memory if needed. More...
 
void DisableLazyCompilation (bool Disabled=true)
 DisableLazyCompilation - When lazy compilation is off (the default), the JIT will eagerly compile every function reachable from the argument to getPointerToFunction. More...
 
bool isCompilingLazily () const
 
void DisableGVCompilation (bool Disabled=true)
 DisableGVCompilation - If called, the JIT will abort if it's asked to allocate space and populate a GlobalVariable that is not internal to the module. More...
 
bool isGVCompilationDisabled () const
 
void DisableSymbolSearching (bool Disabled=true)
 DisableSymbolSearching - If called, the JIT will not try to lookup unknown symbols with dlsym. More...
 
bool isSymbolSearchingDisabled () const
 
void setVerifyModules (bool Verify)
 Enable/Disable IR module verification. More...
 
bool getVerifyModules () const
 
void InstallLazyFunctionCreator (FunctionCreator C)
 InstallLazyFunctionCreator - If an unknown function is needed, the specified function pointer is invoked to create it. More...
 

Static Public Member Functions

(Private) Registration Interfaces
static void Register ()
 
static ExecutionEnginecreateJIT (std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MemMgr, std::shared_ptr< LegacyJITSymbolResolver > Resolver, std::unique_ptr< TargetMachine > TM)
 

Protected Member Functions

std::unique_ptr< MemoryBufferemitObject (Module *M)
 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. More...
 
void notifyObjectLoaded (const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L)
 
void notifyFreeingObject (const object::ObjectFile &Obj)
 
JITSymbol findExistingSymbol (const std::string &Name)
 
ModulefindModuleForSymbol (const std::string &Name, bool CheckFunctionsOnly)
 
- Protected Member Functions inherited from llvm::ExecutionEngine
virtual chargetMemoryForGV (const GlobalVariable *GV)
 getMemoryforGV - Allocate memory for a global variable. More...
 
std::string getMangledName (const GlobalValue *GV)
 getMangledName - Get mangled name. More...
 
 ExecutionEngine (DataLayout DL)
 
 ExecutionEngine (DataLayout DL, std::unique_ptr< Module > M)
 
 ExecutionEngine (std::unique_ptr< Module > M)
 
void emitGlobals ()
 EmitGlobals - Emit all of the global variables to memory, storing their addresses into GlobalAddress. More...
 
void EmitGlobalVariable (const GlobalVariable *GV)
 
GenericValue getConstantValue (const Constant *C)
 Converts a Constant* into a GenericValue, including handling of ConstantExpr values. More...
 
void LoadValueFromMemory (GenericValue &Result, GenericValue *Ptr, Type *Ty)
 FIXME: document. More...
 

Additional Inherited Members

- Public Attributes inherited from llvm::ExecutionEngine
sys::Mutex lock
 lock - This lock protects the ExecutionEngine and MCJIT classes. More...
 
- Protected Attributes inherited from llvm::ExecutionEngine
SmallVector< std::unique_ptr< Module >, 1 > Modules
 The list of Modules that we are JIT'ing from. More...
 
FunctionCreator LazyFunctionCreator
 LazyFunctionCreator - If an unknown function is needed, this function pointer is invoked to create it. More...
 
- Static Protected Attributes inherited from llvm::ExecutionEngine
static ExecutionEngine *(* MCJITCtor )(std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MM, std::shared_ptr< LegacyJITSymbolResolver > SR, std::unique_ptr< TargetMachine > TM) = nullptr
 
static ExecutionEngine *(* OrcMCJITReplacementCtor )(std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MM, std::shared_ptr< LegacyJITSymbolResolver > SR, std::unique_ptr< TargetMachine > TM) = nullptr
 
static ExecutionEngine *(* InterpCtor )(std::unique_ptr< Module > M, std::string *ErrorStr) =nullptr
 

Detailed Description

Definition at line 68 of file MCJIT.h.

Constructor & Destructor Documentation

◆ ~MCJIT()

MCJIT::~MCJIT ( )
override

Definition at line 91 of file MCJIT.cpp.

Member Function Documentation

◆ addArchive()

void MCJIT::addArchive ( object::OwningBinary< object::Archive A)
overridevirtual

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 135 of file MCJIT.cpp.

◆ addModule()

void MCJIT::addModule ( std::unique_ptr< Module M)
overridevirtual

Add a Module to the list of modules that we can JIT from.

Reimplemented from llvm::ExecutionEngine.

Definition at line 103 of file MCJIT.cpp.

◆ addObjectFile() [1/2]

void MCJIT::addObjectFile ( std::unique_ptr< object::ObjectFile O)
overridevirtual

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 117 of file MCJIT.cpp.

References llvm::report_fatal_error().

◆ addObjectFile() [2/2]

void MCJIT::addObjectFile ( object::OwningBinary< object::ObjectFile O)
overridevirtual

Reimplemented from llvm::ExecutionEngine.

Definition at line 127 of file MCJIT.cpp.

References llvm::object::OwningBinary< T >::takeBinary().

◆ createJIT()

ExecutionEngine * MCJIT::createJIT ( std::unique_ptr< Module M,
std::string *  ErrorStr,
std::shared_ptr< MCJITMemoryManager MemMgr,
std::shared_ptr< LegacyJITSymbolResolver Resolver,
std::unique_ptr< TargetMachine TM 
)
static

◆ emitObject()

std::unique_ptr< MemoryBuffer > 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 144 of file MCJIT.cpp.

References assert(), llvm::cantFail(), llvm::Module::materializeAll(), llvm::report_fatal_error(), and llvm::SystemZISD::TM.

◆ finalizeLoadedModules()

void MCJIT::finalizeLoadedModules ( )

Definition at line 237 of file MCJIT.cpp.

◆ finalizeModule()

void MCJIT::finalizeModule ( Module M)
virtual

Definition at line 268 of file MCJIT.cpp.

References assert().

◆ finalizeObject()

void MCJIT::finalizeObject ( )
overridevirtual

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 253 of file MCJIT.cpp.

References llvm::SmallVectorTemplateBase< T >::push_back().

◆ findExistingSymbol()

JITSymbol MCJIT::findExistingSymbol ( const std::string &  Name)
protected

Definition at line 281 of file MCJIT.cpp.

References llvm::JITSymbolFlags::Exported.

◆ FindFunctionNamed()

Function * MCJIT::FindFunctionNamed ( StringRef  FnName)
overridevirtual

FindFunctionNamed - Search all of the active modules to find the function that defines FnName.

This is very slow operation and shouldn't be used for general code.

Reimplemented from llvm::ExecutionEngine.

Definition at line 484 of file MCJIT.cpp.

References F().

◆ FindGlobalVariableNamed()

GlobalVariable * MCJIT::FindGlobalVariableNamed ( StringRef  Name,
bool  AllowInternal = false 
)
overridevirtual

FindGlobalVariableNamed - Search all of the active modules to find the global variable that defines Name.

This is very slow operation and shouldn't be used for general code.

Reimplemented from llvm::ExecutionEngine.

Definition at line 496 of file MCJIT.cpp.

◆ findModuleForSymbol()

Module * MCJIT::findModuleForSymbol ( const std::string &  Name,
bool  CheckFunctionsOnly 
)
protected

◆ findSymbol()

JITSymbol MCJIT::findSymbol ( const std::string &  Name,
bool  CheckFunctionsOnly 
)

◆ generateCodeForModule()

void MCJIT::generateCodeForModule ( Module M)
overridevirtual

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 187 of file MCJIT.cpp.

References assert(), llvm::object::ObjectFile::createObjectFile(), llvm::raw_ostream::flush(), llvm::Expected< T >::get(), llvm::Module::getDataLayout(), llvm::logAllUnhandledErrors(), llvm::report_fatal_error(), and llvm::Expected< T >::takeError().

◆ getFunctionAddress()

uint64_t MCJIT::getFunctionAddress ( const std::string &  Name)
overridevirtual

getFunctionAddress - Return the address of the specified function.

This may involve code generation.

Reimplemented from llvm::ExecutionEngine.

Definition at line 399 of file MCJIT.cpp.

◆ getGlobalValueAddress()

uint64_t MCJIT::getGlobalValueAddress ( const std::string &  Name)
overridevirtual

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 391 of file MCJIT.cpp.

◆ getPointerToFunction()

void * MCJIT::getPointerToFunction ( Function F)
overridevirtual

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 408 of file MCJIT.cpp.

References E, llvm::GlobalValue::getParent(), llvm::GlobalValue::hasAvailableExternallyLinkage(), llvm::GlobalValue::hasExternalWeakLinkage(), I, llvm::GlobalValue::isDeclaration(), Name, llvm::ExecutionEngine::runStaticConstructorsDestructors(), and llvm::SystemZISD::TM.

◆ getPointerToNamedFunction()

void * MCJIT::getPointerToNamedFunction ( StringRef  Name,
bool  AbortOnFailure = true 
)
overridevirtual

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 611 of file MCJIT.cpp.

◆ getSymbolAddress()

uint64_t MCJIT::getSymbolAddress ( const std::string &  Name,
bool  CheckFunctionsOnly 
)

Definition at line 317 of file MCJIT.cpp.

References llvm::Mangler::getNameWithPrefix(), and llvm::report_fatal_error().

◆ getTargetMachine()

TargetMachine* llvm::MCJIT::getTargetMachine ( )
inlineoverridevirtual

Return the target machine (if available).

Reimplemented from llvm::ExecutionEngine.

Definition at line 294 of file MCJIT.h.

◆ mapSectionAddress()

void llvm::MCJIT::mapSectionAddress ( const void *  LocalAddress,
uint64_t  TargetAddress 
)
inlineoverridevirtual

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 281 of file MCJIT.h.

References llvm::RuntimeDyld::mapSectionAddress().

◆ notifyFreeingObject()

void MCJIT::notifyFreeingObject ( const object::ObjectFile Obj)
protected

Definition at line 662 of file MCJIT.cpp.

References llvm::StringRef::data(), and llvm::object::Binary::getData().

◆ notifyObjectLoaded()

void MCJIT::notifyObjectLoaded ( const object::ObjectFile Obj,
const RuntimeDyld::LoadedObjectInfo L 
)
protected

Definition at line 651 of file MCJIT.cpp.

References llvm::StringRef::data(), llvm::object::Binary::getData(), and I.

◆ Register()

static void llvm::MCJIT::Register ( )
inlinestatic

Definition at line 300 of file MCJIT.h.

References llvm::LinkingSymbolResolver::findSymbol().

◆ RegisterJITEventListener()

void MCJIT::RegisterJITEventListener ( JITEventListener )
overridevirtual

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 633 of file MCJIT.cpp.

◆ removeModule()

bool MCJIT::removeModule ( Module M)
overridevirtual

removeModule - Removes a Module from the list of modules, but does not free the module's memory.

Returns true if M is found, in which case the caller assumes responsibility for deleting the module.

Reimplemented from llvm::ExecutionEngine.

Definition at line 112 of file MCJIT.cpp.

◆ runFunction()

GenericValue MCJIT::runFunction ( Function F,
ArrayRef< GenericValue ArgValues 
)
overridevirtual

runFunction - Execute the specified function with the specified arguments, and return the result.

For MCJIT execution engines, clients are encouraged to use the "GetFunctionAddress" method (rather than runFunction) and cast the returned uint64_t to the desired function pointer type. However, for backwards compatibility MCJIT's implementation can execute 'main-like' function (i.e. those returning void or int, and taking either no arguments or (int, char*[])).

Implements llvm::ExecutionEngine.

Definition at line 508 of file MCJIT.cpp.

References assert(), llvm::Type::DoubleTyID, llvm::GenericValue::DoubleVal, llvm::ArrayRef< T >::empty(), llvm::Type::FloatTyID, llvm::GenericValue::FloatVal, llvm::Type::FP128TyID, getBitWidth(), llvm::Function::getFunctionType(), llvm::FunctionType::getNumParams(), llvm::FunctionType::getParamType(), llvm::GlobalValue::getParent(), 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::report_fatal_error(), llvm::ArrayRef< T >::size(), llvm::Type::VoidTyID, and llvm::Type::X86_FP80TyID.

◆ runStaticConstructorsDestructors()

void MCJIT::runStaticConstructorsDestructors ( bool  isDtors)
overridevirtual

runStaticConstructorsDestructors - This method is used to execute all of the static constructors or destructors for a program.

Parameters
isDtors- Run the destructors instead of constructors.

Reimplemented from llvm::ExecutionEngine.

Definition at line 450 of file MCJIT.cpp.

References E, F(), I, llvm::GlobalValue::isDeclaration(), and Name.

◆ setObjectCache()

void MCJIT::setObjectCache ( ObjectCache manager)
overridevirtual

Sets the object manager that MCJIT should use to avoid compilation.

Reimplemented from llvm::ExecutionEngine.

Definition at line 139 of file MCJIT.cpp.

◆ setProcessAllSections()

void llvm::MCJIT::setProcessAllSections ( bool  ProcessAllSections)
inlineoverridevirtual

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 236 of file MCJIT.h.

References F(), and llvm::RuntimeDyld::setProcessAllSections().

◆ UnregisterJITEventListener()

void MCJIT::UnregisterJITEventListener ( JITEventListener L)
overridevirtual

Reimplemented from llvm::ExecutionEngine.

Definition at line 640 of file MCJIT.cpp.

References llvm::find(), I, llvm::reverse(), and std::swap().


The documentation for this class was generated from the following files: