|
FAUST compiler
0.9.9.6b8
|
#include <loop.hh>

Public Member Functions | |
| Loop (Tree recsymbol, Loop *encl, const string &size) | |
| create a recursive loop | |
| Loop (Loop *encl, const string &size) | |
| create a non recursive loop | |
| bool | isEmpty () |
| true when the loop doesn't contain any line of code | |
| bool | hasRecDependencyIn (Tree S) |
| returns true is this loop or its ancestors define a symbol in S | |
| void | addPreCode (const string &str) |
| add a line of C++ code pre code | |
| void | addExecCode (const string &str) |
| add a line of C++ code | |
| void | addPostCode (const string &str) |
| add a line of C++ post code | |
| void | println (int n, ostream &fout) |
| print the loop | |
| void | printParLoopln (int n, ostream &fout) |
| print the loop with a #pragma omp loop | |
| void | printoneln (int n, ostream &fout) |
| print the loop in scalar mode | |
| void | absorb (Loop *l) |
| absorb a loop inside this one | |
| void | concat (Loop *l) |
Public Attributes | |
| const bool | fIsRecursive |
| recursive loops can't be SIMDed | |
| Tree | fRecSymbolSet |
| recursive loops define a set of recursive symbol | |
| Loop *const | fEnclosingLoop |
| Loop from which this one originated. | |
| const string | fSize |
| number of iterations of the loop | |
| set< Loop * > | fBackwardLoopDependencies |
| Loops that must be computed before this one. | |
| set< Loop * > | fForwardLoopDependencies |
| Loops that will be computed after this one. | |
| list< string > | fPreCode |
| code to execute at the begin of the loop | |
| list< string > | fExecCode |
| code to execute in the loop | |
| list< string > | fPostCode |
| code to execute at the end of the loop | |
| int | fOrder |
| used during topological sort | |
| int | fIndex |
| used during scheduler mode code generation | |
| int | fUseCount |
| how many loops depend on this one | |
| list< Loop * > | fExtraLoops |
| extra loops that where in sequences | |
| int | fPrinted |
| true when loop has been printed (to track multi-print errors) | |
| Loop::Loop | ( | Tree | recsymbol, |
| Loop * | encl, | ||
| const string & | size | ||
| ) |
create a recursive loop
Create a recursive loop.
| recsymbol | the recursive symbol defined in this loop |
| encl | the enclosing loop |
| size | the number of iterations of the loop |
Definition at line 41 of file loop.cpp.
: fIsRecursive(true), fRecSymbolSet(singleton(recsymbol)), fEnclosingLoop(encl), fSize(size), fOrder(-1), fIndex(-1), fUseCount(0), fPrinted(0) {}
| Loop::Loop | ( | Loop * | encl, |
| const string & | size | ||
| ) |
create a non recursive loop
Create a non recursive loop.
| encl | the enclosing loop |
| size | the number of iterations of the loop |
Definition at line 51 of file loop.cpp.
: fIsRecursive(false), fRecSymbolSet(nil), fEnclosingLoop(encl), fSize(size), fOrder(-1), fIndex(-1), fUseCount(0), fPrinted(0) {}
| 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.
| l | the 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().
{
// the loops must have the same number of iterations
assert(fSize == l->fSize);
fRecSymbolSet = setUnion(fRecSymbolSet, l->fRecSymbolSet);
// update loop dependencies by adding those from the absorbed loop
fBackwardLoopDependencies.insert(l->fBackwardLoopDependencies.begin(), l->fBackwardLoopDependencies.end());
// add the line of code of the absorbed loop
fPreCode.insert(fPreCode.end(), l->fPreCode.begin(), l->fPreCode.end());
fExecCode.insert(fExecCode.end(), l->fExecCode.begin(), l->fExecCode.end());
fPostCode.insert(fPostCode.begin(), l->fPostCode.begin(), l->fPostCode.end());
}


| void Loop::addExecCode | ( | const string & | str | ) |
| void Loop::addPostCode | ( | const string & | str | ) |
| void Loop::addPreCode | ( | const string & | str | ) |
| void Loop::concat | ( | Loop * | l | ) |
Definition at line 237 of file loop.cpp.
References fBackwardLoopDependencies, fExtraLoops, and fUseCount.
Referenced by groupSeqLoops().
{
assert(l->fUseCount == 1);
assert(fBackwardLoopDependencies.size() == 1);
assert((*fBackwardLoopDependencies.begin()) == l);
fExtraLoops.push_front(l);
fBackwardLoopDependencies = l->fBackwardLoopDependencies;
}

| 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().
{
Loop* l = this;
while ( l && isNil(setIntersection(l->fRecSymbolSet,S)) ) l=l->fEnclosingLoop;
return l != 0;
}


| 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).
Definition at line 74 of file loop.cpp.
References fExecCode, fExtraLoops, fPostCode, and fPreCode.
Referenced by Klass::closeLoop().
{
return fPreCode.empty() && fExecCode.empty() && fPostCode.empty() && (fExtraLoops.begin()==fExtraLoops.end());
}

| void Loop::println | ( | int | n, |
| ostream & | fout | ||
| ) |
print the loop
Print a loop (unless it is empty)
| n | number of tabs of indentation |
| fout | output stream |
Definition at line 134 of file loop.cpp.
References fExecCode, fExtraLoops, fPostCode, fPreCode, fSize, printlines(), and tab().
Referenced by Klass::printLoopDeepFirst().
{
for (list<Loop*>::const_iterator s = fExtraLoops.begin(); s != fExtraLoops.end(); s++) {
(*s)->println(n, fout);
}
if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) {
/* if (gVectorSwitch) {
tab(n,fout);
fout << ((fIsRecursive) ? "// recursive loop" : "// vectorizable loop");
}*/
tab(n,fout); fout << "// LOOP " << this ;
if (fPreCode.size()>0) {
tab(n,fout); fout << "// pre processing";
printlines(n, fPreCode, fout);
}
tab(n,fout); fout << "// exec code";
tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {";
printlines(n+1, fExecCode, fout);
tab(n,fout); fout << "}";
if (fPostCode.size()>0) {
tab(n,fout); fout << "// post processing";
printlines(n, fPostCode, fout);
}
tab(n,fout);
}
}


| void Loop::printoneln | ( | int | n, |
| ostream & | fout | ||
| ) |
print the loop in scalar mode
Print a single loop (unless it is empty)
| n | number of tabs of indentation |
| fout | output stream |
Definition at line 214 of file loop.cpp.
References fExecCode, fPostCode, fPreCode, fSize, printlines(), and tab().
Referenced by Klass::printLoopGraphScalar().
{
if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) {
/* if (gVectorSwitch) {
tab(n,fout);
fout << ((fIsRecursive) ? "// recursive loop" : "// vectorizable loop");
}*/
tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {";
if (fPreCode.size()>0) {
tab(n+1,fout); fout << "// pre processing";
printlines(n+1, fPreCode, fout);
}
printlines(n+1, fExecCode, fout);
if (fPostCode.size()>0) {
tab(n+1,fout); fout << "// post processing";
printlines(n+1, fPostCode, fout);
}
tab(n,fout); fout << "}";
}
}


| 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
| n | number of tabs of indentation |
| fout | output stream |
Definition at line 172 of file loop.cpp.
References fExecCode, fExtraLoops, fPostCode, fPreCode, fSize, printlines(), and tab().
{
for (list<Loop*>::const_iterator s = fExtraLoops.begin(); s != fExtraLoops.end(); s++) {
tab(n,fout); fout << "#pragma omp single";
tab(n,fout); fout << "{";
(*s)->println(n+1, fout);
tab(n,fout); fout << "}";
}
if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) {
tab(n,fout); fout << "// LOOP " << this ;
if (fPreCode.size()>0) {
tab(n,fout); fout << "#pragma omp single";
tab(n,fout); fout << "{";
tab(n+1,fout); fout << "// pre processing";
printlines(n+1, fPreCode, fout);
tab(n,fout); fout << "}";
}
tab(n,fout); fout << "// exec code";
tab(n,fout); fout << "#pragma omp for";
tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {";
printlines(n+1, fExecCode, fout);
tab(n,fout); fout << "}";
if (fPostCode.size()>0) {
tab(n,fout); fout << "#pragma omp single";
tab(n,fout); fout << "{";
tab(n+1,fout); fout << "// post processing";
printlines(n+1, fPostCode, fout);
tab(n,fout); fout << "}";
}
tab(n,fout);
}
}

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 |
| 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 |
| 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 |
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().
1.8.0