#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 | hasRecDependencies () |
returns true is this loop has recursive dependencies | |
void | addRecDependency (Tree t) |
Check for a recursive dependecy and add it if needed. | |
bool | findRecDefinition (Tree t) |
indicates a dependency with an enclosing loop | |
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 | 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 | |
const Tree | fRecSymbol |
recursive loops define a recursive symbol | |
Loop *const | fEnclosingLoop |
Loop from which this one originated. | |
const string | fSize |
number of iterations of the loop | |
set< Tree > | fRecDependencies |
Loops having recursive dependencies must be merged. | |
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 |
Definition at line 51 of file loop.hh.
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 39 of file loop.cpp.
00040 : fIsRecursive(true), fRecSymbol(recsymbol), fEnclosingLoop(encl), fSize(size), fOrder(-1), fIndex(-1), fUseCount(0) 00041 {}
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 49 of file loop.cpp.
00050 : fIsRecursive(false), fRecSymbol(), fEnclosingLoop(encl), fSize(size), fOrder(-1), fIndex(-1), fUseCount(0) 00051 {}
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 132 of file loop.cpp.
References fBackwardLoopDependencies, fExecCode, fIsRecursive, fPostCode, fPreCode, fRecDependencies, fRecSymbol, and fSize.
Referenced by Klass::closeLoop().
00133 { 00134 // the loops must have the same number of iterations 00135 assert(fSize == l->fSize); 00136 00137 // update recursive dependencies by adding those from the absorbed loop 00138 fRecDependencies.insert(l->fRecDependencies.begin(), l->fRecDependencies.end()); 00139 if (fIsRecursive) fRecDependencies.erase(fRecSymbol); 00140 00141 // update loop dependencies by adding those from the absorbed loop 00142 fBackwardLoopDependencies.insert(l->fBackwardLoopDependencies.begin(), l->fBackwardLoopDependencies.end()); 00143 00144 // add the line of code of the absorbed loop 00145 fPreCode.insert(fPreCode.end(), l->fPreCode.begin(), l->fPreCode.end()); 00146 fExecCode.insert(fExecCode.end(), l->fExecCode.begin(), l->fExecCode.end()); 00147 fPostCode.insert(fPostCode.begin(), l->fPostCode.begin(), l->fPostCode.end()); 00148 }
void Loop::addExecCode | ( | const string & | str | ) |
add a line of C++ code
Add a line of exec code.
Definition at line 110 of file loop.cpp.
References fExecCode.
Referenced by Klass::addExecCode().
00111 { 00112 // cerr << this << "->addExecCode " << str << endl; 00113 fExecCode.push_back(str); 00114 }
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 120 of file loop.cpp.
References fPostCode.
Referenced by Klass::addPostCode().
00121 { 00122 // cerr << this << "->addPostCode " << str << endl; 00123 fPostCode.push_front(str); 00124 }
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 101 of file loop.cpp.
References fPreCode.
Referenced by Klass::addPreCode().
00102 { 00103 // cerr << this << "->addExecCode " << str << endl; 00104 fPreCode.push_back(str); 00105 }
void Loop::addRecDependency | ( | Tree | t | ) |
Check for a recursive dependecy and add it if needed.
Add a recursive dependency, unless it is itself.
Definition at line 79 of file loop.cpp.
References fRecDependencies, and fRecSymbol.
Referenced by VectorCompiler::CS(), and VectorCompiler::generateCode().
00080 { 00081 if (t != fRecSymbol) { 00082 fRecDependencies.insert(t); 00083 } 00084 }
void Loop::concat | ( | Loop * | l | ) |
Definition at line 215 of file loop.cpp.
References fBackwardLoopDependencies, fExtraLoops, and fUseCount.
Referenced by groupSeqLoops().
00216 { 00217 assert(l->fUseCount == 1); 00218 assert(fBackwardLoopDependencies.size() == 1); 00219 assert((*fBackwardLoopDependencies.begin()) == l); 00220 00221 fExtraLoops.push_front(l); 00222 fBackwardLoopDependencies = l->fBackwardLoopDependencies; 00223 }
bool Loop::findRecDefinition | ( | Tree | t | ) |
indicates a dependency with an enclosing loop
Search if t is defined in this loop or the enclosing ones.
Definition at line 91 of file loop.cpp.
References fEnclosingLoop, and fRecSymbol.
Referenced by VectorCompiler::CS(), and VectorCompiler::generateCode().
00092 { 00093 Loop* l = this; 00094 while (l && l->fRecSymbol != t) l=l->fEnclosingLoop; 00095 return l != 0; 00096 }
bool Loop::hasRecDependencies | ( | ) |
returns true is this loop has recursive dependencies
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 60 of file loop.cpp.
References fRecDependencies.
Referenced by Klass::closeLoop().
00061 { 00062 return !fRecDependencies.empty(); 00063 }
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 70 of file loop.cpp.
References fExecCode, fExtraLoops, fPostCode, and fPreCode.
Referenced by Klass::closeLoop().
00071 { 00072 return fPreCode.empty() && fExecCode.empty() && fPostCode.empty() && (fExtraLoops.begin()==fExtraLoops.end()); 00073 }
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 156 of file loop.cpp.
References fExecCode, fExtraLoops, fPostCode, fPreCode, fSize, printlines(), and tab().
Referenced by Klass::printLoopDeepFirst().
00157 { 00158 for (list<Loop*>::const_iterator s = fExtraLoops.begin(); s != fExtraLoops.end(); s++) { 00159 (*s)->println(n, fout); 00160 } 00161 00162 if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) { 00163 /* if (gVectorSwitch) { 00164 tab(n,fout); 00165 fout << ((fIsRecursive) ? "// recursive loop" : "// vectorizable loop"); 00166 }*/ 00167 00168 tab(n,fout); fout << "// LOOP " << this ; 00169 if (fPreCode.size()>0) { 00170 tab(n,fout); fout << "// pre processing"; 00171 printlines(n, fPreCode, fout); 00172 } 00173 00174 tab(n,fout); fout << "// exec code"; 00175 tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {"; 00176 printlines(n+1, fExecCode, fout); 00177 tab(n,fout); fout << "}"; 00178 00179 if (fPostCode.size()>0) { 00180 tab(n,fout); fout << "// post processing"; 00181 printlines(n, fPostCode, fout); 00182 } 00183 tab(n,fout); 00184 } 00185 }
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 192 of file loop.cpp.
References fExecCode, fPostCode, fPreCode, fSize, printlines(), and tab().
Referenced by Klass::printLoopGraphScalar().
00193 { 00194 if (fPreCode.size()+fExecCode.size()+fPostCode.size() > 0) { 00195 /* if (gVectorSwitch) { 00196 tab(n,fout); 00197 fout << ((fIsRecursive) ? "// recursive loop" : "// vectorizable loop"); 00198 }*/ 00199 00200 tab(n,fout); fout << "for (int i=0; i<" << fSize << "; i++) {"; 00201 if (fPreCode.size()>0) { 00202 tab(n+1,fout); fout << "// pre processing"; 00203 printlines(n+1, fPreCode, fout); 00204 } 00205 printlines(n+1, fExecCode, fout); 00206 if (fPostCode.size()>0) { 00207 tab(n+1,fout); fout << "// post processing"; 00208 printlines(n+1, fPostCode, fout); 00209 } 00210 tab(n,fout); fout << "}"; 00211 } 00212 }
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 55 of file loop.hh.
Referenced by Klass::closeLoop(), and findRecDefinition().
list<string> Loop::fExecCode |
code to execute in the loop
Definition at line 62 of file loop.hh.
Referenced by absorb(), addExecCode(), isEmpty(), println(), and printoneln().
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(), and printoneln().
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(), and printoneln().
Loops having recursive dependencies must be merged.
Definition at line 58 of file loop.hh.
Referenced by absorb(), addRecDependency(), and hasRecDependencies().
const Tree Loop::fRecSymbol |
recursive loops define a recursive symbol
Definition at line 54 of file loop.hh.
Referenced by absorb(), addRecDependency(), and findRecDefinition().
const string Loop::fSize |
number of iterations of the loop
Definition at line 56 of file loop.hh.
Referenced by absorb(), println(), and printoneln().
int Loop::fUseCount |
how many loops depend on this one
Definition at line 68 of file loop.hh.
Referenced by computeUseCount(), concat(), and groupSeqLoops().