33 static struct RegisterJIT {
43 std::string *ErrorStr,
57 bool AllocateGVsWithCode)
61 OwnedModules.addModule(m);
81 for (it = LoadedObjects.
begin(); it !=
end; ++it) {
88 LoadedObjects.
clear();
94 OwnedModules.addModule(M);
99 return OwnedModules.removeModule(M);
132 CompiledObject->
flush();
143 return CompiledObject.
take();
151 assert(OwnedModules.ownsModule(M) &&
152 "MCJIT::generateCodeForModule: Unknown module.");
155 if (OwnedModules.hasModuleBeenLoaded(M))
162 if (0 != PreCompiledObject.get())
169 assert(ObjectToLoad.
get() &&
"Compilation did not produce an object.");
175 LoadedObjects[M] = LoadedObject;
184 OwnedModules.markModuleAsLoaded(M);
193 OwnedModules.markAllLoadedModulesAsFinalized();
207 E = OwnedModules.end_added();
220 assert(OwnedModules.ownsModule(M) &&
"MCJIT::finalizeModule: Unknown module.");
223 if (!OwnedModules.hasModuleBeenLoaded(M))
242 bool CheckFunctionsOnly) {
247 E = OwnedModules.end_added();
253 if (!CheckFunctionsOnly) {
265 bool CheckFunctionsOnly)
313 bool HasBeenAddedButNotLoaded = OwnedModules.hasModuleBeenAddedButNotLoaded(M);
316 if (HasBeenAddedButNotLoaded)
318 else if (!OwnedModules.hasModuleBeenLoaded(M))
328 if (BaseName[0] ==
'\1')
342 void MCJIT::runStaticConstructorsDestructorsInModulePtrSet(
343 bool isDtors, ModulePtrSet::iterator
I, ModulePtrSet::iterator E) {
344 for (; I != E; ++
I) {
351 runStaticConstructorsDestructorsInModulePtrSet(
352 isDtors, OwnedModules.begin_added(), OwnedModules.end_added());
353 runStaticConstructorsDestructorsInModulePtrSet(
354 isDtors, OwnedModules.begin_loaded(), OwnedModules.end_loaded());
355 runStaticConstructorsDestructorsInModulePtrSet(
356 isDtors, OwnedModules.begin_finalized(), OwnedModules.end_finalized());
359 Function *MCJIT::FindFunctionNamedInModulePtrSet(
const char *FnName,
360 ModulePtrSet::iterator I,
361 ModulePtrSet::iterator E) {
362 for (; I != E; ++
I) {
363 if (
Function *
F = (*I)->getFunction(FnName))
370 Function *
F = FindFunctionNamedInModulePtrSet(
371 FnName, OwnedModules.begin_added(), OwnedModules.end_added());
373 F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_loaded(),
374 OwnedModules.end_loaded());
376 F = FindFunctionNamedInModulePtrSet(FnName, OwnedModules.begin_finalized(),
377 OwnedModules.end_finalized());
382 const std::vector<GenericValue> &ArgValues) {
383 assert(F &&
"Function *F was null at entry to run()");
386 assert(FPtr &&
"Pointer to fn's code was null after getPointerToFunction");
392 "Wrong number of arguments passed into function!");
394 "This doesn't support passing arguments through varargs (yet)!");
399 switch (ArgValues.size()) {
404 int (*PF)(int,
char **,
const char **) =
405 (
int(*)(int,
char **,
const char **))(
intptr_t)FPtr;
410 (
char **)
GVTOP(ArgValues[1]),
411 (
const char **)
GVTOP(ArgValues[2])));
418 int (*PF)(int,
char **) = (
int(*)(int,
char **))(
intptr_t)FPtr;
423 (
char **)
GVTOP(ArgValues[1])));
431 int (*PF)(int) = (
int(*)(int))(
intptr_t)FPtr;
440 if (ArgValues.empty()) {
445 unsigned BitWidth = cast<IntegerType>(RetTy)->
getBitWidth();
448 else if (BitWidth <= 8)
450 else if (BitWidth <= 16)
452 else if (BitWidth <= 32)
454 else if (BitWidth <= 64)
482 bool AbortOnFailure) {
494 if (AbortOnFailure) {
496 "' which could not be resolved!");
505 EventListeners.push_back(L);
512 std::find(EventListeners.rbegin(), EventListeners.rend(), L);
513 if (I != EventListeners.rend()) {
515 EventListeners.pop_back();
521 for (
unsigned I = 0, S = EventListeners.size(); I < S; ++
I) {
522 EventListeners[
I]->NotifyObjectEmitted(Obj);
527 for (
unsigned I = 0, S = EventListeners.size(); I < S; ++
I) {
528 EventListeners[
I]->NotifyFreeingObject(Obj);
536 if (!Result && Name[0] ==
'_')
540 return ClientMM->getSymbolAddress(Name);
std::reverse_iterator< iterator > reverse_iterator
const_iterator end(StringRef path)
Get end iterator over path.
virtual bool finalizeMemory(std::string *ErrMsg=0)
virtual void * getPointerToBasicBlock(BasicBlock *BB)
The main container class for the LLVM Intermediate Representation.
unsigned getNumParams() const
2: 32-bit floating point type
virtual Function * FindFunctionNamed(const char *FnName)
StringRef getErrorString()
StringRef substr(size_t Start, size_t N=npos) const
bool hasAvailableExternallyLinkage() const
virtual void notifyObjectLoaded(ExecutionEngine *EE, const ObjectImage *Obj)
ObjectImage * loadObject(ObjectBuffer *InputBuffer)
4: 80-bit floating point type (X87)
virtual void setObjectCache(ObjectCache *manager)
Sets the object manager that MCJIT should use to avoid compilation.
virtual void * recompileAndRelinkFunction(Function *F)
void deregisterEHFrames()
const GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false) const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
StringRef getName() const
void runStaticConstructorsDestructors(bool isDtors)
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
static ExecutionEngine * createJIT(Module *M, std::string *ErrorStr, RTDyldMemoryManager *MemMgr, bool GVsWithCode, TargetMachine *TM)
virtual void runStaticConstructorsDestructors(bool isDtors)
void setDataLayout(const DataLayout *td)
const MCAsmInfo * getMCAsmInfo() const
#define llvm_unreachable(msg)
void *(* LazyFunctionCreator)(const std::string &)
virtual bool removeModule(Module *M)
virtual void finalizeModule(Module *)
virtual uint64_t getGlobalValueAddress(const std::string &Name)
MemoryBuffer * getMemBuffer() const
uint64_t getExistingSymbolAddress(const std::string &Name)
virtual void UnregisterJITEventListener(JITEventListener *L)
Function * getFunction(StringRef Name) const
10: Arbitrary bit width integers
virtual void * getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure=true)
Guard a section of code with a Mutex.
ObjectBufferStream * emitObject(Module *M)
Type * getParamType(unsigned i) const
Parameter type accessors.
LLVM Basic Block Representation.
virtual MemoryBuffer * getObject(const Module *M)=0
bool isSymbolSearchingDisabled() const
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=0)
raw_ostream & getOStream()
6: 128-bit floating point type (two 64-bits, PowerPC)
void NotifyObjectEmitted(const ObjectImage &Obj)
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
void * GVTOP(const GenericValue &GV)
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
bool hasExternalWeakLinkage() const
uint64_t getSymbolLoadAddress(StringRef Name)
const char * getGlobalPrefix() const
uint64_t getSymbolAddress(const std::string &Name, bool CheckFunctionsOnly)
virtual bool addPassesToEmitMC(PassManagerBase &, MCContext *&, raw_ostream &, bool=true)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
virtual void * getPointerToFunction(Function *F)
GenericValue PTOGV(void *P)
Class for arbitrary precision integers.
Module * findModuleForSymbol(const std::string &Name, bool CheckFunctionsOnly)
virtual uint64_t getSymbolAddress(const std::string &Name)
void addGlobalMapping(const GlobalValue *GV, void *Addr)
void NotifyFreeingObject(const ObjectImage &Obj)
bool isDeclaration() const
virtual void freeMachineCodeForFunction(Function *F)
virtual const DataLayout * getDataLayout() const
FunctionType * getFunctionType() const
SmallVector< Module *, 1 > Modules
virtual void registerWithDebugger()=0
void resolveRelocations()
Resolve the relocations for all symbols we currently know about.
3: 64-bit floating point type
Type * getReturnType() const
virtual void * getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure=true)
virtual void addModule(Module *M)
virtual void RegisterJITEventListener(JITEventListener *L)
virtual GenericValue runFunction(Function *F, const std::vector< GenericValue > &ArgValues)
void finalizeLoadedModules()
virtual void notifyObjectCompiled(const Module *M, const MemoryBuffer *Obj)=0
notifyObjectCompiled - Provides a pointer to compiled code for Module M.
virtual uint64_t getFunctionAddress(const std::string &Name)
virtual void generateCodeForModule(Module *M)
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
5: 128-bit floating point type (112-bit mantissa)
virtual void finalizeObject()