FAUST compiler  0.9.9.6b8
Public Member Functions | Public Attributes | List of all members
Loop Struct Reference

#include <loop.hh>

Collaboration diagram for Loop:
Collaboration graph
[legend]

Public Member Functions

 Loop (Tree recsymbol, Loop *encl, const string &size)
 create a recursive loop More...
 
 Loop (Loop *encl, const string &size)
 create a non recursive loop More...
 
bool isEmpty ()
 true when the loop doesn't contain any line of code More...
 
bool hasRecDependencyIn (Tree S)
 returns true is this loop or its ancestors define a symbol in S More...
 
void addPreCode (const string &str)
 add a line of C++ code pre code More...
 
void addExecCode (const string &str)
 add a line of C++ code More...
 
void addPostCode (const string &str)
 add a line of C++ post code More...
 
void println (int n, ostream &fout)
 print the loop More...
 
void printParLoopln (int n, ostream &fout)
 print the loop with a #pragma omp loop More...
 
void printoneln (int n, ostream &fout)
 print the loop in scalar mode More...
 
void absorb (Loop *l)
 absorb a loop inside this one More...
 
void concat (Loop *l)
 

Public Attributes

const bool fIsRecursive
 recursive loops can't be SIMDed More...
 
Tree fRecSymbolSet
 recursive loops define a set of recursive symbol More...
 
Loop *const fEnclosingLoop
 Loop from which this one originated. More...
 
const string fSize
 number of iterations of the loop More...
 
set< Loop * > fBackwardLoopDependencies
 Loops that must be computed before this one. More...
 
set< Loop * > fForwardLoopDependencies
 Loops that will be computed after this one. More...
 
list< string > fPreCode
 code to execute at the begin of the loop More...
 
list< string > fExecCode
 code to execute in the loop More...
 
list< string > fPostCode
 code to execute at the end of the loop More...
 
int fOrder
 used during topological sort More...
 
int fIndex
 used during scheduler mode code generation More...
 
int fUseCount
 how many loops depend on this one More...
 
list< Loop * > fExtraLoops
 extra loops that where in sequences More...
 
int fPrinted
 true when loop has been printed (to track multi-print errors) More...
 

Detailed Description

Definition at line 52 of file loop.hh.

Constructor & Destructor Documentation

Loop::Loop ( Tree  recsymbol,
Loop encl,
const string &  size 
)

create a recursive loop

Create a recursive loop.

Parameters
recsymbolthe recursive symbol defined in this loop
enclthe enclosing loop
sizethe number of iterations of the loop

Definition at line 41 of file loop.cpp.

42  : fIsRecursive(true), fRecSymbolSet(singleton(recsymbol)), fEnclosingLoop(encl), fSize(size), fOrder(-1), fIndex(-1), fUseCount(0), fPrinted(0)
43 {}
Loop *const fEnclosingLoop
Loop from which this one originated.
Definition: loop.hh:56
int fUseCount
how many loops depend on this one
Definition: loop.hh:68
const bool fIsRecursive
recursive loops can't be SIMDed
Definition: loop.hh:54
Tree fRecSymbolSet
recursive loops define a set of recursive symbol
Definition: loop.hh:55
int fPrinted
true when loop has been printed (to track multi-print errors)
Definition: loop.hh:71
Tree singleton(Tree e)
Definition: list.cpp:302
int fOrder
used during topological sort
Definition: loop.hh:65
const string fSize
number of iterations of the loop
Definition: loop.hh:57
int fIndex
used during scheduler mode code generation
Definition: loop.hh:66
Loop::Loop ( Loop encl,
const string &  size 
)

create a non recursive loop

Create a non recursive loop.

Parameters
enclthe enclosing loop
sizethe number of iterations of the loop

Definition at line 51 of file loop.cpp.

52  : fIsRecursive(false), fRecSymbolSet(nil), fEnclosingLoop(encl), fSize(size), fOrder(-1), fIndex(-1), fUseCount(0), fPrinted(0)
53 {}
Loop *const fEnclosingLoop
Loop from which this one originated.
Definition: loop.hh:56
int fUseCount
how many loops depend on this one
Definition: loop.hh:68
const bool fIsRecursive
recursive loops can't be SIMDed
Definition: loop.hh:54
Tree fRecSymbolSet
recursive loops define a set of recursive symbol
Definition: loop.hh:55
int fPrinted
true when loop has been printed (to track multi-print errors)
Definition: loop.hh:71
Tree nil
Definition: list.cpp:116
int fOrder
used during topological sort
Definition: loop.hh:65
const string fSize
number of iterations of the loop
Definition: loop.hh:57
int fIndex
used during scheduler mode code generation
Definition: loop.hh:66

Member Function Documentation

void Loop::absorb ( Loop l)

absorb a loop inside this one

Absorb a loop by copying its recursive dependencies, its loop dependencies and its lines of exec and post exec code.

Parameters
lthe Loop to be absorbed

Definition at line 113 of file loop.cpp.

References fBackwardLoopDependencies, fExecCode, fPostCode, fPreCode, fRecSymbolSet, fSize, and setUnion().

Referenced by Klass::closeLoop().

114 {
115  // the loops must have the same number of iterations
116  assert(fSize == l->fSize);
118 
119  // update loop dependencies by adding those from the absorbed loop
121 
122  // add the line of code of the absorbed loop
123  fPreCode.insert(fPreCode.end(), l->fPreCode.begin(), l->fPreCode.end());
124  fExecCode.insert(fExecCode.end(), l->fExecCode.begin(), l->fExecCode.end());
125  fPostCode.insert(fPostCode.begin(), l->fPostCode.begin(), l->fPostCode.end());
126 }
list< string > fPostCode
code to execute at the end of the loop
Definition: loop.hh:63
Tree fRecSymbolSet
recursive loops define a set of recursive symbol
Definition: loop.hh:55
list< string > fExecCode
code to execute in the loop
Definition: loop.hh:62
Tree setUnion(Tree A, Tree B)
Definition: list.cpp:317
const string fSize
number of iterations of the loop
Definition: loop.hh:57
list< string > fPreCode
code to execute at the begin of the loop
Definition: loop.hh:61
set< Loop * > fBackwardLoopDependencies
Loops that must be computed before this one.
Definition: loop.hh:59

Here is the call graph for this function:

Here is the caller graph for this function:

void Loop::addExecCode ( const string &  str)

add a line of C++ code

Add a line of exec code.

Definition at line 91 of file loop.cpp.

References fExecCode.

92 {
93  // cerr << this << "->addExecCode " << str << endl;
94  fExecCode.push_back(str);
95 }
list< string > fExecCode
code to execute in the loop
Definition: loop.hh:62
void Loop::addPostCode ( const string &  str)

add a line of C++ post code

Add a line of post exec code (end of the loop)

Definition at line 101 of file loop.cpp.

References fPostCode.

102 {
103  // cerr << this << "->addPostCode " << str << endl;
104  fPostCode.push_front(str);
105 }
list< string > fPostCode
code to execute at the end of the loop
Definition: loop.hh:63
void Loop::addPreCode ( const string &  str)

add a line of C++ code pre code

Add a line of pre code (begin of the loop)

Definition at line 82 of file loop.cpp.

References fPreCode.

83 {
84  // cerr << this << "->addExecCode " << str << endl;
85  fPreCode.push_back(str);
86 }
list< string > fPreCode
code to execute at the begin of the loop
Definition: loop.hh:61
void Loop::concat ( Loop l)

Definition at line 237 of file loop.cpp.

References fBackwardLoopDependencies, fExtraLoops, and fUseCount.

Referenced by groupSeqLoops().

238 {
239  assert(l->fUseCount == 1);
240  assert(fBackwardLoopDependencies.size() == 1);
241  assert((*fBackwardLoopDependencies.begin()) == l);
242 
243  fExtraLoops.push_front(l);
245 }
int fUseCount
how many loops depend on this one
Definition: loop.hh:68
list< Loop * > fExtraLoops
extra loops that where in sequences
Definition: loop.hh:69
set< Loop * > fBackwardLoopDependencies
Loops that must be computed before this one.
Definition: loop.hh:59

Here is the caller graph for this function:

bool Loop::hasRecDependencyIn ( Tree  S)

returns true is this loop or its ancestors define a symbol in S

A loop with recursive dependencies can't be run alone.

It must be included into another loop. returns true is this loop has recursive dependencies and must be included in an enclosing loop

Definition at line 63 of file loop.cpp.

References fEnclosingLoop, fRecSymbolSet, isNil(), and setIntersection().

Referenced by Klass::closeLoop(), and VectorCompiler::generateLoopCode().

64 {
65  Loop* l = this;
66  while ( l && isNil(setIntersection(l->fRecSymbolSet,S)) ) l=l->fEnclosingLoop;
67  return l != 0;
68 }
Loop *const fEnclosingLoop
Loop from which this one originated.
Definition: loop.hh:56
Tree setIntersection(Tree A, Tree B)
Definition: list.cpp:327
bool isNil(Tree l)
Definition: list.hh:137
Tree fRecSymbolSet
recursive loops define a set of recursive symbol
Definition: loop.hh:55
Definition: loop.hh:52

Here is the call graph for this function:

Here is the caller graph for this function:

bool Loop::isEmpty ( )

true when the loop doesn't contain any line of code

Test if a loop is empty that is if it contains no lines of code).

Returns
true if the loop is empty

Definition at line 74 of file loop.cpp.

References fExecCode, fExtraLoops, fPostCode, and fPreCode.

Referenced by Klass::closeLoop().

75 {
76  return fPreCode.empty() && fExecCode.empty() && fPostCode.empty() && (fExtraLoops.begin()==fExtraLoops.end());
77 }
list< string > fPostCode
code to execute at the end of the loop
Definition: loop.hh:63
list< string > fExecCode
code to execute in the loop
Definition: loop.hh:62
list< Loop * > fExtraLoops
extra loops that where in sequences
Definition: loop.hh:69
list< string > fPreCode
code to execute at the begin of the loop
Definition: loop.hh:61

Here is the caller graph for this function:

void Loop::println ( int  n,
ostream &  fout 
)

print the loop

Print a loop (unless it is empty)

Parameters
nnumber of tabs of indentation
foutoutput stream

Definition at line 134 of file loop.cpp.

References fExecCode, fExtraLoops, fPostCode, fPreCode, fSize, printlines(), and tab().

Referenced by Klass::printLoopDeepFirst().

135 {
136  for (list<Loop*>::const_iterator s = fExtraLoops.begin(); s != fExtraLoops.end(); s++) {
137  (*s)->println(n, fout);
138  }
139 
140  if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) {
141 /* if (gVectorSwitch) {
142  tab(n,fout);
143  fout << ((fIsRecursive) ? "// recursive loop" : "// vectorizable loop");
144  }*/
145 
146  tab(n,fout); fout << "// LOOP " << this ;
147  if (fPreCode.size()>0) {
148  tab(n,fout); fout << "// pre processing";
149  printlines(n, fPreCode, fout);
150  }
151 
152  tab(n,fout); fout << "// exec code";
153  tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {";
154  printlines(n+1, fExecCode, fout);
155  tab(n,fout); fout << "}";
156 
157  if (fPostCode.size()>0) {
158  tab(n,fout); fout << "// post processing";
159  printlines(n, fPostCode, fout);
160  }
161  tab(n,fout);
162  }
163 }
static void tab(int n, ostream &fout)
Print n tabs (for indentation purpose)
Definition: loop.cpp:13
list< string > fPostCode
code to execute at the end of the loop
Definition: loop.hh:63
list< string > fExecCode
code to execute in the loop
Definition: loop.hh:62
list< Loop * > fExtraLoops
extra loops that where in sequences
Definition: loop.hh:69
static void printlines(int n, list< string > &lines, ostream &fout)
Print a list of lines.
Definition: loop.cpp:26
const string fSize
number of iterations of the loop
Definition: loop.hh:57
list< string > fPreCode
code to execute at the begin of the loop
Definition: loop.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

void Loop::printoneln ( int  n,
ostream &  fout 
)

print the loop in scalar mode

Print a single loop (unless it is empty)

Parameters
nnumber of tabs of indentation
foutoutput stream

Definition at line 214 of file loop.cpp.

References fExecCode, fPostCode, fPreCode, fSize, printlines(), and tab().

Referenced by Klass::printLoopGraphScalar().

215 {
216  if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) {
217 /* if (gVectorSwitch) {
218  tab(n,fout);
219  fout << ((fIsRecursive) ? "// recursive loop" : "// vectorizable loop");
220  }*/
221 
222  tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {";
223  if (fPreCode.size()>0) {
224  tab(n+1,fout); fout << "// pre processing";
225  printlines(n+1, fPreCode, fout);
226  }
227  printlines(n+1, fExecCode, fout);
228  if (fPostCode.size()>0) {
229  tab(n+1,fout); fout << "// post processing";
230  printlines(n+1, fPostCode, fout);
231  }
232  tab(n,fout); fout << "}";
233  }
234 }
static void tab(int n, ostream &fout)
Print n tabs (for indentation purpose)
Definition: loop.cpp:13
list< string > fPostCode
code to execute at the end of the loop
Definition: loop.hh:63
list< string > fExecCode
code to execute in the loop
Definition: loop.hh:62
static void printlines(int n, list< string > &lines, ostream &fout)
Print a list of lines.
Definition: loop.cpp:26
const string fSize
number of iterations of the loop
Definition: loop.hh:57
list< string > fPreCode
code to execute at the begin of the loop
Definition: loop.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

void Loop::printParLoopln ( int  n,
ostream &  fout 
)

print the loop with a #pragma omp loop

Print a parallel loop (unless it is empty).

Should be called only for loop without pre and post processing

Parameters
nnumber of tabs of indentation
foutoutput stream

Definition at line 172 of file loop.cpp.

References fExecCode, fExtraLoops, fPostCode, fPreCode, fSize, printlines(), and tab().

173 {
174  for (list<Loop*>::const_iterator s = fExtraLoops.begin(); s != fExtraLoops.end(); s++) {
175  tab(n,fout); fout << "#pragma omp single";
176  tab(n,fout); fout << "{";
177  (*s)->println(n+1, fout);
178  tab(n,fout); fout << "}";
179  }
180 
181  if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) {
182 
183  tab(n,fout); fout << "// LOOP " << this ;
184  if (fPreCode.size()>0) {
185  tab(n,fout); fout << "#pragma omp single";
186  tab(n,fout); fout << "{";
187  tab(n+1,fout); fout << "// pre processing";
188  printlines(n+1, fPreCode, fout);
189  tab(n,fout); fout << "}";
190  }
191 
192  tab(n,fout); fout << "// exec code";
193  tab(n,fout); fout << "#pragma omp for";
194  tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {";
195  printlines(n+1, fExecCode, fout);
196  tab(n,fout); fout << "}";
197 
198  if (fPostCode.size()>0) {
199  tab(n,fout); fout << "#pragma omp single";
200  tab(n,fout); fout << "{";
201  tab(n+1,fout); fout << "// post processing";
202  printlines(n+1, fPostCode, fout);
203  tab(n,fout); fout << "}";
204  }
205  tab(n,fout);
206  }
207 }
static void tab(int n, ostream &fout)
Print n tabs (for indentation purpose)
Definition: loop.cpp:13
list< string > fPostCode
code to execute at the end of the loop
Definition: loop.hh:63
list< string > fExecCode
code to execute in the loop
Definition: loop.hh:62
list< Loop * > fExtraLoops
extra loops that where in sequences
Definition: loop.hh:69
static void printlines(int n, list< string > &lines, ostream &fout)
Print a list of lines.
Definition: loop.cpp:26
const string fSize
number of iterations of the loop
Definition: loop.hh:57
list< string > fPreCode
code to execute at the begin of the loop
Definition: loop.hh:61

Here is the call graph for this function:

Member Data Documentation

set<Loop*> Loop::fBackwardLoopDependencies

Loops that must be computed before this one.

Definition at line 59 of file loop.hh.

Referenced by absorb(), Klass::closeLoop(), computeUseCount(), concat(), VectorCompiler::CS(), groupSeqLoops(), Klass::printLoopDeepFirst(), and resetOrder().

Loop* const Loop::fEnclosingLoop

Loop from which this one originated.

Definition at line 56 of file loop.hh.

Referenced by Klass::closeLoop(), and hasRecDependencyIn().

list<string> Loop::fExecCode

code to execute in the loop

Definition at line 62 of file loop.hh.

Referenced by absorb(), addExecCode(), isEmpty(), println(), printoneln(), and printParLoopln().

list<Loop*> Loop::fExtraLoops

extra loops that where in sequences

Definition at line 69 of file loop.hh.

Referenced by concat(), isEmpty(), println(), and printParLoopln().

set<Loop*> Loop::fForwardLoopDependencies

Loops that will be computed after this one.

Definition at line 60 of file loop.hh.

int Loop::fIndex

used during scheduler mode code generation

Definition at line 66 of file loop.hh.

Referenced by Klass::buildTasksList(), and Klass::printOneLoopScheduler().

const bool Loop::fIsRecursive

recursive loops can't be SIMDed

Definition at line 54 of file loop.hh.

int Loop::fOrder

used during topological sort

Definition at line 65 of file loop.hh.

Referenced by Klass::printLoopDeepFirst(), resetOrder(), and setOrder().

list<string> Loop::fPostCode

code to execute at the end of the loop

Definition at line 63 of file loop.hh.

Referenced by absorb(), addPostCode(), isEmpty(), println(), printoneln(), and printParLoopln().

list<string> Loop::fPreCode

code to execute at the begin of the loop

Definition at line 61 of file loop.hh.

Referenced by absorb(), addPreCode(), isEmpty(), println(), printoneln(), and printParLoopln().

int Loop::fPrinted

true when loop has been printed (to track multi-print errors)

Definition at line 71 of file loop.hh.

Tree Loop::fRecSymbolSet

recursive loops define a set of recursive symbol

Definition at line 55 of file loop.hh.

Referenced by absorb(), Klass::closeLoop(), and hasRecDependencyIn().

const string Loop::fSize

number of iterations of the loop

Definition at line 57 of file loop.hh.

Referenced by absorb(), println(), printoneln(), and printParLoopln().

int Loop::fUseCount

how many loops depend on this one

Definition at line 68 of file loop.hh.

Referenced by computeUseCount(), concat(), and groupSeqLoops().


The documentation for this struct was generated from the following files: