00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _KLASS_H
00025 #define _KLASS_H
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 using namespace std;
00039
00040 #include <string>
00041 #include <list>
00042 #include <set>
00043 #include <map>
00044 #include "sigtype.hh"
00045 #include "smartpointer.hh"
00046 #include "tlib.hh"
00047 #include "uitree.hh"
00048 #include "property.hh"
00049
00050 #define kMaxCategory 32
00051
00052 #include "loop.hh"
00053 #include "graphSorting.hh"
00054
00055 class Klass
00056 {
00057
00058 protected:
00059
00060 string fKlassName;
00061 string fSuperKlassName;
00062 int fNumInputs;
00063 int fNumOutputs;
00064 int fNumActives;
00065 int fNumPassives;
00066
00067
00068 set<string> fIncludeFileSet;
00069 set<string> fLibrarySet;
00070
00071 list<Klass* > fSubClassList;
00072
00073 list<string> fDeclCode;
00074 list<string> fStaticInitCode;
00075 list<string> fStaticFields;
00076 list<string> fInitCode;
00077 list<string> fUICode;
00078 list<string> fUIMacro;
00079
00080 #if 0
00081 list<string> fSlowDecl;
00082 list<string> fSharedDecl;
00083 list<string> fCommonCode;
00084 list<string> fSlowCode;
00085 list<string> fEndCode;
00086 #endif
00087 list<string> fSharedDecl;
00088 list<string> fFirstPrivateDecl;
00089
00090 list<string> fZone1Code;
00091 list<string> fZone2Code;
00092 list<string> fZone2bCode;
00093 list<string> fZone2cCode;
00094 list<string> fZone3Code;
00095
00096 Loop* fTopLoop;
00097 property<Loop*> fLoopProperty;
00098
00099 bool fVec;
00100
00101 public:
00102
00103 Klass (const string& name, const string& super, int numInputs, int numOutputs, bool __vec = false)
00104 : fKlassName(name), fSuperKlassName(super), fNumInputs(numInputs), fNumOutputs(numOutputs),
00105 fNumActives(0), fNumPassives(0),
00106 fTopLoop(new Loop(0, "count")), fVec(__vec)
00107 {}
00108
00109 virtual ~Klass() {}
00110
00111 void openLoop(const string& size);
00112 void openLoop(Tree recsymbol, const string& size);
00113 void closeLoop(Tree sig=0);
00114
00115 void setLoopProperty(Tree sig, Loop* l);
00116 bool getLoopProperty(Tree sig, Loop*& l);
00117
00118 Loop* topLoop() { return fTopLoop; }
00119
00120 void buildTasksList();
00121
00122 void addIncludeFile (const string& str) { fIncludeFileSet.insert(str); }
00123
00124 void addLibrary (const string& str) { fLibrarySet.insert(str); }
00125
00126 void collectIncludeFile(set<string>& S);
00127
00128 void collectLibrary(set<string>& S);
00129
00130 void addSubKlass (Klass* son) { fSubClassList.push_back(son); }
00131
00132 void addDeclCode (const string& str) { fDeclCode.push_back(str); }
00133
00134 void addInitCode (const string& str) { fInitCode.push_back(str); }
00135
00136 void addStaticInitCode (const string& str) { fStaticInitCode.push_back(str); }
00137
00138 void addStaticFields (const string& str) { fStaticFields.push_back(str); }
00139
00140 void addUICode (const string& str) { fUICode.push_back(str); }
00141
00142 void addUIMacro (const string& str) { fUIMacro.push_back(str); }
00143
00144 void incUIActiveCount () { fNumActives++; }
00145 void incUIPassiveCount () { fNumPassives++; }
00146
00147
00148 void addSharedDecl (const string& str) { fSharedDecl.push_back(str); }
00149 void addFirstPrivateDecl (const string& str) { fFirstPrivateDecl.push_back(str); }
00150
00151 void addZone1 (const string& str) { fZone1Code.push_back(str); }
00152 void addZone2 (const string& str) { fZone2Code.push_back(str); }
00153 void addZone2b (const string& str) { fZone2bCode.push_back(str); }
00154 void addZone2c (const string& str) { fZone2cCode.push_back(str); }
00155 void addZone3 (const string& str) { fZone3Code.push_back(str); }
00156
00157 void addPreCode ( const string& str) { fTopLoop->addPreCode(str); }
00158 void addExecCode ( const string& str) { fTopLoop->addExecCode(str); }
00159 void addPostCode (const string& str) { fTopLoop->addPostCode(str); }
00160
00161 virtual void println(int n, ostream& fout);
00162
00163 virtual void printComputeMethod (int n, ostream& fout);
00164 virtual void printComputeMethodScalar (int n, ostream& fout);
00165 virtual void printComputeMethodVectorFaster (int n, ostream& fout);
00166 virtual void printComputeMethodVectorSimple (int n, ostream& fout);
00167 virtual void printComputeMethodOpenMP (int n, ostream& fout);
00168 virtual void printComputeMethodScheduler (int n, ostream& fout);
00169
00170 virtual void printLoopGraphScalar(int n, ostream& fout);
00171 virtual void printLoopGraphVector(int n, ostream& fout);
00172 virtual void printLoopGraphOpenMP(int n, ostream& fout);
00173 virtual void printLoopGraphScheduler(int n, ostream& fout);
00174 virtual void printLoopGraphInternal(int n, ostream& fout);
00175
00176
00177 virtual void printLoopDeepFirst(int n, ostream& fout, Loop* l, set<Loop*>& visited);
00178
00179 virtual void printLastLoopLevelScheduler(int n, int lnum, const lset& L, ostream& fout);
00180 virtual void printLoopLevelScheduler(int n, int lnum, const lset& L, ostream& fout);
00181 virtual void printOneLoopScheduler(lset::const_iterator p, int n, ostream& fout);
00182 virtual void printLoopLevelOpenMP(int n, int lnum, const lset& L, ostream& fout);
00183
00184 virtual void printMetadata(int n, const map<Tree, set<Tree> >& S, ostream& fout);
00185
00186 virtual void printIncludeFile(ostream& fout);
00187
00188 virtual void printLibrary(ostream& fout);
00189
00190 int inputs() { return fNumInputs; }
00191 int outputs() { return fNumOutputs; }
00192 };
00193
00194 class SigIntGenKlass : public Klass {
00195
00196 public:
00197
00198 SigIntGenKlass (const string& name) : Klass(name, "", 0, 1, false) {}
00199
00200 virtual void println(int n, ostream& fout);
00201 };
00202
00203 class SigFloatGenKlass : public Klass {
00204
00205 public:
00206
00207 SigFloatGenKlass (const string& name) : Klass(name, "", 0, 1, false) {}
00208
00209 virtual void println(int n, ostream& fout);
00210 };
00211
00212
00213 #endif