User Guide
loop_unroll_visitor.hpp
Go to the documentation of this file.
1
/*
2
* Copyright 2023 Blue Brain Project, EPFL.
3
* See the top-level LICENSE file for details.
4
*
5
* SPDX-License-Identifier: Apache-2.0
6
*/
7
8
#pragma once
9
10
/**
11
* \file
12
* \brief \copybrief nmodl::visitor::LoopUnrollVisitor
13
*/
14
15
#include <string>
16
17
#include "
visitors/ast_visitor.hpp
"
18
19
namespace
nmodl
{
20
namespace
visitor {
21
22
/**
23
* \addtogroup visitor_classes
24
* \{
25
*/
26
27
/**
28
* \class LoopUnrollVisitor
29
* \brief Unroll for loop in the AST
30
*
31
* Derivative and kinetic blocks have for loop with coupled set of ODEs :
32
*
33
* \code{.mod}
34
* DEFINE NANN 4
35
* KINETIC state {
36
* FROM i=0 TO NANN-2 {
37
* ~ ca[i] <-> ca[i+1] (DFree*frat[i+1]*1(um), DFree*frat[i+1]*1(um))
38
* }
39
* }
40
* \endcode
41
*
42
* To solve these ODEs with SymPy, we need to get all ODEs from such loops.
43
* This visitor unroll such loops and insert new expression statement in
44
* the AST :
45
*
46
* \code{.mod}
47
* KINETIC state {
48
* {
49
* ~ ca[0] <-> ca[0+1] (DFree*frat[0+1]*1(um), DFree*frat[0+1]*1(um))
50
* ~ ca[1] <-> ca[1+1] (DFree*frat[1+1]*1(um), DFree*frat[1+1]*1(um))
51
* ~ ca[2] <-> ca[2+1] (DFree*frat[2+1]*1(um), DFree*frat[2+1]*1(um))
52
* }
53
* }
54
* \endcode
55
*
56
* Note that the index `0+1` is not expanded to `1` because we do not run
57
* constant folder pass within this loop (but could be easily done).
58
*/
59
class
LoopUnrollVisitor
:
public
AstVisitor
{
60
public
:
61
LoopUnrollVisitor
() =
default
;
62
63
void
visit_statement_block
(
ast::StatementBlock
& node)
override
;
64
};
65
66
/** \} */
// end of visitor_classes
67
68
}
// namespace visitor
69
}
// namespace nmodl
nmodl
encapsulates code generation backend implementations
Definition:
ast_common.hpp:26
nmodl::visitor::LoopUnrollVisitor::visit_statement_block
void visit_statement_block(ast::StatementBlock &node) override
Parse verbatim blocks and rename variable if it is used.
Definition:
loop_unroll_visitor.cpp:80
nmodl::visitor::LoopUnrollVisitor
Unroll for loop in the AST.
Definition:
loop_unroll_visitor.hpp:59
nmodl::visitor::AstVisitor
Concrete visitor for all AST classes.
Definition:
ast_visitor.hpp:37
nmodl::visitor::LoopUnrollVisitor::LoopUnrollVisitor
LoopUnrollVisitor()=default
nmodl::ast::StatementBlock
Represents block encapsulating list of statements.
Definition:
statement_block.hpp:53
ast_visitor.hpp
Concrete visitor for all AST classes.
src
visitors
loop_unroll_visitor.hpp