roadrunner  2.6.0
Fast simulator for SBML models
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
rrllvm::Jit Class Referenceabstract

superclass of all Jit types. More...

#include <Jit.h>

Inheritance diagram for rrllvm::Jit:
rrllvm::LLJit

Public Member Functions

 Jit (std::uint32_t options)
 instantiate a Jit object with some options. More...
 
 Jit ()
 default constructor. More...
 
virtual void mapFunctionsToJitSymbols ()=0
 adds functions that are declared and defined in C++ to the jit engine. More...
 
virtual ~Jit ()=default
 Add support for libsbml distrib functions. More...
 
virtual std::uint64_t lookupFunctionAddress (const std::string &name)=0
 
virtual void addObjectFile (rrOwningBinary owningObject)=0
 add an in-memory representation of an object file to the current jit module. More...
 
virtual void addObjectFile (std::unique_ptr< llvm::object::ObjectFile > objectFile)=0
 add an in-memory representation of an object file to the current jit module.
 
virtual void addObjectFile (std::unique_ptr< llvm::MemoryBuffer > obj)=0
 add an in-memory representation of an object file to the current jit module.
 
virtual void addModule (llvm::Module *M)=0
 add a module More...
 
virtual void addModule (std::unique_ptr< llvm::Module > M, std::unique_ptr< llvm::LLVMContext > ctx)=0
 add a module More...
 
virtual void addModule ()=0
 add the module and context which are member variables of the Jit instance to the current Jit engine. More...
 
virtual const llvm::DataLayout & getDataLayout () const =0
 get the DataLayout currently in use in the Jit
 
virtual std::unique_ptr< llvm::MemoryBuffer > getCompiledModelFromCache (const std::string &sbmlMD5)=0
 lookup the sbml with the md5 More...
 
virtual void transferObjectsToResources (std::shared_ptr< rrllvm::ModelResources > modelResources)
 Moves objects over to ModelResources ptr
 
virtual void mapLLVMGeneratedFunctionsToSymbols (ModelResources *modelResources, std::uint32_t options)
 Map the Jit'd functions that collectively represent a roadrunner compiled sbml model to symbols in the ModelResources. More...
 
virtual llvm::Module * getModuleNonOwning ()
 returns a non owning pointer to the llvm::Module instance
 
virtual llvm::LLVMContext * getContextNonOwning ()
 returns a non owning pointer to the llvm::LLVMContext instance
 
virtual llvm::IRBuilder * getBuilderNonOwning ()
 returns a non owning pointer to the llvm::LLVMContext instance
 
virtual std::string emitToString ()
 Write the Jit::module in its current state to string as LLVM IR.
 
llvm::raw_svector_ostream & getCompiledModuleStream ()
 get the stream that stores a compiled module as binary.
 
std::string getDefaultTargetTriple () const
 
void setModuleIdentifier (const std::string &id)
 
virtual std::string mangleName (const std::string &unmangledName) const
 
virtual std::string getModuleAsString (std::string sbmlMD5)=0
 get a binary string representation of the current module. More...
 

Public Attributes

std::unique_ptr< llvm::raw_svector_ostream > compiledModuleBinaryStream
 MCJit compiles the generated LLVM IR to this binary stream which is then used both for adding to the Jit as a module and for saveState. More...
 
llvm::SmallVector< char, 10 > moduleBuffer
 The buffer used by compiledModuleBinaryStream.
 

Protected Member Functions

std::string getProcessTriple () const
 getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the current process, e.g. More...
 
const llvm::Target * getDefaultTargetMachine () const
 use llvm calls to work out which TargetMachine is currently being used.
 
FnMap externalFunctionSignatures () const
 returns a mapping between function names and function signatures
 

Protected Attributes

std::unique_ptr< llvm::LLVMContext > context
 
std::unique_ptr< llvm::Module > module
 
llvm::Module * moduleNonOwning = nullptr
 
std::unique_ptr< llvm::IRBuilder<> > builder
 
std::uint32_t options
 

Detailed Description

superclass of all Jit types.

Builds the machinery necessary to compile a sbml model on the fly to machine code.

Constructor & Destructor Documentation

◆ Jit() [1/2]

rrllvm::Jit::Jit ( std::uint32_t  options)
explicit

instantiate a Jit object with some options.

Parameters
optionsLoadSBMLOptions::modelGeneratorOpt. The options are stored by bit masks and can be manipulated by either modifying LoadSBMLOptions or Config.

◆ Jit() [2/2]

rrllvm::Jit::Jit ( )

default constructor.

delegates to Jit(std::uint32_t options). The options argument is the default constructed from LoadSBMLOptions.modelGeneratorOpt. Note, that LoadSBMLOptions is influenced by the global Config.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

◆ ~Jit()

virtual rrllvm::Jit::~Jit ( )
virtualdefault

Add support for libsbml distrib functions.

similar to Jit::mapFunctionsToJitSymbols, these are declared and defined in C++. Support for distrib in libsbml must be present for these functions to be jitted, but if distrib is not available there are no adverse consequences other than no being able to simulate models that depend on libsbml distrib.

defaulted virtual destructor

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

Member Function Documentation

◆ addModule() [1/3]

virtual void rrllvm::Jit::addModule ( )
pure virtual

add the module and context which are member variables of the Jit instance to the current Jit engine.

similar to addModule(std::unique_ptr<llvm::Module> M, std::unique_ptr<llvm::LLVMContext> ctx) the references are stolen by the call to construct a ThreadSafeModule which then takes ownership of the module and context.

Implemented in rrllvm::LLJit.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

◆ addModule() [2/3]

virtual void rrllvm::Jit::addModule ( llvm::Module *  M)
pure virtual

add a module

Parameters
Mdirectly to the jit engine.

Implemented in rrllvm::LLJit.

◆ addModule() [3/3]

virtual void rrllvm::Jit::addModule ( std::unique_ptr< llvm::Module >  M,
std::unique_ptr< llvm::LLVMContext >  ctx 
)
pure virtual

add a module

Parameters
Mand Context
ctxto the current jit engine.

the parameters M and cts are unique pointers and therefore must be moved, not copied into the module. An llvm ThreadSafeModule is created internalls, which steals the references. For this reason, any code to be added to the module must happen before the call to addModule.

Implemented in rrllvm::LLJit.

◆ addObjectFile()

virtual void rrllvm::Jit::addObjectFile ( rrOwningBinary  owningObject)
pure virtual

add an in-memory representation of an object file to the current jit module.

the rrOwningBinary is a typedef'd llvm::object::OwningBinary<llvm::object::ObjectFile>

Implemented in rrllvm::LLJit.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

◆ getCompiledModelFromCache()

virtual std::unique_ptr<llvm::MemoryBuffer> rrllvm::Jit::getCompiledModelFromCache ( const std::string &  sbmlMD5)
pure virtual

lookup the sbml with the md5

Parameters
sbmlMD5in the compiled object cache. If it is there, return a memory buffer containing it (which you can turn into an object file). Returns empty (null) unique_ptr if not found.
Note
at present this only works with LLJit.

Implemented in rrllvm::LLJit.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

◆ getModuleAsString()

virtual std::string rrllvm::Jit::getModuleAsString ( std::string  sbmlMD5)
pure virtual

get a binary string representation of the current module.

This must be called after the module is added to the jit engine. Throws if string is empty.

This interface is moderate abuse of interface design – the parameter sbmlMD5 is only required for the LLJit subclass, as it is used to query the object cache created by llvm. This is of course bad design but we are boxed by not being able to find a way to enable the same cache system with the old MCJit class.

Regardless of the bad design, it works, so lets not spend any more time on it.

Implemented in rrllvm::LLJit.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

◆ getProcessTriple()

std::string rrllvm::Jit::getProcessTriple ( ) const
protected

getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the current process, e.g.

when using the JIT.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

◆ mapFunctionsToJitSymbols()

virtual void rrllvm::Jit::mapFunctionsToJitSymbols ( )
pure virtual

adds functions that are declared and defined in C++ to the jit engine.

unlike most functions that are created directly in the llvm IR language these functions are just C++ i.e. tan, arccsh, quotient. In MCJit (llvm 6) these were "mapped" to sbml support functions in addGlobalMappings.

Implemented in rrllvm::LLJit.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

◆ mapLLVMGeneratedFunctionsToSymbols()

void rrllvm::Jit::mapLLVMGeneratedFunctionsToSymbols ( ModelResources *  modelResources,
std::uint32_t  options 
)
virtual

Map the Jit'd functions that collectively represent a roadrunner compiled sbml model to symbols in the ModelResources.

Parameters
modelResourcesthe ModelResources to which to map.
optionsbitfield options to use.

this must be called after a the main roadrunner module has been added to the Jit – otherwise the lookup will fail.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

Member Data Documentation

◆ compiledModuleBinaryStream

std::unique_ptr<llvm::raw_svector_ostream> rrllvm::Jit::compiledModuleBinaryStream

MCJit compiles the generated LLVM IR to this binary stream which is then used both for adding to the Jit as a module and for saveState.

MCJit is the only Jit that uses this. (Its bad interface design but works at least.). LLJit uses a caching mechanism which allows us to retrieve object files directly, foregoing the need for this variable.

Examples
/home/vsts/work/1/s/source/llvm/Jit.h.

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