Skip to content

Commit

Permalink
Create mechanism instance struct in LLVM IR (#507)
Browse files Browse the repository at this point in the history
* Moved info related function to codegen_info
  - Moved get_float_variables, codegen_int_variables,
     codegen_global_variables, codegen_shadow_variables
     into CodegenHelper
  - Move small utility functions from CodegenCVisitor to codeged_utils
* Add proper variables to the mech_Instance
* Adding LLVMStructBlock
* Added test and visitor
* Fix llvm codegen tests with x[0-9].*
  • Loading branch information
iomaganaris authored and pramodk committed May 8, 2021
1 parent a32f76b commit bfaff72
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 396 deletions.
292 changes: 33 additions & 259 deletions src/codegen/codegen_c_visitor.cpp

Large diffs are not rendered by default.

123 changes: 0 additions & 123 deletions src/codegen/codegen_c_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,6 @@ enum class MemberType {
thread
};


/**
* \class IndexVariableInfo
* \brief Helper to represent information about index/int variables
*
*/
struct IndexVariableInfo {
/// symbol for the variable
const std::shared_ptr<symtab::Symbol> symbol;

/// if variable reside in vdata field of NrnThread
/// typically true for bbcore pointer
bool is_vdata = false;

/// if this is pure index (e.g. style_ion) variables is directly
/// index and shouldn't be printed with data/vdata
bool is_index = false;

/// if this is an integer (e.g. tqitem, point_process) variable which
/// is printed as array accesses
bool is_integer = false;

/// if the variable is qualified as constant (this is property of IndexVariable)
bool is_constant = false;

IndexVariableInfo(std::shared_ptr<symtab::Symbol> symbol,
bool is_vdata = false,
bool is_index = false,
bool is_integer = false)
: symbol(std::move(symbol))
, is_vdata(is_vdata)
, is_index(is_index)
, is_integer(is_integer) {}
};

/** @} */ // end of codegen_details


Expand Down Expand Up @@ -163,11 +128,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
*/
symtab::SymbolTable* program_symtab = nullptr;

/**
* All float variables for the model
*/
std::vector<SymbolType> codegen_float_variables;

/**
* All int variables for the model
*/
Expand Down Expand Up @@ -356,26 +316,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
}


/**
* Constructs a shadow variable name
* \param name The name of the variable
* \return The name of the variable prefixed with \c shadow_
*/
std::string shadow_varname(const std::string& name) const {
return "shadow_" + name;
}


/**
* Creates a temporary symbol
* \param name The name of the symbol
* \return A symbol based on the given name
*/
SymbolType make_symbol(const std::string& name) const {
return std::make_shared<symtab::Symbol>(name, ModToken());
}


/**
* Checks if the given variable name belongs to a state variable
* \param name The variable name
Expand All @@ -384,55 +324,13 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
bool state_variable(const std::string& name) const;


/**
* Check if net receive/send buffering kernels required
*/
bool net_receive_buffering_required() const noexcept;


/**
* Check if nrn_state function is required
*/
bool nrn_state_required() const noexcept;


/**
* Check if nrn_cur function is required
*/
bool nrn_cur_required() const noexcept;


/**
* Check if net_receive function is required
*/
bool net_receive_required() const noexcept;


/**
* Check if net_send_buffer is required
*/
bool net_send_buffer_required() const noexcept;


/**
* Check if setup_range_variable function is required
* \return
*/
bool range_variable_setup_required() const noexcept;


/**
* Check if net_receive node exist
*/
bool net_receive_exist() const noexcept;


/**
* Check if breakpoint node exist
*/
bool breakpoint_exist() const noexcept;


/**
* Check if given method is defined in this model
* \param name The name of the method to check
Expand Down Expand Up @@ -598,27 +496,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
void update_index_semantics();


/**
* Determine all \c float variables required during code generation
* \return A \c vector of \c float variables
*/
std::vector<SymbolType> get_float_variables();


/**
* Determine all \c int variables required during code generation
* \return A \c vector of \c int variables
*/
std::vector<IndexVariableInfo> get_int_variables();


/**
* Determine all ion write variables that require shadow vectors during code generation
* \return A \c vector of ion variables
*/
std::vector<SymbolType> get_shadow_variables();


/**
* Print the items in a vector as a list
*
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/codegen_helper_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using namespace ast;
using symtab::syminfo::NmodlType;
using symtab::syminfo::Status;


/**
* How symbols are stored in NEURON? See notes written in markdown file.
*
Expand Down Expand Up @@ -273,6 +274,7 @@ void CodegenHelperVisitor::find_non_range_variables() {
// clang-format on
}


/**
* Find range variables i.e. ones that are belong to per instance allocation
*
Expand Down Expand Up @@ -664,6 +666,9 @@ void CodegenHelperVisitor::visit_program(const ast::Program& node) {
find_range_variables();
find_non_range_variables();
find_table_variables();
info.get_int_variables();
info.get_shadow_variables();
info.get_float_variables();
}


Expand Down
10 changes: 10 additions & 0 deletions src/codegen/codegen_helper_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ class CodegenHelperVisitor: public visitor::ConstAstVisitor {
void find_non_range_variables();
void sort_with_mod2c_symbol_order(std::vector<SymbolType>& symbols) const;

/**
* Check if breakpoint node exist
*/
bool breakpoint_exist() const noexcept;

/**
* Check if net_receive node exist
*/
bool net_receive_exist() const noexcept;

public:
CodegenHelperVisitor() = default;

Expand Down
Loading

0 comments on commit bfaff72

Please sign in to comment.