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 = 0
static EECtorFn InterpCtor = 0

Detailed Description

Definition at line 61 of file ExecutionEngine.h.


Member Typedef Documentation

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

Definition at line 77 of file ExecutionEngine.h.


Constructor & Destructor Documentation

ExecutionEngine::ExecutionEngine ( ModuleProvider P  ) 

Definition at line 37 of file ExecutionEngine.cpp.

ExecutionEngine::ExecutionEngine ( Module M  ) 

Definition at line 42 of file ExecutionEngine.cpp.

References M.

ExecutionEngine::~ExecutionEngine (  )  [virtual]

Definition at line 46 of file ExecutionEngine.cpp.

References MP.


Member Function Documentation

void llvm::ExecutionEngine::addGlobalMapping ( const GlobalValue GV,
void *  Addr 
) [inline]

Definition at line 117 of file ExecutionEngine.h.

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 llvm::ExecutionEngine::clearAllGlobalMappings (  )  [inline]

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

Definition at line 134 of file ExecutionEngine.h.

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

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 161 of file ExecutionEngine.cpp.

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

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 529 of file ExecutionEngine.cpp.

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

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

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

Definition at line 568 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().

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.

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

FIXME: document

Definition at line 205 of file ExecutionEngine.cpp.

References abort(), llvm::Type::BoolTyID, llvm::CallingConv::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().

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

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

Definition at line 53 of file ExecutionEngine.cpp.

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

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

Definition at line 90 of file ExecutionEngine.h.

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

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 216 of file ExecutionEngine.h.

References getPointerToGlobal(), and GV.

Referenced by getConstantValue().

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 185 of file ExecutionEngine.h.

References F, and getPointerToFunction().

Referenced by getConstantValue().

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 185 of file ExecutionEngine.cpp.

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

Referenced by getOrEmitGlobalVariable().

void* llvm::ExecutionEngine::getPointerToGlobalIfAvailable ( const GlobalValue GV  )  [inline]

getPointerToGlobalIfAvailable - This returns the address of the specified global value if it is available, otherwise it returns null.

Definition at line 162 of file ExecutionEngine.h.

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

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

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

Definition at line 91 of file ExecutionEngine.h.

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

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

Definition at line 482 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().

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

FIXME: document

Definition at line 404 of file ExecutionEngine.cpp.

References abort(), 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().

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 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().

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 133 of file ExecutionEngine.cpp.

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

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 103 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().

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

Definition at line 70 of file ExecutionEngine.h.

References td.

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

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

FIXME: document

Definition at line 329 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 llvm::ExecutionEngine::updateGlobalMapping ( const GlobalValue GV,
void *  Addr 
) [inline]

updateGlobalMapping - Replace an existing mapping for GV with a new address. This updates both maps as required.

Definition at line 143 of file ExecutionEngine.h.

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


Member Data Documentation

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

Definition at line 78 of file ExecutionEngine.h.

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

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

Definition at line 78 of file ExecutionEngine.h.

Referenced by create(), and llvm::JIT::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 84 of file ExecutionEngine.h.

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

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

Definition at line 68 of file ExecutionEngine.h.

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


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