FAUST compiler  0.9.9.6b8
Public Member Functions | Public Attributes
Loop Struct Reference

#include <loop.hh>

Collaboration diagram for Loop:
Collaboration graph
[legend]

List of all members.

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)

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.

        : 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.

Parameters:
enclthe enclosing loop
sizethe 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)
{}

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

{ 
    // 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());
}

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.

{ 
   // cerr << this << "->addExecCode " << str << endl;
    fExecCode.push_back(str); 
}
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.

{ 
   // cerr << this << "->addPostCode " << str << endl;
    fPostCode.push_front(str); 
}
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.

{ 
   // cerr << this << "->addExecCode " << str << endl;
    fPreCode.push_back(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;   
}

Here is the caller graph for this function:

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;
}

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

{ 
    return fPreCode.empty() && fExecCode.empty() && fPostCode.empty() && (fExtraLoops.begin()==fExtraLoops.end()); 
}

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

{
    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);
    }
}

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

{
    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 << "}";
    }
}

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

{
    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);
    }
}

Here is the call graph for this function:


Member Data Documentation

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

extra loops that where in sequences

Definition at line 69 of file loop.hh.

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

Loops that will be computed after this one.

Definition at line 60 of file loop.hh.

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.

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

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

Definition at line 71 of file loop.hh.

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

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: