roadrunner  2.6.0
Fast simulator for SBML models
LoadSymbolResolverBase.h
1 /*
2  * LoadSymbolResolverBase.h
3  *
4  * Created on: May 15, 2014
5  * Author: andy
6  */
7 
8 #ifndef LOADSYMBOLRESOLVERBASE_H_
9 #define LOADSYMBOLRESOLVERBASE_H_
10 
11 #include "CodeGen.h"
12 #include "LLVMIncludes.h"
13 #include "LLVMModelDataSymbols.h"
14 #include "LLVMModelSymbols.h"
15 #include "ModelGeneratorContext.h"
16 
17 #include <rr_unordered_map>
18 
19 namespace libsbml
20 {
21 class Model;
22 }
23 
24 namespace rrllvm
25 {
26 
34 {
35 public:
40  llvm::Value* loadReactionRate(const libsbml::Reaction*);
41 
42  void recursiveSymbolPush(const std::string& symbol) override;
43 
44  void recursiveSymbolPop() override;
45 
46  virtual bool isLocalParameter(const std::string& symbol) override;
47 
52  void flushCache();
53 
59  size_t pushCacheBlock() override;
60 
67  size_t popCacheBlock() override;
68 
69 
70 protected:
71  LoadSymbolResolverBase(const ModelGeneratorContext &ctx, llvm::Value *modelData);
72 
73  typedef std::list<std::string> StringStack;
74  typedef std::unordered_map<std::string, llvm::Value*> ValueMap;
75  typedef std::deque<ValueMap> ValueMapStack;
76 
77  const ModelGeneratorContext &modelGenContext;
78  const libsbml::Model *model;
79  const LLVMModelDataSymbols &modelDataSymbols;
80  const LLVMModelSymbols &modelSymbols;
81  llvm::IRBuilder<> &builder;
82  llvm::Value *modelData;
83 
84  // check for recursive symbol definitions in rule evaluations
85  StringStack symbolStack;
86 
87  // cache symbols
88  ValueMapStack symbolCache;
89 
97  llvm::Value* cacheValue(const std::string& symbol,
98  const llvm::ArrayRef<llvm::Value*>& args,
99  llvm::Value* value = nullptr);
100 };
101 
102 
103 } /* namespace rrllvm */
104 
105 #endif /* LOADSYMBOLRESOLVERBASE_H_ */
stores the names of all the symbols in the sbml model and thier indexes in the ModelData arrays.
Definition: LLVMModelDataSymbols.h:128
Hold all the un-evaluated symbolic inforamtion in the model.
Definition: LLVMModelSymbols.h:26
provide common sbml model functionality to three kinds of resolvers.
Definition: LoadSymbolResolverBase.h:34
llvm::Value * cacheValue(const std::string &symbol, const llvm::ArrayRef< llvm::Value * > &args, llvm::Value *value=nullptr)
check in the symbol cache if the symbol exists, if so return it.
Definition: LoadSymbolResolverBase.cpp:111
size_t pushCacheBlock() override
nested conditionals (or functions?) can push a local cache block, where symbols would be chached.
Definition: LoadSymbolResolverBase.cpp:96
void flushCache()
Flush the symbol cache.
Definition: LoadSymbolResolverBase.cpp:90
llvm::Value * loadReactionRate(const libsbml::Reaction *)
shortcut to get a reaction rate, performance wise, quicker than going through all the loadSymbolValue...
Definition: LoadSymbolResolverBase.cpp:39
size_t popCacheBlock() override
Pop a scoped cache block, this clears these values, and any subsequent reads re-evaluate the requeste...
Definition: LoadSymbolResolverBase.cpp:102
LLVM load instruction class.
Definition: CodeGen.h:37
All LLVM code generating objects basically need at a minimum three things to operate:
Definition: ModelGeneratorContext.h:95