roadrunner  2.6.0
Fast simulator for SBML models
ModelDataIRBuilder.h
1 /*
2  * ModelDataIRBuilder.h
3  *
4  * Created on: Jun 28, 2013
5  *
6  * Author: Andy Somogyi,
7  * email decode: V1 = "."; V2 = "@"; V3 = V1;
8  * andy V1 somogyi V2 gmail V3 com
9  */
10 
11 #ifndef ModelDataIRBuilderH
12 #define ModelDataIRBuilderH
13 
14 #include "LLVMIncludes.h"
15 #include "LLVMModelDataSymbols.h"
16 
17 #include <map>
18 #include <llvm/IR/DataLayout.h>
19 
20 namespace libsbml
21 {
22 class Model;
23 }
24 
25 namespace rrllvm
26 {
32  {
33  public:
34 
38  ModelDataIRBuilder(llvm::Value* modelData, LLVMModelDataSymbols const&, llvm::IRBuilder<>&);
39 
40  llvm::Value* createFloatSpeciesAmtGEP(const std::string& id,
41  const llvm::Twine& name = "");
42 
43  llvm::Value* createBoundSpeciesAmtGEP(const std::string& id,
44  const llvm::Twine& name = "");
45 
46  llvm::Value* createGlobalParamGEP(const std::string& id);
47 
53  llvm::Value* createGEP(ModelDataFields field);
54 
59  llvm::Value* createGEP(ModelDataFields field, unsigned index,
60  const llvm::Twine& name = "");
61 
62  llvm::Value* createLoad(ModelDataFields field, unsigned index,
63  const llvm::Twine& name = "");
64 
65  llvm::Value* createStore(ModelDataFields field, unsigned index,
66  llvm::Value* value, const llvm::Twine& name = "");
67 
71  llvm::Value* createCompGEP(const std::string& id);
72 
76  llvm::Value* createCompLoad(const std::string& id,
77  const llvm::Twine& name = "");
78 
82  llvm::Value* createCompStore(const std::string& id,
83  llvm::Value* value);
84 
88  llvm::Value* createInitFloatSpeciesAmtGEP(const std::string& id,
89  const llvm::Twine& name = "");
90 
94  llvm::Value* createInitBoundarySpeciesAmtGEP(const std::string& id,
95  const llvm::Twine& name = "");
96 
100  llvm::Value* createInitFloatSpeciesAmtLoad(const std::string& id,
101  const llvm::Twine& name = "");
102 
106  llvm::Value* createInitBoundarySpeciesAmtLoad(const std::string& id,
107  const llvm::Twine& name = "");
108 
112  llvm::Value* createInitFloatSpeciesAmtStore(const std::string& id,
113  llvm::Value* value);
114 
118  llvm::Value* createInitBoundarySpeciesAmtStore(const std::string& id,
119  llvm::Value* value);
120 
124  llvm::Value* createInitCompGEP(const std::string& id,
125  const llvm::Twine& name = "");
126 
130  llvm::Value* createInitCompLoad(const std::string& id,
131  const llvm::Twine& name = "");
132 
136  llvm::Value* createInitCompStore(const std::string& id,
137  llvm::Value* value);
138 
139 
143  llvm::Value* createInitGlobalParamGEP(const std::string& id,
144  const llvm::Twine& name = "");
145 
149  llvm::Value* createInitGlobalParamLoad(const std::string& id,
150  const llvm::Twine& name = "");
151 
155  llvm::Value* createInitGlobalParamStore(const std::string& id,
156  llvm::Value* value);
157 
161  llvm::Value* createGlobalParamLoad(const std::string& id,
162  const llvm::Twine& name = "");
163 
167  llvm::Value* createGlobalParamStore(const std::string& id,
168  llvm::Value* value);
169 
173  llvm::Value* createFloatSpeciesAmtLoad(const std::string& id,
174  const llvm::Twine& name = "");
175 
179  llvm::Value* createFloatSpeciesAmtStore(const std::string& id,
180  llvm::Value* value);
181 
185  llvm::Value* createFloatSpeciesAmtRateGEP(const std::string& id,
186  const llvm::Twine& name = "");
187 
191  llvm::Value* createFloatSpeciesAmtRateLoad(const std::string& id,
192  const llvm::Twine& name = "");
193 
197  llvm::Value* createFloatSpeciesAmtRateStore(const std::string& id,
198  llvm::Value* value);
199 
203  llvm::Value* createBoundSpeciesAmtLoad(const std::string& id,
204  const llvm::Twine& name = "");
205 
209  llvm::Value* createBoundSpeciesAmtStore(const std::string& id,
210  llvm::Value* value);
211 
215  llvm::Value* createReactionRateLoad(const std::string& id,
216  const llvm::Twine& name = "");
217 
221  llvm::Value* createReactionRateStore(const std::string& id,
222  llvm::Value* value);
223 
227  llvm::Value* createRateRuleValueGEP(const std::string& id,
228  const llvm::Twine& name = "");
229 
233  llvm::Value* createRateRuleValueLoad(const std::string& id,
234  const llvm::Twine& name = "");
235 
239  llvm::Value* createRateRuleValueStore(const std::string& id,
240  llvm::Value* value);
241 
245  llvm::Value* createRateRuleRateGEP(const std::string& id,
246  const llvm::Twine& name = "");
247 
251  llvm::Value* createRateRuleRateLoad(const std::string& id,
252  const llvm::Twine& name = "");
253 
257  llvm::Value* createRateRuleRateStore(const std::string& id,
258  llvm::Value* value);
259 
260  llvm::Value* createStoichiometryStore(uint row, uint col,
261  llvm::Value* value, const llvm::Twine& name = "");
262 
263  llvm::Value* createStoichiometryLoad(uint row, uint col,
264  const llvm::Twine& name = "");
265 
269  llvm::Value* createRandomLoad();
270 
276  static llvm::CallInst* createCSRMatrixSetNZ(llvm::IRBuilder<>&,
277  llvm::Value* csrPtr, llvm::Value* row, llvm::Value* col,
278  llvm::Value* value, const llvm::Twine& name = "");
279 
285  static llvm::CallInst* createCSRMatrixGetNZ(llvm::IRBuilder<>&,
286  llvm::Value* csrPtr, llvm::Value* row, llvm::Value* col,
287  const llvm::Twine& name = "");
288 
294  static llvm::Function* getCSRMatrixSetNZDecl(llvm::Module* module);
295 
301  static llvm::Function* getCSRMatrixGetNZDecl(llvm::Module* module);
302 
308  static llvm::StructType* getCSRSparseStructType(llvm::Module* module,
309  llvm::ExecutionEngine* engine = 0);
310 
317  static llvm::StructType* createModelDataStructType(llvm::Module* module,
318  llvm::ExecutionEngine* engine, LLVMModelDataSymbols const& symbols);
319 
327  static llvm::StructType* getStructType(llvm::Module* module);
328 
329  static unsigned getModelDataSize(llvm::Module* module, const llvm::DataLayout& dl);
330 
331  static const char* LLVMModelDataName;
332  static const char* csr_matrixName;
333  static const char* csr_matrix_set_nzName;
334  static const char* csr_matrix_get_nzName;
335 
336  private:
340  llvm::Value* modelData;
341 
342  llvm::IRBuilder<>& builder;
343 
344  LLVMModelDataSymbols const& symbols;
345 
355  static llvm::Module* getModule(llvm::IRBuilder<>& builder, const char* func);
356 
361  void validateStruct(llvm::Value* s, const char* funcName);
362 
363  friend class LLVMModelDataIRBuilderTesting;
364  };
365 
370  {
371  public:
372 
374  llvm::IRBuilder<>&);
375 
376 
378  void createAccessors(llvm::Module* module);
379 
380  std::pair<llvm::Function*, llvm::Function*> createFloatingSpeciesAccessors(
381  llvm::Module* module, const std::string id);
382 
383 
384  static llvm::Function* getDispIntDecl(llvm::Module* module);
385  llvm::CallInst* createDispInt(llvm::Value* intVal);
386 
387  static llvm::Function* getDispDoubleDecl(llvm::Module* module);
388  llvm::CallInst* createDispDouble(llvm::Value* doubleVal);
389 
390  static llvm::Function* getDispCharDecl(llvm::Module* module);
391  llvm::CallInst* createDispChar(llvm::Value* doubleVal);
392 
393 
396  llvm::IRBuilder<>& builder;
397 
398  LLVMModelDataSymbols const& symbols;
399  };
400 
401 } /* namespace rr */
402 #endif /* ModelDataIRBuilderH */
testing class
Definition: ModelDataIRBuilder.h:370
stores the names of all the symbols in the sbml model and thier indexes in the ModelData arrays.
Definition: LLVMModelDataSymbols.h:128
The model data IR builder.
Definition: ModelDataIRBuilder.h:32
llvm::Value * createInitCompStore(const std::string &id, llvm::Value *value)
store the compartment value
Definition: ModelDataIRBuilder.cpp:531
llvm::Value * createFloatSpeciesAmtStore(const std::string &id, llvm::Value *value)
store the floating species amount
Definition: ModelDataIRBuilder.cpp:285
llvm::Value * createGEP(ModelDataFields field, unsigned index, const llvm::Twine &name="")
create a GEP for an array which belongs to the ModelData struct, only valid for arrays,...
llvm::Value * createInitFloatSpeciesAmtGEP(const std::string &id, const llvm::Twine &name="")
the GEP for a floating species initial amount
Definition: ModelDataIRBuilder.cpp:466
static llvm::StructType * getStructType(llvm::Module *module)
get the ModelData struct type.
Definition: ModelDataIRBuilder.cpp:731
llvm::Value * createCompGEP(const std::string &id)
the GEP for a compartment
Definition: ModelDataIRBuilder.cpp:418
llvm::Value * createInitBoundarySpeciesAmtLoad(const std::string &id, const llvm::Twine &name="")
load the boundary species initial amount value
Definition: ModelDataIRBuilder.cpp:493
llvm::Value * createRateRuleValueLoad(const std::string &id, const llvm::Twine &name="")
load the rate rule value
Definition: ModelDataIRBuilder.cpp:357
llvm::Value * createBoundSpeciesAmtLoad(const std::string &id, const llvm::Twine &name="")
load the floating species amount value
Definition: ModelDataIRBuilder.cpp:426
llvm::Value * createInitGlobalParamLoad(const std::string &id, const llvm::Twine &name="")
load the init global param value
Definition: ModelDataIRBuilder.cpp:548
llvm::Value * createInitFloatSpeciesAmtStore(const std::string &id, llvm::Value *value)
store the floating species initial value
Definition: ModelDataIRBuilder.cpp:500
static llvm::StructType * getCSRSparseStructType(llvm::Module *module, llvm::ExecutionEngine *engine=0)
get the struct type for the CSR sparse storage struct.
Definition: ModelDataIRBuilder.cpp:168
llvm::Value * createRateRuleRateStore(const std::string &id, llvm::Value *value)
store the rate rule rate
Definition: ModelDataIRBuilder.cpp:390
static llvm::Function * getCSRMatrixGetNZDecl(llvm::Module *module)
get the function declaration (prototype) for the csr_matrix_set_nz function.
Definition: ModelDataIRBuilder.cpp:237
llvm::Value * createInitCompLoad(const std::string &id, const llvm::Twine &name="")
load the compartment value
Definition: ModelDataIRBuilder.cpp:524
llvm::Value * createInitCompGEP(const std::string &id, const llvm::Twine &name="")
the GEP for a compartment
Definition: ModelDataIRBuilder.cpp:514
llvm::Value * createInitGlobalParamStore(const std::string &id, llvm::Value *value)
store the init global param value
Definition: ModelDataIRBuilder.cpp:555
llvm::Value * createFloatSpeciesAmtRateStore(const std::string &id, llvm::Value *value)
store the floating species amount
Definition: ModelDataIRBuilder.cpp:309
llvm::Value * createRateRuleValueStore(const std::string &id, llvm::Value *value)
store the rate rule value
Definition: ModelDataIRBuilder.cpp:365
llvm::Value * createRateRuleValueGEP(const std::string &id, const llvm::Twine &name="")
rate rule GEP
Definition: ModelDataIRBuilder.cpp:347
llvm::Value * createCompStore(const std::string &id, llvm::Value *value)
store the compartment value
Definition: ModelDataIRBuilder.cpp:411
static llvm::Function * getCSRMatrixSetNZDecl(llvm::Module *module)
get the function declaration (prototype) for the csr_matrix_set_nz function.
Definition: ModelDataIRBuilder.cpp:215
llvm::Value * createInitBoundarySpeciesAmtStore(const std::string &id, llvm::Value *value)
store the boundary species initial value
Definition: ModelDataIRBuilder.cpp:507
llvm::Value * createGEP(ModelDataFields field)
create a GEP for a ModelData structure field.
Definition: ModelDataIRBuilder.cpp:116
llvm::Value * createBoundSpeciesAmtStore(const std::string &id, llvm::Value *value)
store the floating species amount
Definition: ModelDataIRBuilder.cpp:433
llvm::Value * createInitBoundarySpeciesAmtGEP(const std::string &id, const llvm::Twine &name="")
the GEP for a boundary species initial amount
Definition: ModelDataIRBuilder.cpp:476
ModelDataIRBuilder(llvm::Value *modelData, LLVMModelDataSymbols const &, llvm::IRBuilder<> &)
these only make sense attached to a modelData pointer.
Definition: ModelDataIRBuilder.cpp:95
llvm::Value * createCompLoad(const std::string &id, const llvm::Twine &name="")
load the compartment value
Definition: ModelDataIRBuilder.cpp:404
llvm::Value * createReactionRateLoad(const std::string &id, const llvm::Twine &name="")
load the floating species amount value
Definition: ModelDataIRBuilder.cpp:562
static llvm::CallInst * createCSRMatrixGetNZ(llvm::IRBuilder<> &, llvm::Value *csrPtr, llvm::Value *row, llvm::Value *col, const llvm::Twine &name="")
create a call to the csr_matrix_get_nz function.
Definition: ModelDataIRBuilder.cpp:331
static llvm::StructType * createModelDataStructType(llvm::Module *module, llvm::ExecutionEngine *engine, LLVMModelDataSymbols const &symbols)
Creates a ModelData struct for the given sbml symbols in the llvm Module.
Definition: ModelDataIRBuilder.cpp:631
llvm::Value * createFloatSpeciesAmtLoad(const std::string &id, const llvm::Twine &name="")
load the floating species amount value
Definition: ModelDataIRBuilder.cpp:278
llvm::Value * createInitFloatSpeciesAmtLoad(const std::string &id, const llvm::Twine &name="")
load the floating species initial amount value
Definition: ModelDataIRBuilder.cpp:486
llvm::Value * createFloatSpeciesAmtRateLoad(const std::string &id, const llvm::Twine &name="")
load the floating species amount value
Definition: ModelDataIRBuilder.cpp:302
llvm::Value * createRandomLoad()
pointer to ModelData::random field.
Definition: ModelDataIRBuilder.cpp:598
llvm::Value * createInitGlobalParamGEP(const std::string &id, const llvm::Twine &name="")
the GEP for a init global params
Definition: ModelDataIRBuilder.cpp:538
llvm::Value * createRateRuleRateLoad(const std::string &id, const llvm::Twine &name="")
load the rate rule rate
Definition: ModelDataIRBuilder.cpp:382
llvm::Value * createReactionRateStore(const std::string &id, llvm::Value *value)
store the floating species amount
Definition: ModelDataIRBuilder.cpp:569
llvm::Value * createRateRuleRateGEP(const std::string &id, const llvm::Twine &name="")
rate rule GEP
Definition: ModelDataIRBuilder.cpp:372
llvm::Value * createGlobalParamStore(const std::string &id, llvm::Value *value)
store the global param value
Definition: ModelDataIRBuilder.cpp:458
static llvm::CallInst * createCSRMatrixSetNZ(llvm::IRBuilder<> &, llvm::Value *csrPtr, llvm::Value *row, llvm::Value *col, llvm::Value *value, const llvm::Twine &name="")
create a call to the csr_matrix_set_nz function.
Definition: ModelDataIRBuilder.cpp:258
llvm::Value * createFloatSpeciesAmtRateGEP(const std::string &id, const llvm::Twine &name="")
the GEP for the amount rates
Definition: ModelDataIRBuilder.cpp:292
llvm::Value * createGlobalParamLoad(const std::string &id, const llvm::Twine &name="")
load the global param value
Definition: ModelDataIRBuilder.cpp:449