roadrunner  2.6.0
Fast simulator for SBML models
Public Member Functions | Friends | List of all members
rrllvm::LLJit Class Reference

Thin layer around the llvm::orc::LLJit. More...

#include <LLJit.h>

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

Public Member Functions

std::string mangleName (const std::string &unmangledName) const override
 
 LLJit (std::uint32_t options)
 
void mapFunctionsToJitSymbols () override
 adds functions that are declared and defined in C++ to the jit engine. More...
 
std::uint64_t lookupFunctionAddress (const std::string &name) override
 
void addObjectFile (rrOwningBinary owningObject) override
 add an in-memory representation of an object file to the current jit module. More...
 
const llvm::DataLayout & getDataLayout () const override
 get the DataLayout currently in use in the Jit
 
void addModule (llvm::Module *M) override
 add a module More...
 
void addModule () override
 add the module and context which are member variables of the Jit instance to the current Jit engine. More...
 
void addObjectFile (std::unique_ptr< llvm::MemoryBuffer > obj) override
 add an in-memory representation of an object file to the current jit module.
 
void addObjectFile (std::unique_ptr< llvm::object::ObjectFile > objectFile) override
 add an in-memory representation of an object file to the current jit module.
 
void addModule (llvm::orc::ThreadSafeModule tsm)
 
void addModule (std::unique_ptr< llvm::Module > M, std::unique_ptr< llvm::LLVMContext > ctx) override
 add a module More...
 
std::unique_ptr< llvm::MemoryBuffer > getCompiledModelFromCache (const std::string &sbmlMD5) override
 lookup a model in the roadrunner object cache and return a memory buffer to it. More...
 
llvm::orc::LLJIT * getLLJitNonOwning ()
 
void addIRModule ()
 
std::string dump ()
 prints the symbol tables currently in the jit.
 
std::string getModuleAsString (std::string sbmlMD5) override
 get a binary string representation of the current module. More...
 
- Public Member Functions inherited from rrllvm::Jit
 Jit (std::uint32_t options)
 instantiate a Jit object with some options. More...
 
 Jit ()
 default constructor. More...
 
virtual ~Jit ()=default
 Add support for libsbml distrib functions. 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)
 

Friends

std::ostream & operator<< (std::ostream &os, LLJit *llJit)
 

Additional Inherited Members

- Public Attributes inherited from rrllvm::Jit
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 inherited from rrllvm::Jit
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 inherited from rrllvm::Jit
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

Thin layer around the llvm::orc::LLJit.

The interface for LLJit is used as a framework

Constructor & Destructor Documentation

◆ LLJit()

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

Create a JTMB.

This is moved into the LLJitBuilder and becomes harder to access, so pull out things which we need later on and store them as member variables.

None, Less, Default or Aggressive are the options.

todo expose as option to user

Set a custom compile function that 1) caches objects and 2) stores a pointer to the targetMachine for access later. The targetMachine pointer is owned by the JITTargetMachineBuilder.

Member Function Documentation

◆ addModule() [1/3]

void rrllvm::LLJit::addModule ( )
overridevirtual

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.

Implements rrllvm::Jit.

◆ addModule() [2/3]

void rrllvm::LLJit::addModule ( llvm::Module *  M)
overridevirtual

add a module

Parameters
Mdirectly to the jit engine.

Implements rrllvm::Jit.

◆ addModule() [3/3]

void rrllvm::LLJit::addModule ( std::unique_ptr< llvm::Module >  M,
std::unique_ptr< llvm::LLVMContext >  ctx 
)
overridevirtual

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.

Implements rrllvm::Jit.

◆ addObjectFile()

void rrllvm::LLJit::addObjectFile ( rrOwningBinary  owningObject)
overridevirtual

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>

Implements rrllvm::Jit.

◆ getCompiledModelFromCache()

std::unique_ptr< llvm::MemoryBuffer > rrllvm::LLJit::getCompiledModelFromCache ( const std::string &  sbmlMD5)
overridevirtual

lookup a model in the roadrunner object cache and return a memory buffer to it.

When compiled (with LLJit), object files are stored in the SBMLModelObjectCache. This is basically a string to MemoryBuffer map, where the string is the sbml's md5. In the case where the moiety conservation is turned on, the sbmlMD5 will be identical. Therefore it is appended with the string "_conserved".

Implements rrllvm::Jit.

◆ getModuleAsString()

std::string rrllvm::LLJit::getModuleAsString ( std::string  sbmlMD5)
overridevirtual

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.

Implements rrllvm::Jit.

◆ mapFunctionsToJitSymbols()

void rrllvm::LLJit::mapFunctionsToJitSymbols ( )
overridevirtual

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.

A note on name mangling. LLVM docs, tutorials and examples all use name mangling for function names. We can do this here by using the mangleName functor and then pass this as input to Function::Create (3rd arg). However, if we want to do this, we need to mangle the names at the time these functions are needed (ASTNodeCodeGen), or we wont be able to locate them. This is easily doable but currently I don't see much point, as we're not likely to have many name clashes.

Implements rrllvm::Jit.


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