00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 static int counter;
00017
00018
00019
00020 void dag::ListIntegrity()
00021 {
00022 #if defined( _STL_LIST_USED_)
00023 ListIntegrity( &Vector );
00024 #else if defined (_STL_VECTOR_USED_)
00025 ListIntegrity( &MasterList );
00026 #endif
00027 }
00028
00029
00030
00031 void dag::ListIntegrity( vector < BigListElement > *V )
00032 {
00033 int i, j, Size1, Size2, OpId;
00034 BigListElement Element, SearchElement;
00035 vector < BigListElement >::iterator BigIter;
00036 vector < SmallListElement > *ListPtr;
00037 vector < SmallListElement >::iterator Front, Back;
00038 SmallListElement SmallElement;
00039
00040
00041 for( i = 0, Size1 = V->size(); i < Size1; i++ ) {
00042 Element = (*V)[ i ];
00043 ListPtr = Element.Predecessors;
00044 for( Front = ListPtr->begin(), Back = ListPtr->end();
00045 Front != Back; Front++ ) {
00046 OpId = (*Front).GetOp()->GetOpId();
00047 BigIter = FindNode( OpId, V );
00048 if ( BigIter == V->end() )
00049 {cerr << " ** ERROR: OpId " << OpId << " not found!\n";};
00050 }
00051
00052 ListPtr = Element.Successors;
00053 for( Front = ListPtr->begin(), Back = ListPtr->end();
00054 Front != Back; Front++ ) {
00055 OpId = (*Front).GetOp()->GetOpId();
00056 BigIter = FindNode( OpId, V );
00057 if ( BigIter == V->end() )
00058 {cerr << " ** ERROR: OpId " << OpId << " not found!\n";};
00059 }
00060
00061 }
00062 }
00063
00064
00065
00066 int dag::SetNodeHeight( BigListElement *Node )
00067 {
00068 int height, tmp, max, latency, OpId;
00069 vector < SmallListElement >::iterator Front, Back;
00070 vector < BigListElement >::iterator BigIter;
00071
00072
00073
00074 if ( (height=Node->GetHeight()) != -1 ) {
00075 derr( "<> SetNodeHeight: Node " << Node->GetOp()->GetOpId()
00076 << " already visited, height " << height << "\n" );
00077 return height;
00078 }
00079
00080
00081 if ( Node->NumSuccessors() == 0 ) {
00082 height = Machine->opLatency( Node->GetOp() );
00083 Node->SetHeight( height );
00084 derr( "<> SetNodeHeight: exit Node " << Node->GetOp()->GetOpId()
00085 << " height set to " << height << ", " << ++counter
00086 << " node done\n" );
00087 return height;
00088 }
00089
00090 latency = Machine->opLatency( (*Node).GetOp() );
00091
00092
00093 for ( max = 0, Front = Node->Successors->begin(),
00094 Back = Node->Successors->end(); Front != Back; Front++ ) {
00095 OpId = (*Front).GetOp()->GetOpId();
00096 #if defined (_STL_LIST_USED_)
00097 BigIter = FindNode( OpId, &Vector );
00098 #else if defined (_STL_VECTOR_USED_)
00099 BigIter = FindNode( OpId, &MasterList );
00100 #endif
00101 tmp = SetNodeHeight( &(*BigIter) );
00102
00103
00104 switch( (*Front).GetDependencyType() ) {
00105 case ET_REGANTI: tmp += 0; break;
00106 case ET_REGFLOW: tmp += latency; break;
00107 case ET_REGOUT: tmp += latency; break;
00108 case ET_MEM: tmp += latency; break;
00109 case ET_CNTL: tmp += latency; break;
00110 default: tmp += latency; break;
00111 }
00112
00113 max = max > tmp ? max : tmp;
00114 }
00115
00116
00117
00118
00119 height = max;
00120
00121 (*Node).SetHeight( height );
00122
00123 derr( "<> SetNodeHeight: node " << (*Node).GetOp()->GetOpId()
00124 << " has height " << height << ", latency " << latency
00125 << ", " << ++counter << " node done\n" );
00126 return height;
00127 }
00128
00129
00130
00131
00132 int dag::SetNodeHeightPath( BigListElement *Node, legoRegion * exit_reg )
00133 {
00134 int height, tmp, max, latency, OpId;
00135 vector < SmallListElement >::iterator Front, Back;
00136 vector < BigListElement >::iterator BigIter;
00137
00138
00139
00140 if ( (height=Node->GetHeight()) != -1 ) {
00141 derr( "<> SetNodeHeight: Node " << Node->GetOp()->GetOpId()
00142 << " already visited, height " << height << "\n" );
00143 return height;
00144 }
00145
00146 bool on_path = false;
00147 legoRegion * par_reg = (legoRegion *)Node->GetOp()->GetParentBlockPtr();
00148 legoRegion * temp_reg = exit_reg;
00149 while(on_path == false)
00150 {
00151 if(temp_reg == par_reg)
00152 {
00153 on_path = true;
00154 break;
00155 }
00156 if(ParentRegion->GetRegionType() == RT_TREE)
00157 if(temp_reg == ((legoTreegion *) ParentRegion)->GetRoot())
00158 break;
00159 else
00160 if(temp_reg == ParentRegion)
00161 break;
00162 temp_reg = temp_reg->GetParents()->GetRegionPtr();
00163
00164 }
00165
00166 if(on_path == false)
00167 {
00168 Node->SetHeight(0);
00169 return(0);
00170
00171 }
00172
00173
00174 bool s_on_path = false;
00175 vector < SmallListElement >::iterator Front1, Back1;
00176 for (Front = Node->Successors->begin(),
00177 Back = Node->Successors->end(); Front != Back; Front++ )
00178 {
00179 legoOp * s_op = (*Front).GetOp();
00180 legoRegion * par_reg_1 = (legoRegion *)s_op->GetParentBlockPtr();
00181 legoRegion * temp_reg_1 = exit_reg;
00182 while(s_on_path == false)
00183 {
00184 if(temp_reg_1 == par_reg_1)
00185 {
00186 s_on_path = true;
00187 break;
00188 }
00189 if(ParentRegion->GetRegionType() == RT_TREE)
00190 if(temp_reg_1 == ((legoTreegion *) ParentRegion)->GetRoot())
00191 break;
00192 else
00193 if(temp_reg_1 == ParentRegion)
00194 break;
00195 temp_reg_1 = temp_reg_1->GetParents()->GetRegionPtr();
00196
00197 }
00198 if(s_on_path) break;
00199 }
00200
00201
00202
00203 if ( Node->NumSuccessors() == 0 || s_on_path == false) {
00204 height = Machine->opLatency( Node->GetOp() );
00205
00206
00207 if(Node->GetOp()->IsDUMMYBROp())
00208 height = 1;
00209
00210
00211 Node->SetHeight( height );
00212 derr( "<> SetNodeHeight: exit Node " << Node->GetOp()->GetOpId()
00213 << " height set to " << height << ", " << ++counter
00214 << " node done\n" );
00215 return height;
00216 }
00217
00218 latency = Machine->opLatency( (*Node).GetOp() );
00219
00220
00221
00222
00223
00224
00225
00226
00227 for ( max = 0, Front = Node->Successors->begin(),
00228 Back = Node->Successors->end(); Front != Back; Front++ ) {
00229 OpId = (*Front).GetOp()->GetOpId();
00230 #if defined (_STL_LIST_USED_)
00231 BigIter = FindNode( OpId, &Vector );
00232 #else if defined (_STL_VECTOR_USED_)
00233 BigIter = FindNode( OpId, &MasterList );
00234 #endif
00235 tmp = SetNodeHeightPath( &(*BigIter), exit_reg );
00236
00237
00238 switch( (*Front).GetDependencyType() ) {
00239 case ET_REGANTI: tmp -= latency; break;
00240 case ET_REGFLOW:
00241 if((*Front).GetOp()->IsBRLOp())
00242 {
00243
00244
00245
00246
00247 tmp += latency - 1;
00248 }
00249 else
00250 tmp += latency;
00251 break;
00252 case ET_REGOUT: tmp -= latency; break;
00253 case ET_MEM: tmp += 0; break;
00254 case ET_CNTL:
00255 if((*Front).GetOp()->IsBRLOp())
00256 tmp += latency;
00257 else
00258 tmp += 0;
00259 break;
00260
00261 default: cout << "<SetNodeHeightPath> Unknown deps.\n"; tmp += 0; break;
00262 }
00263
00264 max = max > tmp ? max : tmp;
00265 }
00266
00267
00268
00269
00270 height = max;
00271
00272 (*Node).SetHeight( height );
00273
00274 derr( "<> SetNodeHeight: node " << (*Node).GetOp()->GetOpId()
00275 << " has height " << height << ", latency " << latency
00276 << ", " << ++counter << " node done\n" );
00277 return height;
00278 }
00279
00280
00281
00282 void dag::SetNodeHeights()
00283 {
00284 vector < BigListElement >::iterator Front, Back;
00285
00286 counter = 0;
00287 derr( ">> SetNodeHeights - BEGIN\n" );
00288 #if defined (_STL_LIST_USED_)
00289 for ( Front = Vector.begin(), Back = Vector.end(); Front != Back;
00290 Front++ )
00291 #else if defined (_STL_VECTOR_USED_)
00292 for ( Front = MasterList.begin(), Back = MasterList.end(); Front != Back;
00293 Front++ )
00294 #endif
00295 if ( (*Front).NumPredecessors() == 0 ) {
00296 derr( " Starting at entry node " << (*Front).GetOp()->GetOpId()
00297 << "\n" );
00298 SetNodeHeight( &(*Front) );
00299 }
00300
00301 derr( "<< SetNodeHeights - END\n" );
00302 }
00303
00304
00305
00306
00307 void dag::ResetNodeHeights()
00308 {
00309 vector < BigListElement >::iterator Front, Back;
00310
00311 counter = 0;
00312 derr( ">> ResetNodeHeights - BEGIN\n" );
00313 #if defined (_STL_LIST_USED_)
00314 for ( Front = Vector.begin(), Back = Vector.end(); Front != Back;
00315 Front++ )
00316 #else if defined (_STL_VECTOR_USED_)
00317 for ( Front = MasterList.begin(), Back = MasterList.end(); Front != Back;
00318 Front++ )
00319 #endif
00320 (*Front).SetHeight(-1);
00321
00322 derr( "<< ResetNodeHeights - END\n" );
00323 }
00324
00325
00326 void dag::SetNodeHeightsPath(int exit_bb_id)
00327 {
00328 vector < BigListElement >::iterator Front, Back;
00329
00330 counter = 0;
00331 derr( ">> SetNodeHeights - BEGIN\n" );
00332
00333
00334
00335 legoRegion * exit_reg = NULL;
00336 if(ParentRegion->GetRegionType() == RT_TREE)
00337 {
00338 for(int i = 0; i < ParentRegion->GetCount(); i++)
00339 {
00340 legoRegion * reg1 = (legoRegion *)ParentRegion->GetItem(i);
00341 assert(reg1->GetRegionType() == RT_BB);
00342 if(reg1->GetRegionId() == exit_bb_id)
00343 {
00344 exit_reg = reg1;
00345 break;
00346 }
00347 }
00348 }
00349 else if(ParentRegion->GetRegionType() == RT_BB && exit_bb_id ==
00350 ParentRegion->GetRegionId())
00351 {
00352 exit_reg = ParentRegion;
00353 }
00354 assert(exit_reg != NULL);
00355
00356 #if defined (_STL_LIST_USED_)
00357 for ( Front = Vector.begin(), Back = Vector.end(); Front != Back;
00358 Front++ )
00359 #else if defined (_STL_VECTOR_USED_)
00360 for ( Front = MasterList.begin(), Back = MasterList.end(); Front != Back;
00361 Front++ )
00362 #endif
00363 if ( (*Front).NumPredecessors() == 0 ) {
00364 derr( " Starting at entry node " << (*Front).GetOp()->GetOpId()
00365 << "\n" );
00366 SetNodeHeightPath( &(*Front), exit_reg );
00367 }
00368
00369 derr( "<< SetNodeHeights - END\n" );
00370 }
00371
00372
00373
00374 int dag::SetNodeDepth( BigListElement *Node )
00375 {
00376 int depth, tmp, max, latency, OpId;
00377 vector < SmallListElement >::iterator Front, Back;
00378 vector < BigListElement >::iterator BigIter;
00379
00380
00381
00382 if ( (depth=Node->GetDepth()) != -1 ) {
00383 derr( "<> SetNodeDepth: node " << Node->GetOp()->GetOpId()
00384 << " already visited, depth " << depth << "\n" );
00385 return depth;
00386 }
00387
00388
00389 if ( Node->NumPredecessors() == 0 ) {
00390 depth = Machine->opLatency( Node->GetOp() );
00391 Node->SetDepth( depth );
00392 derr( "<> SetNodeDepth: entry node " << Node->GetOp()->GetOpId()
00393 << " depth set to " << depth << ", " << ++counter
00394 << " node done\n" );
00395 return depth;
00396 }
00397
00398 derr( ">> SetNodeDepth: processing node " << Node->GetOp()->GetOpId()
00399 << "\n" );
00400
00401 for ( max = 0, Front = Node->Predecessors->begin(),
00402 Back = Node->Predecessors->end(); Front != Back; Front++ ) {
00403 OpId = (*Front).GetOp()->GetOpId();
00404 derr( " ** Op " << Node->GetOp()->GetOpId()
00405 << ": Process predecessor " << OpId << "\n" );
00406 #if defined (_STL_LIST_USED_)
00407 BigIter = FindNode( OpId, &Vector );
00408 #else if defined (_STL_VECTOR_USED_)
00409 BigIter = FindNode( OpId, &MasterList );
00410 #endif
00411 tmp = SetNodeDepth( &(*BigIter) );
00412
00413
00414
00415 int predecessor_latency = Machine->opLatency( (*BigIter).GetOp() );
00416 switch( (*Front).GetDependencyType() ) {
00417 case ET_REGANTI: tmp -= predecessor_latency; break;
00418 case ET_REGFLOW: break;
00419 case ET_REGOUT: break;
00420 case ET_MEM: break;
00421 case ET_CNTL: break;
00422 default: break;
00423 }
00424 max = max > tmp ? max : tmp;
00425 }
00426
00427
00428 latency = Machine->opLatency( (*Node).GetOp() );
00429 depth = latency + max;
00430 (*Node).SetDepth( depth );
00431
00432 derr( "<< SetNodeDepth: node " << (*Node).GetOp()->GetOpId()
00433 << " has depth " << depth << ", latency " << latency
00434 << ", " << ++counter << " node done\n" );
00435 return depth;
00436 }
00437
00438
00439
00440 void dag::SetNodeDepths()
00441 {
00442 vector < BigListElement >::iterator Front, Back;
00443
00444 derr( ">> SetNodeDepths - BEGIN\n" );
00445 counter = 0;
00446 #if defined (_STL_LIST_USED_)
00447 for ( Front = Vector.begin(), Back = Vector.end(); Front != Back;
00448 Front++ )
00449 #else if defined (_STL_VECTOR_USED_)
00450 for ( Front = MasterList.begin(), Back = MasterList.end(); Front != Back;
00451 Front++ )
00452 #endif
00453 if ( (*Front).NumSuccessors() == 0 ) {
00454 derr( " Starting at exit node " << (*Front).GetOp()->GetOpId()
00455 << "\n" );
00456 SetNodeDepth( &(*Front) );
00457 }
00458
00459 derr( "<< SetNodeDepths - END\n" );
00460 }
00461
00462
00463
00464 void dag::ResetNodeDepths()
00465 {
00466 vector < BigListElement >::iterator Front, Back;
00467
00468 counter = 0;
00469 derr( ">> ResetNodeHeights - BEGIN\n" );
00470 #if defined (_STL_LIST_USED_)
00471 for ( Front = Vector.begin(), Back = Vector.end(); Front != Back;
00472 Front++ )
00473 #else if defined (_STL_VECTOR_USED_)
00474 for ( Front = MasterList.begin(), Back = MasterList.end(); Front != Back;
00475 Front++ )
00476 #endif
00477 (*Front).SetDepth(-1);
00478
00479 derr( "<< ResetNodeDepths - END\n" );
00480 }
00481
00482
00483
00484
00485
00486
00487 void dag::MaxHeights()
00488 {
00489 if(num_path == 0) return;
00490
00491 vector < BigListElement >::iterator Front, Back;
00492
00493 if(ParentRegion->GetRegionType() == RT_BB)
00494 {
00495 assert(num_path == 1);
00496
00497 SetNodeHeightsPath(path_BB_ids[0]);
00498
00499 double max_h = 0;
00500 #if defined (_STL_LIST_USED_)
00501 for ( Front = Vector.begin(), Back = Vector.end(); Front != Back;
00502 Front++ )
00503 #else if defined (_STL_VECTOR_USED_)
00504 for ( Front = MasterList.begin(), Back = MasterList.end(); Front != Back;
00505 Front++ )
00506 #endif
00507 {
00508 if((*Front).GetHeight() > max_h)
00509 max_h = (*Front).GetHeight();
00510 }
00511 max_heights[0] = max_h;
00512 ave_max_height = max_h;
00513 }
00514 else if(ParentRegion->GetRegionType() == RT_TREE)
00515 {
00516 double total_weight = 0;
00517 ave_max_height = 0;
00518
00519
00520
00521
00522
00523
00524
00525
00526 int i;
00527 for(i = 0; i < num_path; i++)
00528 {
00529 double max_h = 0;
00530 if(weights[i] > 0)
00531 {
00532 ResetNodeHeights();
00533 SetNodeHeightsPath(path_BB_ids[i]);
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551 #if defined (_STL_LIST_USED_)
00552 for ( Front = Vector.begin(), Back = Vector.end(); Front != Back;
00553 Front++ )
00554 #else if defined (_STL_VECTOR_USED_)
00555 for ( Front = MasterList.begin(), Back = MasterList.end(); Front != Back;
00556 Front++ )
00557 #endif
00558 {
00559 if((*Front).GetHeight() > max_h)
00560 max_h = (*Front).GetHeight();
00561 }
00562 }
00563 max_heights[i] = max_h;
00564 ave_max_height += max_h * weights[i];
00565 total_weight += weights[i];
00566 }
00567
00568 for(i = 0; i < num_path; i++)
00569 {
00570 double width_d = num_ops[i] * 1.0 / (Machine->GetNumSlots() - 1);
00571 width_d = (width_d - (int)width_d > 0.09) ? (int)(width_d +
00572 1) : width_d;
00573 if(max_heights[i] < width_d)
00574 max_heights[i] = width_d;
00575 }
00576
00577
00578 if(total_weight != 0)
00579 ave_max_height = ave_max_height / total_weight;
00580 else
00581 ave_max_height = 0;
00582 }
00583 else
00584 {
00585 cout << "<MaxHeights> Unsupported region type.\n";
00586 return;
00587 }
00588 }
00589
00590
00591
00592 void dag::CopyGraph( dag *src )
00593 {
00594 int size1, size2;
00595
00596 derr( ">> CopyGraph\n" );
00597 #if defined (_STL_LIST_USED_)
00598 size1 = src->Vector.size();
00599 CopyBigVector( &(src->Vector), &Vector );
00600 size2 = Vector.size();
00601 VectorActive = 1;
00602 #else if defined (_STL_VECTOR_USED_)
00603 size1 = src->MasterList.size();
00604 CopyBigVector( &(src->MasterList), &MasterList );
00605 size2 = MasterList.size();
00606 #endif
00607 if ( size1 != size2 )
00608 {cerr << "ERROR: dag::CopyGraph - graph node counts do not match: "
00609 << size1 << " vs. " << size2 << "\n";};
00610 derr( " src dag has " << size1 << " nodes, target dag has " << size2
00611 << " nodes\n" );
00612 derr( "<< CopyGraph\n" );
00613 }
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623 int dag::RemoveDepBetweenOps( legoOp *Op1, legoOp *Op2,
00624 enum edgeTypes dep_type )
00625 {
00626 VectorList::iterator Front, Back;
00627 vector < SmallListElement >::iterator Front2, Back2;
00628
00629 #if defined (_STL_LIST_USED_)
00630 for (Front = Vector.begin(); Front != Back; Front++) {
00631 #else if defined (_STL_VECTOR_USED_)
00632 for (Front = MasterList.begin(); Front != Back; Front++)
00633 #endif
00634 if ( (*Front).GetOp() == Op1 ) break;
00635
00636
00637 if ( Front == Back ) return -1;
00638
00639
00640 for ( Front2 = (*Front).Successors->begin(),
00641 Back2 = (*Front).Successors->end(); Front2 != Back2; Front2++ ) {
00642
00643
00644 if ( (*Front2).GetDependencyType() == dep_type &&
00645 (*Front2).GetDagEntry()->GetOp() == Op2 ) {
00646
00647 VectorList::iterator Op2_location = (*Front2).GetDagEntry();
00648
00649 (*Front).Successors->erase( Front2 );
00650
00651 Back2 = (*Front).Successors->end();
00652 SetVectorPtrs( (*Front).Successors );
00653
00654
00655 for ( Front2 = (*Op2_location).Predecessors->begin(),
00656 Back2 = (*Op2_location).Predecessors->end(); Front2 != Back2;
00657 Front2++ )
00658 if ( (*Front2).GetDependencyType() == dep_type &&
00659 (*Front2).GetDagEntry()->GetOp() == Op1 ) {
00660 (*Op2_location).Predecessors->erase( Front2 );
00661
00662 Back2 = (*Op2_location).Predecessors->end();
00663 SetVectorPtrs( (*Op2_location).Predecessors );
00664 break;
00665 }
00666 if ( Front2 == Back2 ) return -3;
00667 return 0;
00668 }
00669 }
00670 return -2;
00671 }
00672
00673
00674
00675
00676
00677
00678
00679
00680 static void PrintMapEntry( char *Key, RegisterInfo Entry )
00681 {
00682
00683
00684
00685
00686 cout << "\n Key " << Key << "\n";
00687 cout << "\t RFType " << Entry.RFType << ", Regid " << Entry.Regid << "\n";
00688 cout << "\t Defining OpId " << Entry.DefiningOpId;
00689
00690
00691
00692
00693 cout << "\t Using OpId " << Entry.UsingOpId;
00694
00695
00696 }
00697
00698
00699
00700 void PrintTable( DagHashTable *TablePtr )
00701 {
00702 DagHashTable::iterator Front, Back;
00703
00704
00705 cout << "\nPrinting def-use table\n";
00706 cout << "\n----------------------\n";
00707 for ( Front = TablePtr->begin(), Back = TablePtr->end(); Front != Back;
00708 Front++ )
00709 PrintMapEntry( (*Front).first, (*Front).second );
00710 cout << "\n---------- END -------\n";
00711 }
00712
00713