00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _INCLUDE_DAG_H_
00012 #define _INCLUDE_DAG_H_
00013
00014 #define IA64_SUPPORT //HZ: enable the setting of inp_start, inp_end, etc.,
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <stl.h>
00046 #include "TinkerKnobs.H"
00047 #include "lego.H"
00048
00049 class machine;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 #include "DagNode.H"
00086 #include "SmallListNode.H"
00087 #include "SmallListElement.H"
00088 #include "BigListElement.H"
00089 #include "DagHashTable.H"
00090
00091
00092
00093 #define MAX_NUM_PATH 1000
00094
00095
00096 class dag_node_ordering;
00097 class list_scheduler;
00098 class bottom_up_greedy;
00099
00100
00101 void PrintTable( DagHashTable *TablePtr );
00102
00103
00104
00105 class dag {
00106
00107 friend class dag_node_ordering;
00108 friend class list_scheduler;
00109 friend class bottom_up_greedy;
00110 friend void DrawDAG (dag *, char *);
00111
00112 public:
00113
00114 MainList MasterList;
00115
00116
00117
00118 protected:
00119
00120 const int Hash_Key_Size = 20, Hash_Reg_Size = 10;
00121
00122
00123 #if defined (_STL_LIST_USED_)
00124 #endif
00125 vector < BigListElement > Vector;
00126 int VectorActive;
00127
00128 legoRegion *ParentRegion;
00129 enum regionTypes ParentRegionType;
00130
00131 vector <char *> HashKeyList;
00132
00133 int KillDagFlag;
00134
00135 MainList::iterator MainListIter,
00136 BranchBarrier;
00137
00138 vector <MainList::iterator> StoreList;
00139 vector <MainList::iterator> LoadList;
00140
00141 DagHashTable::const_iterator LookupIter;
00142 RegisterInfo WriteElement,
00143 ReadElement;
00144
00145 DagHashTable Table;
00146
00147 int NumNodes;
00148 double ProfileWeight;
00149
00150
00151
00152 machine *Machine;
00153
00154 int InternalNodes;
00155
00156
00157 int NotRoot;
00158
00159
00160 legoRegion *prev_block_ptr;
00161
00162 char *WriteHashKey, *ReadHashKey,
00163 *WriteHashReg, *ReadHashReg;
00164 private:
00165
00166 double ave_max_height;
00167 double * max_heights;
00168 int num_path;
00169 int * path_BB_ids;
00170 double * weights;
00171 int * num_ops;
00172
00173
00174
00175
00176 int inp_start, inp_end, ret_start, ret_end, fp_ret_start, fp_ret_end;
00177
00178
00179 void SetNodeHeightsPath(int end_bb_id);
00180 int SetNodeHeightPath(vector < BigListElement >::iterator, legoRegion
00181 *exit_reg);
00182 protected:
00183 MainList::iterator InsertOp( BigListElement Element );
00184 void SetBrDeps( MainList::iterator MasterListIter );
00185
00186 void SetBrDepsFirst( MainList::iterator MasterListIter, legoRegion *Region );
00187 void SetPBRDeps( MainList::iterator MasterListIter, legoRegion *Region );
00188
00189 void SetVectorPtrs( vector < SmallListElement > * );
00190 void SetSublistPtrs( VectorList *V );
00191 void CopyVectorToVector( VectorList *v1, VectorList *v2 );
00192 void CopyListToVector( MainList::iterator, MainList::iterator );
00193 void CopyListToVector();
00194
00195 void AnalyzeFlowDep( legoOprd *, MainList::iterator );
00196 int OutputDeps( legoOprd *, MainList::iterator );
00197 int AntiDeps( legoOprd *, MainList::iterator );
00198
00199 void FlowDeps( MainList::iterator, BigListElement * );
00200 void OutputAntiDeps( MainList::iterator, BigListElement * );
00201 void UpdateUseStatus( MainList::iterator, BigListElement * );
00202 void RemoveUndefPredecessors();
00203
00204 void ConstructLinearDag( legoRegion * );
00205 void ConstructTreeDag(legoRegion *, DagHashTable *,
00206 vector <MainList::iterator> *,
00207 vector <MainList::iterator> *);
00208
00209 int SetNodeHeight( vector < BigListElement >::iterator );
00210 int SetNodeDepth( vector < BigListElement >::iterator );
00211
00212 void PrintVectorDag( vector < BigListElement> * );
00213
00214
00215 void PrintVectorDag( vector < BigListElement> *, ofstream & os1);
00216
00217 void ListIntegrity( vector < BigListElement > * );
00218
00219 void BubbleSort( vector < BigListElement >::iterator,
00220 vector < BigListElement >::iterator,
00221 int (*)( BigListElement *, BigListElement * ) );
00222 void BubbleSort( int (*)( BigListElement *, BigListElement * ) );
00223
00224 public:
00225
00226
00227
00228
00229
00230
00231 dag(int Inp_start, int Inp_end, int Ret_start, int Ret_end, int Fp_ret_start,
00232 int Fp_ret_end)
00233 {
00234 NumNodes = KillDagFlag = 0;
00235 inp_start = Inp_start;
00236 inp_end = Inp_end;
00237 ret_start = Ret_start;
00238 ret_end = Ret_end;
00239 fp_ret_start = Fp_ret_start;
00240 fp_ret_end = Fp_ret_end;
00241 }
00242
00243
00244 dag( machine *, int Inp_start, int Inp_end, int Ret_start, int Ret_end, int Fp_ret_start,
00245 int Fp_ret_end );
00246
00247
00248 dag( machine *, knobs *, int Inp_start, int Inp_end, int Ret_start, int Ret_end, int Fp_ret_start,
00249 int Fp_ret_end );
00250
00251
00252 void CopyGraph( dag *src );
00253
00254
00255 void CopyDefUseTable( dag *src )
00256 {
00257
00258
00259 Table = src->Table;
00260 }
00261
00262
00263 machine *GetMachine() { return Machine; }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 ~dag();
00274
00275
00276 void DeleteDefUseTable();
00277
00278
00279 void DeleteGraphNodes();
00280
00281
00282
00283 void KillDag();
00284
00285
00286
00287
00288
00289 Stats();
00290
00291 void SetNumNodes( int Value ) { NumNodes = Value; }
00292 int GetListSize() { return NumNodes; }
00293
00294 void ConstructDag( legoRegion * );
00295 vector < BigListElement > *GetList()
00296 {
00297 #if defined (_STL_LIST_USED_)
00298 return &Vector;
00299 #else if defined (_STL_VECTOR_USED_)
00300 return &MasterList;
00301 #endif
00302 }
00303
00304 void FullyResolvePredicates( legoRegion *, legoOp* );
00305
00306 void SortByOpId();
00307 void SortByHeight();
00308 void SortByValue();
00309
00310 void SetNodeHeights();
00311 void SetNodeDepths();
00312
00313
00314 void ResetNodeHeights();
00315 void ResetNodeDepths();
00316
00317 void MaxHeights();
00318
00319 double GetAveMaxHeight() {return ave_max_height;}
00320 int GetNumPath() {return num_path;}
00321 int GetAveWidth()
00322 {
00323 int ave_width = 0;
00324 for(int i = 0; i < num_path; i++)
00325 {
00326 ave_width += num_ops[i];
00327 }
00328 if(num_path > 0)
00329 return ave_width/num_path;
00330 else
00331 return 0;
00332 }
00333
00334 void PrintDag();
00335 void PrintGraphicDag( int print_control_edges = 1 );
00336 void PrintDag(ofstream & os1);
00337 void PrintDefUseTable() { PrintTable( &Table ); }
00338
00339 void ListIntegrity();
00340
00341
00342
00343
00344
00345
00346
00347
00348 int RemoveDepBetweenOps( legoOp *Op1, legoOp *Op2, enum edgeTypes dep_type );
00349 int AreVectorsIndependent(bitvector *vector1, bitvector *vector2, int vector_size);
00350 int AreOpsDependent(legoOp *Op1, legoOp *Op2);
00351 };
00352
00353 #endif // _INCLUDE_DAG_H_