LLVM API Documentation

llvm::ExecutionEngine Class Reference

#include <ExecutionEngine.h>

Inheritance diagram for llvm::ExecutionEngine:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ExecutionEngine (ModuleProvider *P)
 ExecutionEngine (Module *M)
virtual ~ExecutionEngine ()
ModulegetModule () const
const TargetDatagetTargetData () const
virtual GenericValue runFunction (Function *F, const std::vector< GenericValue > &ArgValues)=0
void runStaticConstructorsDestructors (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 updateGlobalMapping (const GlobalValue *GV, void *Addr)
void * getPointerToGlobalIfAvailable (const GlobalValue *GV)
void * getPointerToGlobal (const GlobalValue *GV)
virtual void * getPointerToFunction (Function *F)=0
virtual void * getPointerToFunctionOrStub (Function *F)
const GlobalValuegetGlobalValueAtAddress (void *Addr)
void StoreValueToMemory (GenericValue Val, GenericValue *Ptr, const Type *Ty)
void InitializeMemory (const Constant *Init, void *Addr)
virtual void * recompileAndRelinkFunction (Function *F)=0
virtual void freeMachineCodeForFunction (Function *F)=0
virtual void * getOrEmitGlobalVariable (const GlobalVariable *GV)

Static Public Member Functions

static ExecutionEnginecreate (ModuleProvider *MP, bool ForceInterpreter=false)

Public Attributes

sys::Mutex lock

Protected Types

typedef ExecutionEngine *(*) EECtorFn (ModuleProvider *)

Protected Member Functions

void setTargetData (const TargetData *td)
void emitGlobals ()
void EmitGlobalVariable (const GlobalVariable *GV)
GenericValue getConstantValue (const Constant *C)
GenericValue LoadValueFromMemory (GenericValue *Ptr, const Type *Ty)

Protected Attributes

ModuleProviderMP

Static Protected Attributes

static EECtorFn JITCtor
static EECtorFn InterpCtor

Detailed Description

Definition at line 62 of file ExecutionEngine.h.


Member Typedef Documentation

typedef ExecutionEngine*(*) llvm::ExecutionEngine::EECtorFn(ModuleProvider *) [protected]

Definition at line 78 of file ExecutionEngine.h.


Constructor & Destructor Documentation

ExecutionEngine::ExecutionEngine ( ModuleProvider P  ) 

Definition at line 38 of file ExecutionEngine.cpp.

ExecutionEngine::ExecutionEngine ( Module M  ) 

Definition at line 43 of file ExecutionEngine.cpp.

References M.

ExecutionEngine::~ExecutionEngine (  )  [virtual]

Definition at line 47 of file ExecutionEngine.cpp.

References MP.


Member Function Documentation

void llvm::ExecutionEngine::setTargetData ( const TargetData td  )  [inline, protected]

Definition at line 71 of file ExecutionEngine.h.

References td.

Referenced by llvm::Interpreter::Interpreter().

Module& llvm::ExecutionEngine::getModule (  )  const [inline]

Definition at line 91 of file ExecutionEngine.h.

Referenced by emitGlobals(), getPointerToNamedFunction(), and lle_X_sprintf().

const TargetData* llvm::ExecutionEngine::getTargetData (  )  const [inline]

Definition at line 92 of file ExecutionEngine.h.

Referenced by CreateArgv(), emitGlobals(), EmitGlobalVariable(), getConstantValue(), llvm::JIT::getOrEmitGlobalVariable(), InitializeMemory(), LoadValueFromMemory(), and StoreValueToMemory().

ExecutionEngine * ExecutionEngine::create ( ModuleProvider MP,
bool  ForceInterpreter = false 
) [static]

create - This is the factory method for creating an execution engine which is appropriate for the current machine.

Definition at line 235 of file ExecutionEngine.cpp.

References InterpCtor, JITCtor, llvm::sys::DynamicLibrary::LoadLibraryPermanently(), and MP.

virtual GenericValue llvm::ExecutionEngine::runFunction ( Function F,
const std::vector< GenericValue > &  ArgValues 
) [pure virtual]

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

Implemented in llvm::Interpreter, and llvm::JIT.

Referenced by runFunctionAsMain(), and runStaticConstructorsDestructors().

void ExecutionEngine::runStaticConstructorsDestructors ( bool  isDtors  ) 

runStaticConstructorsDestructors - This method is used to execute all of the static constructors or destructors for a module, depending on the value of isDtors.

Definition at line 173 of file ExecutionEngine.cpp.

References llvm::Instruction::Cast, F, llvm::Module::getNamedGlobal(), llvm::User::getNumOperands(), llvm::Constant::getOperand(), GV, llvm::GlobalValue::hasInternalLinkage(), llvm::GlobalValue::isExternal(), llvm::Constant::isNullValue(), Name, and runFunction().

int ExecutionEngine::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.

Definition at line 207 of file ExecutionEngine.cpp.

References CreateArgv(), llvm::Function::getFunctionType(), llvm::FunctionType::getNumParams(), llvm::GVTOP(), llvm::GenericValue::IntVal, llvm::PTOGV(), and runFunction().

void ExecutionEngine::addGlobalMapping ( const GlobalValue GV,
void *  Addr 
)

addGlobalMapping - Tell the execution engine that the specified global is at the specified location. This is used internally as functions are JIT'd and as global variables are laid out in memory. It can and should also be used by clients of the EE that want to have an LLVM global overlay existing data in memory.

Definition at line 56 of file ExecutionEngine.cpp.

References llvm::ExecutionEngineState::getGlobalAddressMap(), llvm::ExecutionEngineState::getGlobalAddressReverseMap(), GV, lock, and V.

Referenced by emitGlobals(), EmitGlobalVariable(), llvm::JIT::getOrEmitGlobalVariable(), llvm::JIT::getPointerToFunction(), and llvm::JIT::recompileAndRelinkFunction().

void ExecutionEngine::clearAllGlobalMappings (  ) 

clearAllGlobalMappings - Clear all global mappings and start over again use in dynamic compilation scenarios when you want to move globals

Definition at line 73 of file ExecutionEngine.cpp.

References llvm::ExecutionEngineState::getGlobalAddressMap(), llvm::ExecutionEngineState::getGlobalAddressReverseMap(), and lock.

void ExecutionEngine::updateGlobalMapping ( const GlobalValue GV,
void *  Addr 
)

updateGlobalMapping - Replace an existing mapping for GV with a new address. This updates both maps as required. If "Addr" is null, the entry for the global is removed from the mappings.

Definition at line 83 of file ExecutionEngine.cpp.

References llvm::ExecutionEngineState::getGlobalAddressMap(), llvm::ExecutionEngineState::getGlobalAddressReverseMap(), GV, lock, and V.

Referenced by llvm::JIT::freeMachineCodeForFunction().

void * ExecutionEngine::getPointerToGlobalIfAvailable ( const GlobalValue GV  ) 

getPointerToGlobalIfAvailable - This returns the address of the specified global value if it is has already been codegen'd, otherwise it returns null.

Definition at line 110 of file ExecutionEngine.cpp.

References llvm::ExecutionEngineState::getGlobalAddressMap(), GV, and lock.

Referenced by EmitGlobalVariable(), llvm::JIT::getOrEmitGlobalVariable(), llvm::JIT::getPointerToFunction(), llvm::JIT::getPointerToFunctionOrStub(), and llvm::JIT::recompileAndRelinkFunction().

void * ExecutionEngine::getPointerToGlobal ( const GlobalValue GV  ) 

getPointerToGlobal - This returns the address of the specified global value. This may involve code generation if it's a function.

Definition at line 262 of file ExecutionEngine.cpp.

References EmitGlobalVariable(), F, llvm::ExecutionEngineState::getGlobalAddressMap(), getPointerToFunction(), GV, and lock.

Referenced by getOrEmitGlobalVariable().

virtual void* llvm::ExecutionEngine::getPointerToFunction ( Function F  )  [pure 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.

Implemented in llvm::JIT.

Referenced by getPointerToFunctionOrStub(), and getPointerToGlobal().

virtual void* llvm::ExecutionEngine::getPointerToFunctionOrStub ( Function F  )  [inline, virtual]

getPointerToFunctionOrStub - If the specified function has been code-gen'd, return a pointer to the function. If not, compile it, or use a stub to implement lazy compilation if available.

Reimplemented in llvm::JIT.

Definition at line 155 of file ExecutionEngine.h.

References F, and getPointerToFunction().

Referenced by getConstantValue().

const GlobalValue * ExecutionEngine::getGlobalValueAtAddress ( void *  Addr  ) 

getGlobalValueAtAddress - Return the LLVM global value object that starts at the specified address.

Definition at line 121 of file ExecutionEngine.cpp.

References E, llvm::ExecutionEngineState::getGlobalAddressMap(), llvm::ExecutionEngineState::getGlobalAddressReverseMap(), and lock.

void ExecutionEngine::StoreValueToMemory ( GenericValue  Val,
GenericValue Ptr,
const Type Ty 
)

StoreValueToMemory - Stores the data in Val of type Ty at address Ptr. Ptr is the address of the memory at which to store Val, cast to GenericValue *. It is not a pointer to a GenericValue containing the address at which to store Val.

Definition at line 409 of file ExecutionEngine.cpp.

References llvm::Type::BoolTyID, llvm::Type::DoubleTyID, llvm::Type::FloatTyID, getTargetData(), llvm::Type::getTypeID(), llvm::Type::IntTyID, llvm::Type::LongTyID, llvm::Type::PointerTyID, llvm::Type::SByteTyID, llvm::Type::ShortTyID, Ty, llvm::Type::UByteTyID, llvm::Type::UIntTyID, llvm::Type::ULongTyID, llvm::GenericValue::Untyped, llvm::Type::UShortTyID, and Val.

Referenced by ByteswapSCANFResults(), CreateArgv(), InitializeMemory(), and llvm::Interpreter::visitStoreInst().

void ExecutionEngine::InitializeMemory ( const Constant Init,
void *  Addr 
)

Definition at line 562 of file ExecutionEngine.cpp.

References llvm::Type::ArrayTyID, CP, getConstantValue(), llvm::User::getNumOperands(), llvm::Constant::getOperand(), llvm::TargetData::getStructLayout(), getTargetData(), llvm::ConstantStruct::getType(), llvm::Value::getType(), llvm::TargetData::getTypeSize(), StoreValueToMemory(), llvm::Type::StructTyID, and Val.

Referenced by EmitGlobalVariable().

virtual void* llvm::ExecutionEngine::recompileAndRelinkFunction ( Function F  )  [pure 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().

Implemented in llvm::Interpreter, and llvm::JIT.

virtual void llvm::ExecutionEngine::freeMachineCodeForFunction ( Function F  )  [pure virtual]

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

Implemented in llvm::Interpreter, and llvm::JIT.

virtual void* llvm::ExecutionEngine::getOrEmitGlobalVariable ( const GlobalVariable GV  )  [inline, virtual]

getOrEmitGlobalVariable - Return the address of the specified global variable, possibly emitting it to memory if needed. This is used by the Emitter.

Reimplemented in llvm::JIT.

Definition at line 186 of file ExecutionEngine.h.

References getPointerToGlobal(), and GV.

Referenced by getConstantValue().

void ExecutionEngine::emitGlobals (  )  [protected]

EmitGlobals - Emit all of the global variables to memory, storing their addresses into GlobalAddress. This must make sure to copy the contents of their initializers into the memory.

Definition at line 609 of file ExecutionEngine.cpp.

References addGlobalMapping(), E, EmitGlobalVariable(), getModule(), getTargetData(), llvm::TargetData::getTypeSize(), llvm::Module::global_begin(), llvm::Module::global_end(), M, llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(), and Ty.

Referenced by llvm::Interpreter::Interpreter().

void ExecutionEngine::EmitGlobalVariable ( const GlobalVariable GV  )  [protected]

Definition at line 648 of file ExecutionEngine.cpp.

References addGlobalMapping(), DEBUG, llvm::SequentialType::getElementType(), llvm::Value::getName(), getPointerToGlobalIfAvailable(), getTargetData(), llvm::GlobalValue::getType(), llvm::TargetData::getTypeSize(), GV, InitializeMemory(), NumGlobals, and NumInitBytes.

Referenced by emitGlobals(), and getPointerToGlobal().

GenericValue ExecutionEngine::getConstantValue ( const Constant C  )  [protected]

FIXME: document

Definition at line 282 of file ExecutionEngine.cpp.

References llvm::Type::BoolTyID, C, llvm::Instruction::Cast, llvm::Type::DoubleTyID, llvm::GenericValue::DoubleVal, F, llvm::Type::FloatTyID, llvm::GenericValue::FloatVal, GET_CONST_VAL, llvm::TargetData::getIndexedOffset(), getOrEmitGlobalVariable(), getPointerToFunctionOrStub(), getTargetData(), GV, llvm::Type::IntTyID, llvm::GenericValue::IntVal, llvm::Type::LongTyID, llvm::GenericValue::LongVal, Offset, Op, llvm::Type::PointerTyID, llvm::GenericValue::PointerVal, llvm::PTOGV(), llvm::Type::SByteTyID, llvm::GenericValue::SByteVal, llvm::Type::ShortTyID, llvm::GenericValue::ShortVal, llvm::Type::UByteTyID, llvm::Type::UIntTyID, llvm::Type::ULongTyID, llvm::Type::UShortTyID, and Val.

Referenced by InitializeMemory().

GenericValue ExecutionEngine::LoadValueFromMemory ( GenericValue Ptr,
const Type Ty 
) [protected]

FIXME: document

Definition at line 484 of file ExecutionEngine.cpp.

References llvm::Type::BoolTyID, llvm::Type::DoubleTyID, llvm::Type::FloatTyID, llvm::TargetData::getPointerSize(), getTargetData(), llvm::Type::getTypeID(), llvm::Type::IntTyID, llvm::Type::LongTyID, llvm::Type::PointerTyID, llvm::Type::SByteTyID, llvm::Type::ShortTyID, Ty, llvm::Type::UByteTyID, llvm::GenericValue::UByteVal, llvm::Type::UIntTyID, llvm::GenericValue::UIntVal, llvm::Type::ULongTyID, llvm::GenericValue::ULongVal, llvm::GenericValue::Untyped, llvm::Type::UShortTyID, and llvm::GenericValue::UShortVal.

Referenced by llvm::Interpreter::visitLoadInst().


Member Data Documentation

ModuleProvider* llvm::ExecutionEngine::MP [protected]

Definition at line 69 of file ExecutionEngine.h.

Referenced by llvm::JIT::create(), llvm::Interpreter::create(), create(), llvm::JIT::getPointerToFunction(), and ~ExecutionEngine().

ExecutionEngine::EECtorFn ExecutionEngine::JITCtor [static, protected]

Definition at line 79 of file ExecutionEngine.h.

Referenced by create(), and llvm::JIT::Register().

ExecutionEngine::EECtorFn ExecutionEngine::InterpCtor [static, protected]

Definition at line 79 of file ExecutionEngine.h.

Referenced by create(), and llvm::Interpreter::Register().

sys::Mutex llvm::ExecutionEngine::lock

lock - This lock is protects the ExecutionEngine, JIT, JITResolver and JITEmitter classes. It must be held while changing the internal state of any of those classes.

Definition at line 85 of file ExecutionEngine.h.

Referenced by addGlobalMapping(), clearAllGlobalMappings(), getGlobalValueAtAddress(), llvm::JIT::getOrEmitGlobalVariable(), llvm::JIT::getPointerToFunction(), getPointerToGlobal(), getPointerToGlobalIfAvailable(), and updateGlobalMapping().


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