Merge branch 'master' of https://scm.cri.ensmp.fr/git/Faustine
[Faustine.git] / interpretor / faust-0.9.47mr3 / compiler / headers / loop.hh
1 /************************************************************************
2 ************************************************************************
3 FAUST compiler
4 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ************************************************************************
20 ************************************************************************/
21
22
23
24 #ifndef _LOOP_H
25 #define _LOOP_H
26
27 /**********************************************************************
28 - loop.hh : loop C++ à remplir (projet FAUST) -
29
30
31 Historique :
32 -----------
33 21-01-2008 : implementation initiale (yo)
34
35 ***********************************************************************/
36 namespace std{}
37 using namespace std;
38
39 #include <string>
40 #include <list>
41 #include <stack>
42 #include <set>
43 #include <map>
44 #include "tlib.hh"
45
46 #define kMaxCategory 32
47
48 /*
49 * Loops are lines of code that correspond to a recursive expression or a vector expression.
50 */
51
52 struct Loop
53 {
54 const bool fIsRecursive; ///< recursive loops can't be SIMDed
55 Tree fRecSymbolSet; ///< recursive loops define a set of recursive symbol
56 Loop* const fEnclosingLoop; ///< Loop from which this one originated
57 const string fSize; ///< number of iterations of the loop
58 // fields concerned by absorbsion
59 set<Loop*> fBackwardLoopDependencies; ///< Loops that must be computed before this one
60 set<Loop*> fForwardLoopDependencies; ///< Loops that will be computed after this one
61 list<string> fPreCode; ///< code to execute at the begin of the loop
62 list<string> fExecCode; ///< code to execute in the loop
63 list<string> fPostCode; ///< code to execute at the end of the loop
64 // for topological sort
65 int fOrder; ///< used during topological sort
66 int fIndex; ///< used during scheduler mode code generation
67 // new fields
68 int fUseCount; ///< how many loops depend on this one
69 list<Loop*> fExtraLoops; ///< extra loops that where in sequences
70
71 int fPrinted; ///< true when loop has been printed (to track multi-print errors)
72
73 public:
74 Loop(Tree recsymbol, Loop* encl, const string& size); ///< create a recursive loop
75 Loop(Loop* encl, const string& size); ///< create a non recursive loop
76
77 bool isEmpty(); ///< true when the loop doesn't contain any line of code
78 bool hasRecDependencyIn(Tree S); ///< returns true is this loop or its ancestors define a symbol in S
79
80 void addPreCode (const string& str); ///< add a line of C++ code pre code
81 void addExecCode (const string& str); ///< add a line of C++ code
82 void addPostCode (const string& str); ///< add a line of C++ post code
83 void println (int n, ostream& fout); ///< print the loop
84 void printParLoopln(int n, ostream& fout); ///< print the loop with a #pragma omp loop
85
86 void printoneln (int n, ostream& fout); ///< print the loop in scalar mode
87
88 void absorb(Loop* l); ///< absorb a loop inside this one
89 // new method
90 void concat(Loop* l);
91 };
92
93 #endif