LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Protected Member Functions | List of all members
llvm::MCJIT Class Reference

#include <MCJIT.h>

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

Public Member Functions

 ~MCJIT ()
 
uint64_t getSymbolAddress (const std::string &Name, bool CheckFunctionsOnly)
 
ExecutionEngine interface implementation
virtual void addModule (Module *M)
 
virtual bool removeModule (Module *M)
 
virtual FunctionFindFunctionNamed (const char *FnName)
 
virtual void setObjectCache (ObjectCache *manager)
 Sets the object manager that MCJIT should use to avoid compilation. More...
 
virtual void generateCodeForModule (Module *M)
 
virtual void finalizeObject ()
 
virtual void finalizeModule (Module *)
 
void finalizeLoadedModules ()
 
void runStaticConstructorsDestructors (bool isDtors)
 
virtual void * getPointerToBasicBlock (BasicBlock *BB)
 
virtual void * getPointerToFunction (Function *F)
 
virtual void * recompileAndRelinkFunction (Function *F)
 
virtual void freeMachineCodeForFunction (Function *F)
 
virtual GenericValue runFunction (Function *F, const std::vector< GenericValue > &ArgValues)
 
virtual void * getPointerToNamedFunction (const std::string &Name, bool AbortOnFailure=true)
 
virtual void mapSectionAddress (const void *LocalAddress, uint64_t TargetAddress)
 
virtual void RegisterJITEventListener (JITEventListener *L)
 
virtual void UnregisterJITEventListener (JITEventListener *L)
 
virtual uint64_t getGlobalValueAddress (const std::string &Name)
 
virtual uint64_t getFunctionAddress (const std::string &Name)
 
- Public Member Functions inherited from llvm::ExecutionEngine
virtual ~ExecutionEngine ()
 
const DataLayoutgetDataLayout () const
 
void runStaticConstructorsDestructors (Module *module, bool isDtors)
 
int runFunctionAsMain (Function *Fn, const std::vector< std::string > &argv, const char *const *envp)
 
void addGlobalMapping (const GlobalValue *GV, void *Addr)
 
void clearAllGlobalMappings ()
 
void clearGlobalMappingsFromModule (Module *M)
 
void * updateGlobalMapping (const GlobalValue *GV, void *Addr)
 
void * getPointerToGlobalIfAvailable (const GlobalValue *GV)
 
void * getPointerToGlobal (const GlobalValue *GV)
 
virtual void * getPointerToFunctionOrStub (Function *F)
 
virtual void runJITOnFunction (Function *, MachineCodeInfo *=0)
 
const GlobalValuegetGlobalValueAtAddress (void *Addr)
 
void StoreValueToMemory (const GenericValue &Val, GenericValue *Ptr, Type *Ty)
 
void InitializeMemory (const Constant *Init, void *Addr)
 
virtual void * getOrEmitGlobalVariable (const GlobalVariable *GV)
 
void DisableLazyCompilation (bool Disabled=true)
 
bool isCompilingLazily () const
 
bool isLazyCompilationDisabled () const
 
void DisableGVCompilation (bool Disabled=true)
 
bool isGVCompilationDisabled () const
 
void DisableSymbolSearching (bool Disabled=true)
 
bool isSymbolSearchingDisabled () const
 
void InstallLazyFunctionCreator (void *(*P)(const std::string &))
 

Static Public Member Functions

(Private) Registration Interfaces
static void Register ()
 
static ExecutionEnginecreateJIT (Module *M, std::string *ErrorStr, RTDyldMemoryManager *MemMgr, bool GVsWithCode, TargetMachine *TM)
 
- Static Public Member Functions inherited from llvm::ExecutionEngine
static ExecutionEnginecreate (Module *M, bool ForceInterpreter=false, std::string *ErrorStr=0, CodeGenOpt::Level OptLevel=CodeGenOpt::Default, bool GVsWithCode=true)
 
static ExecutionEnginecreateJIT (Module *M, std::string *ErrorStr=0, JITMemoryManager *JMM=0, CodeGenOpt::Level OptLevel=CodeGenOpt::Default, bool GVsWithCode=true, Reloc::Model RM=Reloc::Default, CodeModel::Model CMM=CodeModel::JITDefault)
 

Protected Member Functions

ObjectBufferStreamemitObject (Module *M)
 
void NotifyObjectEmitted (const ObjectImage &Obj)
 
void NotifyFreeingObject (const ObjectImage &Obj)
 
uint64_t getExistingSymbolAddress (const std::string &Name)
 
ModulefindModuleForSymbol (const std::string &Name, bool CheckFunctionsOnly)
 
- Protected Member Functions inherited from llvm::ExecutionEngine
void setDataLayout (const DataLayout *td)
 
virtual char * getMemoryForGV (const GlobalVariable *GV)
 getMemoryforGV - Allocate memory for a global variable. More...
 
 ExecutionEngine (Module *M)
 
void emitGlobals ()
 
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)
 

Additional Inherited Members

- Public Attributes inherited from llvm::ExecutionEngine
sys::Mutex lock
 
- Protected Attributes inherited from llvm::ExecutionEngine
SmallVector< Module *, 1 > Modules
 
void *(* LazyFunctionCreator )(const std::string &)
 
- Static Protected Attributes inherited from llvm::ExecutionEngine
static ExecutionEngine *(* JITCtor )(Module *M, std::string *ErrorStr, JITMemoryManager *JMM, bool GVsWithCode, TargetMachine *TM)
 
static ExecutionEngine *(* MCJITCtor )(Module *M, std::string *ErrorStr, RTDyldMemoryManager *MCJMM, bool GVsWithCode, TargetMachine *TM)
 
static ExecutionEngine *(* InterpCtor )(Module *M, std::string *ErrorStr)
 

Detailed Description

Definition at line 93 of file lib/ExecutionEngine/MCJIT/MCJIT.h.

Constructor & Destructor Documentation

MCJIT::~MCJIT ( )

Member Function Documentation

void MCJIT::addModule ( Module M)
virtual

addModule - Add a Module to the list of modules that we can JIT from. Note that this takes ownership of the Module: when the ExecutionEngine is destroyed, it destroys the Module as well.

Reimplemented from llvm::ExecutionEngine.

Definition at line 92 of file MCJIT.cpp.

References llvm::ExecutionEngine::lock.

ExecutionEngine * MCJIT::createJIT ( Module M,
std::string *  ErrorStr,
RTDyldMemoryManager MemMgr,
bool  GVsWithCode,
TargetMachine TM 
)
static

Definition at line 42 of file MCJIT.cpp.

References llvm::sys::DynamicLibrary::LoadLibraryPermanently().

Referenced by Register().

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

References llvm::TargetMachine::addPassesToEmitMC(), llvm::ObjectBufferStream::flush(), llvm::TargetMachine::getDataLayout(), llvm::ObjectBuffer::getMemBuffer(), llvm::ObjectBufferStream::getOStream(), llvm::ExecutionEngine::lock, llvm::ObjectCache::notifyObjectCompiled(), llvm::report_fatal_error(), and llvm::OwningPtr< T >::take().

Referenced by generateCodeForModule().

void MCJIT::finalizeLoadedModules ( )
void MCJIT::finalizeModule ( Module M)
virtual
void MCJIT::finalizeObject ( )
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 203 of file MCJIT.cpp.

References finalizeLoadedModules(), generateCodeForModule(), I, and llvm::ExecutionEngine::lock.

Function * MCJIT::FindFunctionNamed ( const char *  FnName)
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 369 of file MCJIT.cpp.

References F().

Module * MCJIT::findModuleForSymbol ( const std::string &  Name,
bool  CheckFunctionsOnly 
)
protected
void MCJIT::freeMachineCodeForFunction ( Function F)
virtual

freeMachineCodeForFunction - Release memory in the ExecutionEngine corresponding to the machine code emitted to execute this function, useful for garbage-collecting generated code.

Implements llvm::ExecutionEngine.

Definition at line 338 of file MCJIT.cpp.

References llvm::report_fatal_error().

void MCJIT::generateCodeForModule ( Module M)
virtual

generateCodeForModule - Run code generationen 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 legacy JIT engine or the interpeter.

Reimplemented from llvm::ExecutionEngine.

Definition at line 146 of file MCJIT.cpp.

References emitObject(), llvm::OwningPtr< T >::get(), llvm::RuntimeDyld::getErrorString(), llvm::ObjectCache::getObject(), llvm::RuntimeDyld::loadObject(), llvm::ExecutionEngine::lock, NotifyObjectEmitted(), llvm::ObjectImage::registerWithDebugger(), llvm::report_fatal_error(), llvm::OwningPtr< T >::reset(), and llvm::OwningPtr< T >::take().

Referenced by finalizeModule(), finalizeObject(), getPointerToFunction(), and getSymbolAddress().

uint64_t MCJIT::getExistingSymbolAddress ( const std::string &  Name)
protected
uint64_t MCJIT::getFunctionAddress ( const std::string &  Name)
virtual

getFunctionAddress - Return the address of the specified function. This may involve code generation.

Reimplemented from llvm::ExecutionEngine.

Definition at line 293 of file MCJIT.cpp.

References finalizeLoadedModules(), getSymbolAddress(), and llvm::ExecutionEngine::lock.

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

getGlobalValueAddress - Return the address of the specified global value. This may involve code generation.

This function should not be called with the JIT or interpreter engines.

Reimplemented from llvm::ExecutionEngine.

Definition at line 285 of file MCJIT.cpp.

References finalizeLoadedModules(), getSymbolAddress(), and llvm::ExecutionEngine::lock.

void * MCJIT::getPointerToBasicBlock ( BasicBlock BB)
virtual

getPointerToBasicBlock - The different EE's represent basic blocks in different ways. Return the representation for a blockaddress of the specified block.

This function will not be implemented for the MCJIT execution engine.

Implements llvm::ExecutionEngine.

Definition at line 229 of file MCJIT.cpp.

References llvm::report_fatal_error().

void * MCJIT::getPointerToFunction ( Function F)
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 302 of file MCJIT.cpp.

References llvm::ExecutionEngine::addGlobalMapping(), generateCodeForModule(), llvm::MCAsmInfo::getGlobalPrefix(), llvm::TargetMachine::getMCAsmInfo(), llvm::Value::getName(), llvm::GlobalValue::getParent(), getPointerToNamedFunction(), llvm::RuntimeDyld::getSymbolLoadAddress(), llvm::GlobalValue::hasAvailableExternallyLinkage(), llvm::GlobalValue::hasExternalWeakLinkage(), llvm::GlobalValue::isDeclaration(), llvm::ExecutionEngine::lock, and llvm::StringRef::substr().

Referenced by runFunction().

void * MCJIT::getPointerToNamedFunction ( const std::string &  Name,
bool  AbortOnFailure = true 
)
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 481 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 
)
virtual void llvm::MCJIT::mapSectionAddress ( const void *  LocalAddress,
uint64_t  TargetAddress 
)
inlinevirtual

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 287 of file lib/ExecutionEngine/MCJIT/MCJIT.h.

References llvm::RuntimeDyld::mapSectionAddress().

void MCJIT::NotifyFreeingObject ( const ObjectImage Obj)
protected

Definition at line 525 of file MCJIT.cpp.

References I, and llvm::ExecutionEngine::lock.

Referenced by ~MCJIT().

void MCJIT::NotifyObjectEmitted ( const ObjectImage Obj)
protected
void * MCJIT::recompileAndRelinkFunction ( Function F)
virtual

recompileAndRelinkFunction - This method is used to force a function which has already been compiled to be compiled again, possibly after it has been modified. Then the entry to the old copy is overwritten with a branch to the new copy. If there was no old copy, this acts just like VM::getPointerToFunction().

Implements llvm::ExecutionEngine.

Definition at line 334 of file MCJIT.cpp.

References llvm::report_fatal_error().

static void llvm::MCJIT::Register ( )
inlinestatic
void MCJIT::RegisterJITEventListener ( JITEventListener )
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 501 of file MCJIT.cpp.

References llvm::ExecutionEngine::lock.

bool MCJIT::removeModule ( Module M)
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 
)
virtual
void MCJIT::runStaticConstructorsDestructors ( bool  isDtors)
virtual

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

void MCJIT::setObjectCache ( ObjectCache manager)
virtual

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

Reimplemented from llvm::ExecutionEngine.

Definition at line 104 of file MCJIT.cpp.

References llvm::ExecutionEngine::lock.

void MCJIT::UnregisterJITEventListener ( JITEventListener L)
virtual

Reimplemented from llvm::ExecutionEngine.

Definition at line 507 of file MCJIT.cpp.

References llvm::ExecutionEngine::lock, and std::swap().


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