10 #ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H
11 #define LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H
33 std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver)
34 : ParentEngine(Parent), ClientResolver(std::move(Resolver)) {}
46 std::shared_ptr<RuntimeDyld::SymbolResolver> ClientResolver;
70 MCJIT(std::unique_ptr<Module> M, std::unique_ptr<TargetMachine> tm,
71 std::shared_ptr<MCJITMemoryManager> MemMgr,
72 std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver);
76 class OwningModuleContainer {
78 OwningModuleContainer() {
80 ~OwningModuleContainer() {
81 freeModulePtrSet(AddedModules);
82 freeModulePtrSet(LoadedModules);
83 freeModulePtrSet(FinalizedModules);
98 void addModule(std::unique_ptr<Module> M) {
99 AddedModules.insert(M.release());
103 return AddedModules.erase(M) || LoadedModules.erase(M) ||
104 FinalizedModules.erase(M);
107 bool hasModuleBeenAddedButNotLoaded(
Module *M) {
108 return AddedModules.count(M) != 0;
111 bool hasModuleBeenLoaded(
Module *M) {
114 return (LoadedModules.count(M) != 0 ) || (FinalizedModules.count(M) != 0);
117 bool hasModuleBeenFinalized(
Module *M) {
118 return FinalizedModules.count(M) != 0;
121 bool ownsModule(
Module* M) {
122 return (AddedModules.count(M) != 0) || (LoadedModules.count(M) != 0) ||
123 (FinalizedModules.count(M) != 0);
126 void markModuleAsLoaded(
Module *M) {
130 assert(AddedModules.count(M) &&
131 "markModuleAsLoaded: Module not found in AddedModules");
134 AddedModules.erase(M);
137 LoadedModules.insert(M);
140 void markModuleAsFinalized(
Module *M) {
145 assert(LoadedModules.count(M) &&
146 "markModuleAsFinalized: Module not found in LoadedModules");
149 LoadedModules.erase(M);
153 FinalizedModules.insert(M);
156 void markAllLoadedModulesAsFinalized() {
158 E = LoadedModules.end();
161 FinalizedModules.insert(M);
163 LoadedModules.clear();
181 std::unique_ptr<TargetMachine> TM;
183 std::shared_ptr<MCJITMemoryManager> MemMgr;
186 std::vector<JITEventListener*> EventListeners;
188 OwningModuleContainer OwnedModules;
199 Function *FindFunctionNamedInModulePtrSet(
const char *FnName,
208 void runStaticConstructorsDestructorsInModulePtrSet(
bool isDtors,
217 void addModule(std::unique_ptr<Module> M)
override;
218 void addObjectFile(std::unique_ptr<object::ObjectFile> O)
override;
275 bool AbortOnFailure =
true)
override;
306 std::string *ErrorStr,
307 std::shared_ptr<MCJITMemoryManager> MemMgr,
308 std::shared_ptr<RuntimeDyld::SymbolResolver> Resolver,
309 std::unique_ptr<TargetMachine> TM);
314 bool CheckFunctionsOnly);
319 bool CheckFunctionsOnly);
335 bool CheckFunctionsOnly);
Information about the loaded object.
void setObjectCache(ObjectCache *manager) override
Sets the object manager that MCJIT should use to avoid compilation.
virtual Function * FindFunctionNamed(const char *FnName) override
FindFunctionNamed - Search all of the active modules to find the function that defines FnName...
A Module instance is used to store all the information related to an LLVM module. ...
JITEventListener - Abstract interface for use by the JIT to notify clients about significant events d...
This class is the base class for all object file types.
void generateCodeForModule(Module *M) override
generateCodeForModule - Run code generation for the specified module and load it into memory...
void UnregisterJITEventListener(JITEventListener *L) override
static ExecutionEngine *(* MCJITCtor)(std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MM, std::shared_ptr< RuntimeDyld::SymbolResolver > SR, std::unique_ptr< TargetMachine > TM)
void runStaticConstructorsDestructors(bool isDtors) override
runStaticConstructorsDestructors - This method is used to execute all of the static constructors or d...
Context object for machine code objects.
uint64_t getGlobalValueAddress(const std::string &Name) override
getGlobalValueAddress - Return the address of the specified global value.
virtual void finalizeModule(Module *)
RuntimeDyld::SymbolInfo findSymbolInLogicalDylib(const std::string &Name) override
This method returns the address of the specified symbol if it exists within the logical dynamic libra...
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name, bool CheckFunctionsOnly)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void * getPointerToFunction(Function *F) override
getPointerToFunction - The different EE's represent function bodies in different ways.
void setProcessAllSections(bool ProcessAllSections)
By default, only sections that are "required for execution" are passed to the RTDyldMemoryManager, and other sections are discarded.
void finalizeObject() override
finalizeObject - ensure the module is fully processed and is usable.
static ExecutionEngine * createJIT(std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MemMgr, std::shared_ptr< RuntimeDyld::SymbolResolver > Resolver, std::unique_ptr< TargetMachine > TM)
void addModule(std::unique_ptr< Module > M) override
Add a Module to the list of modules that we can JIT from.
void setProcessAllSections(bool ProcessAllSections) override
setProcessAllSections (MCJIT Only): By default, only sections that are "required for execution" are p...
bool removeModule(Module *M) override
removeModule - Remove a Module from the list of modules.
void * getPointerToNamedFunction(StringRef Name, bool AbortOnFailure=true) override
getPointerToNamedFunction - This method returns the address of the specified function by using the dl...
uint64_t getFunctionAddress(const std::string &Name) override
getFunctionAddress - Return the address of the specified function.
TargetMachine * getTargetMachine() override
Return the target machine (if available).
virtual GlobalVariable * FindGlobalVariableNamed(const char *Name, bool AllowInternal=false) override
FindGlobalVariableNamed - Search all of the active modules to find the global variable that defines N...
Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...
void addArchive(object::OwningBinary< object::Archive > O) override
addArchive - Add an Archive to the execution engine.
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress) override
mapSectionAddress - map a section to its target address space value.
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
RuntimeDyld::SymbolInfo findExistingSymbol(const std::string &Name)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
uint64_t getSymbolAddress(const std::string &Name, bool CheckFunctionsOnly)
uint64_t TargetAddress
Represents an address in the target process's address space.
void RegisterJITEventListener(JITEventListener *L) override
Registers a listener to be called back on various events within the JIT.
A range adaptor for a pair of iterators.
Module * findModuleForSymbol(const std::string &Name, bool CheckFunctionsOnly)
GenericValue runFunction(Function *F, ArrayRef< GenericValue > ArgValues) override
runFunction - Execute the specified function with the specified arguments, and return the result...
std::unique_ptr< MemoryBuffer > emitObject(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.
RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override
This method returns the address of the specified function or variable.
Information about a named symbol.
This is the base ObjectCache type which can be provided to an ExecutionEngine for the purpose of avoi...
LinkingSymbolResolver(MCJIT &Parent, std::shared_ptr< RuntimeDyld::SymbolResolver > Resolver)
void NotifyFreeingObject(const object::ObjectFile &Obj)
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
void NotifyObjectEmitted(const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L)
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress)
Map a section to its target address space value.
void finalizeLoadedModules()
void addObjectFile(std::unique_ptr< object::ObjectFile > O) override
addObjectFile - Add an ObjectFile to the execution engine.