00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00046
00047 #include <set>
00048 #include <utility>
00049 #include <ext/hash_map>
00050 #include "defs.h"
00051 #include "tracing.h"
00052 #include "cgtarget.h"
00053 #include "cg_dep_graph.h"
00054 #include "w2op.h"
00055 #include "targ_proc_properties.h"
00056 #include "ipfec_defs.h"
00057 #include "region_bb_util.h"
00058 #include "dag.h"
00059 #include "prdb.h"
00060 #include "region_bb_util.h"
00061 #include "op_targ.h"
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 extern MEM_POOL dep_nz_pool;
00073 extern TN_LIST *same_reg[REGISTER_MAX+1][ISA_REGISTER_CLASS_MAX+1];
00074
00075 TN *
00076 set_representative_tn (TN* tn) {
00077 if (!TN_is_register(tn) || TN_register(tn) == REGISTER_UNDEFINED) {
00078 return tn ;
00079 }
00080
00081 REGISTER rnum = TN_register(tn);
00082 ISA_REGISTER_CLASS rclass = TN_register_class(tn);
00083 TN_LIST *tns = same_reg[rnum][rclass];
00084
00085 if (tns) { return TN_LIST_first(tns); }
00086
00087 same_reg[rnum][rclass] = TN_LIST_Push(tn, same_reg[rnum][rclass],
00088 &dep_nz_pool);
00089
00090 return tn ;
00091 }
00092
00093 TN *
00094 get_representative_tn (TN *tn) {
00095 if (!TN_is_register (tn)) return tn ;
00096 REGISTER rnum = TN_register(tn);
00097 ISA_REGISTER_CLASS rclass = TN_register_class(tn);
00098 TN_LIST *tns;
00099
00100 for (tns = same_reg[rnum][rclass]; tns; tns = TN_LIST_rest(tns)) {
00101 return TN_LIST_first(tns) ;
00102 }
00103
00104 return tn ;
00105 }
00106
00107 INT16
00108 get_opnd_idx (OP *op , TN* tn) {
00109 tn = set_representative_tn(tn);
00110 for (INT16 idx = OP_opnds (op) - 1 ; idx >= 0 ; idx--) {
00111 TN * opnd = OP_opnd(op,idx);
00112 opnd = set_representative_tn (opnd) ;
00113 if (opnd == tn) return idx ;
00114 }
00115
00116 return -1;
00117 }
00118
00119 void
00120 adjust_reganti_latency (ARC *arc) {
00121 if (ARC_kind (arc) != CG_DEP_REGANTI) return ;
00122
00123 OP * pred = ARC_pred (arc) ;
00124 TN * tn = OP_opnd(pred,ARC_opnd(arc)) ;
00125
00126 if (TN_is_register(tn) && TN_register_class(tn) ==
00127 ISA_REGISTER_CLASS_predicate) {
00128 return ;
00129 }
00130
00131 arc->latency = 0 ;
00132 }
00133
00134 void
00135 adjust_reganti_latency (BB *bb) {
00136
00137 OP * op ;
00138 FOR_ALL_BB_OPs (bb, op) {
00139 for (ARC_LIST* arcs = OP_succs(op); arcs != NULL;
00140 arcs = ARC_LIST_rest(arcs)) {
00141 ARC *arc = ARC_LIST_first(arcs) ;
00142 if (ARC_kind(arc) != CG_DEP_REGANTI) continue ;
00143 adjust_reganti_latency (arc) ;
00144 }
00145 }
00146 }
00147
00148 inline mINT32 DAG_BUILDER::Get_Table_Index(OP* op){
00149
00150 return _BB_Bitset_Table_Index[BB_id(OP_bb(op))];
00151 }
00152
00153 inline mINT32 DAG_BUILDER::Get_Table_Index(BB* bb){
00154
00155 return _BB_Bitset_Table_Index[BB_id(bb)];
00156 }
00157
00158
00159 inline mINT32 DAG_BUILDER::Get_Table_Index(TN* tn){
00160
00161 return _TN_Bitset_Table_Index[TN_number(tn)];
00162 }
00163
00164
00165 BOOL
00166 DAG_BUILDER::OP_Shadowed_By_Prev_OPs(OP* defop,
00167 OPs& prev_def_ops,
00168 COMPARE_FUNCTION comp_func)
00169 {
00170
00171 return FALSE;
00172 }
00173
00174 DAG_BUILDER::OPs&
00175 DAG_BUILDER::Get_Def_Use_OPs(OP *op, UINT8 res, CG_DEP_KIND arc_kind)
00176 {
00177 TN *tn;
00178 if (arc_kind == CG_DEP_REGIN) {
00179 tn = OP_opnd(op, res);
00180 } else if (arc_kind == CG_DEP_REGOUT ||
00181 arc_kind == CG_DEP_REGANTI) {
00182 tn = OP_result(op, res);
00183 }
00184
00185 tn = set_representative_tn (tn);
00186
00187 if (!TN_is_register(tn) || TN_is_true_pred(tn)) {
00188 return _empty_set;
00189 }
00190
00191 if (arc_kind == CG_DEP_REGIN) {
00192 return _bb_def_info_map[OP_bb(op)][tn];
00193 } else if (arc_kind == CG_DEP_REGOUT) {
00194 return _bb_def_info_map[OP_bb(op)][tn];
00195 } else if (arc_kind == CG_DEP_REGANTI) {
00196 return _bb_use_info_map[OP_bb(op)][tn];
00197 } else {
00198 Is_True(FALSE, ("Shouldn't come here"));
00199 }
00200 }
00201
00202 void
00203 DAG_BUILDER::Get_Define_OPs(OP *op, UINT8 res, CG_DEP_KIND arc_kind)
00204 {
00205 _Define_OPs.clear();
00206
00207 TN *tn;
00208 if (arc_kind == CG_DEP_REGIN ||
00209 arc_kind == CG_DEP_REGANTI) {
00210 tn = OP_opnd(op, res);
00211 }
00212 else if (arc_kind == CG_DEP_REGOUT ) {
00213 tn = OP_result(op, res);
00214 }
00215
00216 tn = set_representative_tn (tn);
00217
00218 if (!TN_is_register(tn) || TN_is_true_pred(tn)) {
00219 return;
00220 }
00221
00222
00223 if (arc_kind == CG_DEP_REGIN ||
00224 arc_kind == CG_DEP_REGOUT ) {
00225
00226
00227
00228
00229 BS* def_ops = BS_Create_Empty (_OP_Count, &_mem_pool);
00230 BS_CopyD( def_ops ,
00231 _BB_Bitset_Table[Get_Table_Index(op)].gen ,
00232 &_mem_pool );
00233 BS_IntersectionD( def_ops ,
00234 _TN_Bitset_Table[Get_Table_Index(tn)].def );
00235
00236
00237
00238 OP* latest_op=NULL;
00239
00240 BS_ELT elt;
00241 for ( elt = BS_Choose( def_ops );
00242 elt != BS_CHOOSE_FAILURE && elt < OP_To_Gid(op);
00243 elt = BS_Choose_Next( def_ops, elt ) ){
00244 OP* tmp = Gid_To_OP(elt);
00245 if (!OP_has_disjoint_predicate(tmp, op)) {
00246 latest_op=Gid_To_OP(elt);
00247 _Define_OPs.push_back(latest_op);
00248 }
00249 }
00250
00251
00252 if(latest_op == NULL){
00253
00254 BS_CopyD( def_ops ,
00255 _BB_Bitset_Table[Get_Table_Index(op)].in,
00256 &_mem_pool );
00257 BS_IntersectionD( def_ops ,
00258 _TN_Bitset_Table[Get_Table_Index(tn)].def );
00259
00260 for ( elt = BS_Choose( def_ops );
00261 elt != BS_CHOOSE_FAILURE ;
00262 elt = BS_Choose_Next( def_ops, elt ) ){
00263 _Define_OPs.push_back( Gid_To_OP(elt) );
00264 }
00265 }
00266
00267 }
00268
00269 else if (arc_kind == CG_DEP_REGANTI) {
00270
00271
00272 BS* def_ops = BS_Create_Empty (_OP_Count, &_mem_pool);
00273 BS_CopyD( def_ops ,
00274 _BB_Bitset_Table[Get_Table_Index(op)].gen ,
00275 &_mem_pool );
00276
00277 BS_IntersectionD( def_ops ,
00278 _TN_Bitset_Table[Get_Table_Index(tn)].def );
00279
00280
00281
00282
00283
00284 OP* nearest_op=NULL;
00285
00286 BS_ELT elt;
00287 for ( elt = OP_To_Gid(op) , elt = BS_Choose_Next( def_ops, elt ) ;
00288
00289 elt != BS_CHOOSE_FAILURE ;
00290 elt = BS_Choose_Next( def_ops, elt ) ){
00291 OP* tmp = Gid_To_OP(elt);
00292 if (!OP_has_disjoint_predicate(tmp, op)) {
00293 nearest_op=Gid_To_OP(elt);
00294 _Define_OPs.push_back(nearest_op);
00295 }
00296 }
00297
00298
00299
00300 if(nearest_op == NULL){
00301
00302 BS_CopyD( def_ops ,
00303 _BB_Bitset_Table[ Get_Table_Index(op)].reverse_in ,
00304 &_mem_pool );
00305 BS_IntersectionD( def_ops ,
00306 _TN_Bitset_Table[Get_Table_Index(tn)].def );
00307
00308
00309 for ( elt = BS_Choose( def_ops );
00310 elt != BS_CHOOSE_FAILURE ;
00311 elt = BS_Choose_Next( def_ops, elt ) ){
00312 _Define_OPs.push_back( Gid_To_OP(elt) );
00313 }
00314 }
00315
00316 }
00317 else {
00318 Is_True(FALSE, ("Shouldn't come here"));
00319 }
00320 }
00321
00322
00323 inline mUINT16 DAG_BUILDER::OP_To_Gid(OP* op){
00324
00325 return op->order;
00326 }
00327
00328 inline OP* DAG_BUILDER::Gid_To_OP(mINT32 gid){
00329
00330 return _OP_Table[gid];
00331 }
00332
00333 void
00334 DAG_BUILDER::Init_TN_BB_Bitset_Table(void)
00335 {
00336
00337 mINT32 i;
00338 _TN_Bitset_Table_Index.resize(_Max_TN_number+1);
00339
00340 for ( i = 0; i < _Max_TN_number+1; i++)
00341 _TN_Bitset_Table_Index[i] = -1;
00342
00343
00344 _BB_Bitset_Table_Index.resize(_Max_BB_id+1);
00345 for ( i = 0; i < _Max_BB_id+1; i++)
00346 _BB_Bitset_Table_Index[i] = -1;
00347
00348 _BB_Bitset_Table.resize(_BB_Count);
00349 for ( i = 0; i < _BB_Count; i++){
00350 _BB_Bitset_Table[i].in = BS_Create_Empty (_OP_Count, &_mem_pool);
00351 _BB_Bitset_Table[i].out = BS_Create_Empty (_OP_Count, &_mem_pool);
00352 _BB_Bitset_Table[i].kill = BS_Create_Empty (_OP_Count, &_mem_pool);
00353 _BB_Bitset_Table[i].gen = BS_Create_Empty (_OP_Count, &_mem_pool);
00354 _BB_Bitset_Table[i].reverse_in = BS_Create_Empty (_OP_Count, &_mem_pool);
00355 _BB_Bitset_Table[i].reverse_out = BS_Create_Empty (_OP_Count, &_mem_pool);
00356
00357 }
00358 }
00359
00360 BS*
00361 DAG_BUILDER::Union_Of_Preds(BB* bb)
00362 {
00363
00364
00365 _out = BS_Create_Empty (_OP_Count, &_mem_pool);
00366
00367 BB_VECTOR bbv(&_mem_pool);
00368
00369 Find_Ancestor_BB (bb, &bbv);
00370
00371 for (BB_VECTOR_ITER iter = bbv.begin () ;
00372 iter != bbv.end() ;
00373 iter ++) {
00374
00375 BB* pred = *iter ;
00376 BS_UnionD(_out ,
00377 _BB_Bitset_Table[Get_Table_Index(pred)].out ,
00378 &_mem_pool);
00379 }
00380 return _out;
00381
00382
00383 }
00384
00385 BS*
00386 DAG_BUILDER::Union_Of_Succs(BB* bb)
00387 {
00388
00389
00390 _reverse_out = BS_Create_Empty (_OP_Count, &_mem_pool);
00391
00392 BB_VECTOR bbv(&_mem_pool);
00393
00394 Find_Successor_BB (bb, &bbv);
00395
00396 for (BB_VECTOR_ITER iter = bbv.begin () ;
00397 iter != bbv.end() ;
00398 iter ++) {
00399
00400 BB* succ = *iter ;
00401 BS_UnionD(_reverse_out ,
00402 _BB_Bitset_Table[Get_Table_Index(succ)].reverse_out ,
00403 &_mem_pool);
00404 }
00405 return _reverse_out;
00406
00407 }
00408
00409 void
00410 DAG_BUILDER::Set_TN_BB_Bitset_Table(void)
00411 {
00412 mINT32 TN_Table_Tail=0,BB_Table_Tail=0;
00413
00414
00415 TN_BITSET_TABLE_ENTRY Blank_Entry ;
00416 Blank_Entry.def = BS_Create_Empty (_OP_Count, &_mem_pool);
00417 Blank_Entry.use = BS_Create_Empty (_OP_Count, &_mem_pool);
00418 _TN_Bitset_Table.push_back(Blank_Entry);
00419
00420
00421 for (TOPOLOGICAL_REGIONAL_CFG_ITER cfg_iter(_region->Regional_Cfg());
00422 cfg_iter != 0;
00423 ++cfg_iter) {
00424
00425 if (!(*cfg_iter)->Is_Region()) {
00426 if ( BB_entry((*cfg_iter)->BB_Node()) || BB_exit((*cfg_iter)->BB_Node()))
00427 continue;
00428
00429 BB* bb = (*cfg_iter)->BB_Node();
00430
00431 _BB_Bitset_Table[BB_Table_Tail].bb=bb;
00432
00433
00434 OP *op;
00435 FOR_ALL_BB_OPs(bb, op) {
00436 INT i;
00437 for ( i = 0; i < OP_results(op); i++) {
00438 TN *result_tn = OP_result(op,i);
00439 result_tn = set_representative_tn (result_tn);
00440
00441 if (TN_is_register(result_tn)&&!TN_is_true_pred(result_tn)) {
00442
00443
00444
00445 if (_TN_Bitset_Table_Index[ TN_number(result_tn) ] == -1) {
00446
00447 BS_Union1D(_TN_Bitset_Table[TN_Table_Tail].def,
00448 OP_To_Gid(op),
00449 &_mem_pool);
00450 _TN_Bitset_Table_Index[ TN_number(result_tn) ] = TN_Table_Tail++;
00451
00452
00453
00454 TN_BITSET_TABLE_ENTRY Blank_Entry ;
00455 Blank_Entry.def = BS_Create_Empty (_OP_Count, &_mem_pool);
00456 Blank_Entry.use = BS_Create_Empty (_OP_Count, &_mem_pool);
00457 _TN_Bitset_Table.push_back(Blank_Entry);
00458
00459 }
00460 else{
00461 BS_Union1D(_TN_Bitset_Table[Get_Table_Index(result_tn)].def,
00462 OP_To_Gid(op),
00463 &_mem_pool);
00464 }
00465
00466 }
00467 }
00468 for ( i = 0; i < OP_opnds(op); i++) {
00469 TN *opnd_tn = OP_opnd(op,i);
00470 opnd_tn = set_representative_tn (opnd_tn);
00471
00472 if (TN_is_register(opnd_tn)&&!TN_is_true_pred(opnd_tn)) {
00473
00474
00475
00476 if (_TN_Bitset_Table_Index[ TN_number(opnd_tn) ] == -1) {
00477
00478 BS_Union1D(_TN_Bitset_Table[TN_Table_Tail].use,
00479 OP_To_Gid(op),
00480 &_mem_pool);
00481 _TN_Bitset_Table_Index[ TN_number(opnd_tn) ] = TN_Table_Tail++;
00482
00483
00484
00485 TN_BITSET_TABLE_ENTRY Blank_Entry ;
00486 Blank_Entry.def = BS_Create_Empty (_OP_Count, &_mem_pool);
00487 Blank_Entry.use = BS_Create_Empty (_OP_Count, &_mem_pool);
00488 _TN_Bitset_Table.push_back(Blank_Entry);
00489
00490 }
00491 else{
00492 BS_Union1D(_TN_Bitset_Table[Get_Table_Index(opnd_tn)].use,
00493 OP_To_Gid(op),
00494 &_mem_pool);
00495 }
00496
00497 }
00498 }
00499
00500
00501 BS_Union1D(_BB_Bitset_Table[BB_Table_Tail].gen,
00502 OP_To_Gid(op),
00503 &_mem_pool);
00504 }
00505
00506 _BB_Bitset_Table_Index[BB_id(bb)]=BB_Table_Tail++;
00507
00508 }
00509 }
00510
00511
00512 for(mINT32 Current_BB=0; Current_BB<_BB_Count; Current_BB++){
00513
00514 BS* gen = BS_Create_Empty (_OP_Count, &_mem_pool);
00515 BS_CopyD( gen , _BB_Bitset_Table[Current_BB].gen , &_mem_pool );
00516
00517
00518
00519
00520 BS_CopyD(_BB_Bitset_Table[Current_BB].out , gen , &_mem_pool );
00521 BS_CopyD(_BB_Bitset_Table[Current_BB].reverse_out , gen , &_mem_pool );
00522
00523 BS_ELT elt;
00524 for ( elt = BS_Choose( gen );
00525 elt != BS_CHOOSE_FAILURE;
00526 elt = BS_Choose_Next( gen, elt ) ){
00527
00528 OP* op=Gid_To_OP(elt);
00529 for ( mINT32 i = 0; i < OP_results(op); i++) {
00530 TN *result_tn = OP_result(op,i);
00531 result_tn = set_representative_tn (result_tn);
00532
00533 if (TN_is_register(result_tn)&&!TN_is_true_pred(result_tn)) {
00534 BS_UnionD(_BB_Bitset_Table[Current_BB].kill ,
00535 _TN_Bitset_Table[Get_Table_Index(result_tn)].def ,
00536
00537 &_mem_pool);
00538
00539 BS_DifferenceD(_BB_Bitset_Table[Current_BB].kill , gen);
00540
00541 }
00542 }
00543 }
00544 }
00545
00546
00547
00548 BOOL change=TRUE;
00549 while (change){
00550
00551 change=FALSE;
00552 for(mINT32 current_bb=0; current_bb<_BB_Count; current_bb++){
00553 BS_CopyD(_BB_Bitset_Table[current_bb].in ,
00554 Union_Of_Preds( _BB_Bitset_Table[current_bb].bb ) ,&_mem_pool );
00555
00556 BS* oldout = BS_Create_Empty (_OP_Count, &_mem_pool);
00557 BS_CopyD(oldout , _BB_Bitset_Table[current_bb].out ,&_mem_pool);
00558
00559
00560 BS* tmp_set = BS_Create_Empty (_OP_Count, &_mem_pool);
00561 BS_CopyD(tmp_set , _BB_Bitset_Table[current_bb].in ,&_mem_pool);
00562
00563
00564
00565
00566 BS_UnionD(tmp_set , _BB_Bitset_Table[current_bb].gen , &_mem_pool);
00567
00568 BS_CopyD(_BB_Bitset_Table[current_bb].out , tmp_set , &_mem_pool);
00569
00570
00571 if (!BS_EqualP(tmp_set , oldout)) change = TRUE;
00572 }
00573
00574 }
00575
00576
00577
00578 BOOL changeR=TRUE;
00579 while (changeR) {
00580
00581 changeR=FALSE;
00582 for(mINT32 current_bb=0; current_bb<_BB_Count; current_bb++) {
00583
00584 BS_CopyD(_BB_Bitset_Table[current_bb].reverse_in ,
00585 Union_Of_Succs( _BB_Bitset_Table[current_bb].bb ) ,&_mem_pool );
00586
00587 BS* oldoutR = BS_Create_Empty (_OP_Count, &_mem_pool);
00588 BS_CopyD(oldoutR , _BB_Bitset_Table[current_bb].reverse_out ,&_mem_pool);
00589
00590
00591 BS* tmp_set = BS_Create_Empty (_OP_Count, &_mem_pool);
00592 BS_CopyD(tmp_set , _BB_Bitset_Table[current_bb].reverse_in ,&_mem_pool);
00593
00594
00595 BS_UnionD(tmp_set , _BB_Bitset_Table[current_bb].gen , &_mem_pool);
00596
00597 BS_CopyD(_BB_Bitset_Table[current_bb].reverse_out , tmp_set , &_mem_pool);
00598
00599
00600 if (!BS_EqualP(tmp_set , oldoutR)) changeR = TRUE;
00601 }
00602
00603 }
00604
00605 }
00606
00607 void
00608 DAG_BUILDER::Update_Max_BB_id(BB* bb)
00609 {
00610 _Max_BB_id=(BB_id(bb) > _Max_BB_id) ?
00611 BB_id(bb) :
00612 _Max_BB_id ;
00613 }
00614
00615
00616 void
00617 DAG_BUILDER::Set_Def_Use_OPs(OP *op)
00618 {
00619 INT i;
00620 for (i = 0; i < OP_results(op); i++) {
00621 TN *result_tn = OP_result(op,i);
00622 result_tn = set_representative_tn (result_tn);
00623
00624 Is_True(TN_is_register(result_tn), ("result is not register.\n"));
00625 if (!TN_is_true_pred(result_tn) &&
00626 !OP_Shadowed_By_Prev_OPs(op,
00627 _bb_def_info_map[OP_bb(op)][result_tn],
00628 OP_has_subset_predicate)) {
00629 _bb_def_info_map[OP_bb(op)][result_tn].insert(op);
00630 }
00631 }
00632
00633 for (i = 0; i < OP_opnds(op); i++) {
00634 TN *opnd_tn = OP_opnd(op,i);
00635 opnd_tn = set_representative_tn (opnd_tn);
00636
00637 if (TN_is_register(opnd_tn) &&
00638 !TN_is_true_pred(opnd_tn) &&
00639 !OP_Shadowed_By_Prev_OPs(op,
00640 _bb_use_info_map[OP_bb(op)][opnd_tn],
00641 OP_has_subset_predicate)) {
00642 _bb_use_info_map[OP_bb(op)][opnd_tn].insert(op);
00643 }
00644 }
00645 }
00646
00647 void
00648 DAG_BUILDER::Update_Max_TN_number(OP *op)
00649 {
00650 INT i;
00651 for ( i = 0; i < OP_results(op); i++) {
00652 TN *result_tn = OP_result(op,i);
00653
00654 if (TN_is_register(result_tn)&&!TN_is_true_pred(result_tn)) {
00655 _Max_TN_number=(TN_number(result_tn) > _Max_TN_number) ?
00656 TN_number(result_tn) :
00657 _Max_TN_number ;
00658 }
00659 }
00660 for ( i = 0; i < OP_opnds(op); i++) {
00661 TN *opnd_tn = OP_opnd(op,i);
00662
00663 if (TN_is_register(opnd_tn)&&!TN_is_true_pred(opnd_tn)) {
00664 _Max_TN_number=(TN_number(opnd_tn) > _Max_TN_number) ?
00665 TN_number(opnd_tn) :
00666 _Max_TN_number ;
00667 }
00668 }
00669
00670 }
00671
00672 inline
00673 void
00674 DAG_BUILDER::Set_OP_Order(OP* op)
00675 {
00676 op->order=_OP_Count;
00677 }
00678
00679 void
00680 DAG_BUILDER::Compute_Defs_Uses_In(BB* bb)
00681 {
00682 BB_VECTOR bbv(&_mem_pool);
00683
00684 Find_Ancestor_BB (bb, &bbv);
00685
00686 for (BB_VECTOR_ITER iter = bbv.begin () ;
00687 iter != bbv.end() ;
00688 iter ++) {
00689
00690 BB* pred = *iter ;
00691
00692 for (TN_OPs_MAP_ITER iter = _bb_def_info_map[pred].begin();
00693 iter != _bb_def_info_map[pred].end();
00694 iter++) {
00695 TN * tn = set_representative_tn (iter->first) ;
00696 _bb_def_info_map[bb][tn].insert(iter->second.begin(),
00697 iter->second.end());
00698 }
00699
00700 for (TN_OPs_MAP_ITER iter = _bb_use_info_map[pred].begin();
00701 iter != _bb_use_info_map[pred].end();
00702 iter++) {
00703 TN * tn = set_representative_tn (iter->first) ;
00704 _bb_use_info_map[bb][tn].insert(iter->second.begin(),
00705 iter->second.end());
00706 }
00707 }
00708 }
00709
00710 void
00711 DAG_BUILDER::Compute_OPs_In(BB* bb)
00712 {
00713 BB_VECTOR bbv(&_mem_pool);
00714
00715 Find_Ancestor_BB (bb, &bbv);
00716
00717 for (BB_VECTOR_ITER iter = bbv.begin () ;
00718 iter != bbv.end() ;
00719 iter ++) {
00720
00721 BB* pred = *iter ;
00722
00723 _bb_ops_map[bb].insert(_bb_ops_map[pred].begin(),
00724 _bb_ops_map[pred].end());
00725 }
00726 }
00727
00728
00729 BOOL
00730 DAG_BUILDER::Is_Control_Speculative(OP* pred, OP* succ)
00731 {
00732
00733 if (OP_br((OP *) pred)) {
00734 TOP opcode = OP_code(succ);
00735 if (OP_xfer(succ) || OP_volatile(succ) || OP_like_store(succ) ||
00736 TOP_is_ftrap(opcode) || TOP_is_itrap(opcode) ||
00737 TOP_is_fdiv(opcode)) {
00738 return FALSE;
00739 } else {
00740 return TRUE;
00741 }
00742 }
00743
00744 return FALSE;
00745 }
00746
00747 INT16
00748 DAG_BUILDER::Find_Ancestor_BB (BB * bb, BB_VECTOR *bbv) {
00749
00750 bbv->clear ();
00751
00752 typedef mempool_allocator<REGIONAL_CFG_NODE *> Node_ALLOC;
00753 typedef std::list<REGIONAL_CFG_NODE*,Node_ALLOC> NODE_LIST;
00754 typedef NODE_LIST::iterator NODE_LIST_ITER;
00755
00756 NODE_LIST nodes (&_mem_pool) ;
00757 nodes.push_back (Regional_Cfg_Node(bb));
00758
00759 BS * visited_rgns = BS_Create_Empty (32, &_mem_pool);
00760 for (CFG_PRED_NODE_ITER preds(Regional_Cfg_Node(bb));
00761 preds != 0; ++preds) {
00762
00763 if ((*preds)->Is_Region ()) {
00764 nodes.push_back (*preds);
00765 } else {
00766 BB * b = (*preds)->BB_Node () ;
00767 if (find (bbv->begin () , bbv->end (), b) == bbv->end() &&
00768 !BB_entry (b) &&
00769 !BB_exit (b)) {
00770 bbv->push_back (b);
00771 }
00772 }
00773 }
00774
00775 while (!nodes.empty ()) {
00776
00777 REGIONAL_CFG_NODE * n = *(nodes.begin ());
00778 nodes.erase (nodes.begin ());
00779
00780 if (n->Is_Region ()) {
00781
00782 REGION * r = n->Region_Node ();
00783 if (BS_MemberP (visited_rgns, r->Id())) {
00784 continue ;
00785 } else {
00786
00787 visited_rgns = BS_Union1D (visited_rgns,
00788 r->Id (),
00789 &_mem_pool);
00790 for (CFG_PRED_NODE_ITER ps(n); ps != 0; ++ps) {
00791
00792 if ((*ps)->Is_Region ()) {
00793
00794 if (BS_MemberP (visited_rgns, (*ps)->Region_Node()->Id())) continue ;
00795 nodes.push_back (*ps);
00796
00797 } else {
00798
00799 BB * b = (*ps)->BB_Node ();
00800 if (find (bbv->begin (), bbv->end (), b) == bbv->end() &&
00801 !BB_entry (b) &&
00802 !BB_exit (b)) {
00803 bbv->push_back (b);
00804 }
00805 }
00806 }
00807
00808 }
00809
00810 }
00811
00812 }
00813
00814 return bbv->size ();
00815 }
00816
00817 INT16
00818 DAG_BUILDER::Find_Successor_BB (BB * bb, BB_VECTOR *bbv) {
00819
00820 bbv->clear ();
00821
00822 typedef mempool_allocator<REGIONAL_CFG_NODE *> Node_ALLOC;
00823 typedef std::list<REGIONAL_CFG_NODE*,Node_ALLOC> NODE_LIST;
00824 typedef NODE_LIST::iterator NODE_LIST_ITER;
00825
00826 NODE_LIST nodes (&_mem_pool) ;
00827 nodes.push_back (Regional_Cfg_Node(bb));
00828
00829 BS * visited_rgns = BS_Create_Empty (32, &_mem_pool);
00830 for (CFG_SUCC_NODE_ITER succs(Regional_Cfg_Node(bb));
00831 succs != 0; ++succs) {
00832
00833 if ((*succs)->Is_Region ()) {
00834 nodes.push_back (*succs);
00835 } else {
00836 BB * b = (*succs)->BB_Node () ;
00837 if (find (bbv->begin () , bbv->end (), b) == bbv->end() &&
00838 !BB_entry (b) &&
00839 !BB_exit (b)) {
00840 bbv->push_back (b);
00841 }
00842 }
00843 }
00844
00845 while (!nodes.empty ()) {
00846
00847 REGIONAL_CFG_NODE * n = *(nodes.begin ());
00848 nodes.erase (nodes.begin ());
00849
00850 if (n->Is_Region ()) {
00851
00852 REGION * r = n->Region_Node ();
00853 if (BS_MemberP (visited_rgns, r->Id())) {
00854 continue ;
00855 } else {
00856
00857 visited_rgns = BS_Union1D (visited_rgns,
00858 r->Id (),
00859 &_mem_pool);
00860 for (CFG_SUCC_NODE_ITER ps(n); ps != 0; ++ps) {
00861
00862 if ((*ps)->Is_Region ()) {
00863
00864 if (BS_MemberP (visited_rgns, (*ps)->Region_Node()->Id())) continue ;
00865 nodes.push_back (*ps);
00866
00867 } else {
00868
00869 BB * b = (*ps)->BB_Node ();
00870 if (find (bbv->begin (), bbv->end (), b) == bbv->end() &&
00871 !BB_entry (b) &&
00872 !BB_exit (b)) {
00873 bbv->push_back (b);
00874 }
00875 }
00876 }
00877
00878 }
00879
00880 }
00881
00882 }
00883
00884 return bbv->size ();
00885 }
00886
00887
00888
00889
00890
00891
00892
00893 void
00894 DAG_BUILDER::Build_DAG()
00895 {
00896
00897
00898 _OP_Count=0; _BB_Count=0;_Max_TN_number=0;_Max_BB_id=0;
00899
00900 if (_region) {
00901 for (TOPOLOGICAL_REGIONAL_CFG_ITER cfg_iter(_region->Regional_Cfg());
00902 cfg_iter != 0;
00903 ++cfg_iter) {
00904
00905
00906 if (!(*cfg_iter)->Is_Region()) {
00907 if ( BB_entry((*cfg_iter)->BB_Node()) || BB_exit((*cfg_iter)->BB_Node()))
00908 continue;
00909
00910 BB* bb = (*cfg_iter)->BB_Node();
00911
00912
00913
00914 _BB_Count++;
00915 Update_Max_BB_id(bb);
00916
00917 BB_OP_MAP omap = BB_OP_MAP_Create(bb, &_mem_pool);
00918 BB_MAP_Set(_cg_dep_op_info, bb, omap);
00919
00920 OP *op;
00921 FOR_ALL_BB_OPs(bb, op) {
00922 BB_OP_MAP_Set(omap, op, new_op_info());
00923
00924
00925 Set_OP_Order(op);
00926
00927 _OP_Table.push_back(op);
00928
00929 Update_Max_TN_number(op);
00930 _OP_Count++;
00931 }
00932 }
00933 }
00934
00935
00936 #ifdef DAG_BITSET_SWITCH_ON // new version switch defined in dag.h
00937
00938
00939 Init_TN_BB_Bitset_Table();
00940
00941
00942
00943
00944
00945 Set_TN_BB_Bitset_Table();
00946 #endif
00947
00948 for (TOPOLOGICAL_REGIONAL_CFG_ITER cfg_iter(_region->Regional_Cfg());
00949 cfg_iter != 0;
00950 ++cfg_iter) {
00951
00952
00953 if (!(*cfg_iter)->Is_Region()) {
00954 if ( BB_entry((*cfg_iter)->BB_Node()) ||BB_exit((*cfg_iter)->BB_Node()))
00955 continue;
00956
00957 BB* bb = (*cfg_iter)->BB_Node();
00958
00959
00960
00961 #ifndef DAG_BITSET_SWITCH_ON
00962 Compute_Defs_Uses_In(bb);
00963 #endif
00964
00965
00966 Compute_OPs_In(bb);
00967
00968 OP *op;
00969
00970 if (BB_exit(bb)) {
00971 OP *exit_sp_adj = BB_exit_sp_adj_op(bb);
00972 for (op = exit_sp_adj; op != NULL; op = OP_prev(op)) {
00973 maybe_add_exit_sp_adj_arc (op, exit_sp_adj);
00974 }
00975 }
00976
00977 FOR_ALL_BB_OPs(bb, op) {
00978 Build_Reg_Arcs(op);
00979
00980 if (OP_load(op) || OP_like_store(op)) {
00981 Build_Mem_Arcs(op);
00982 }
00983
00984 Build_Misc_Arcs(op);
00985
00986
00987 if (_include_control_arcs) {
00988 Build_Branch_Arcs(op, TRUE);
00989 }
00990
00991
00992 _bb_ops_map[OP_bb(op)].insert(op);
00993
00994
00995 #ifndef DAG_BITSET_SWITCH_ON
00996 Set_Def_Use_OPs(op);
00997 #endif
00998 }
00999 }
01000 }
01001 } else if (_bb) {
01002 CG_DEP_Compute_Graph (
01003 _bb,
01004 INCLUDE_ASSIGNED_REG_DEPS,
01005 NON_CYCLIC,
01006 INCLUDE_MEMREAD_ARCS,
01007 INCLUDE_MEMIN_ARCS,
01008 INCLUDE_CONTROL_ARCS,
01009 NULL);
01010 adjust_reganti_latency (_bb);
01011 }
01012 }
01013
01014
01015
01016
01017 DAG_BUILDER::DAG_BUILDER(REGION* region,
01018 PRDB_GEN *prdb,
01019 BOOL assigned_regs,
01020 BOOL memread_arcs,
01021 BOOL memin_arcs,
01022 BOOL control_arcs) :
01023 _cyclic(FALSE),
01024 _prdb(prdb),
01025 _include_assigned_registers(assigned_regs),
01026 _include_memread_arcs(memread_arcs),
01027 _include_memin_arcs(memin_arcs),
01028 _include_control_arcs(control_arcs),
01029 _num_data_spec_arcs( 0 ),
01030 _num_cntl_spec_arcs( 0 ),
01031 _bb ( NULL ),
01032 _region( region ),
01033 _bb_ops_map(100, ptr_hash<BB*>(), std::equal_to<BB*>(),
01034 BB_OPs_ALLOC(&_mem_pool)),
01035 _bb_def_info_map(100, ptr_hash<BB*>(), std::equal_to<BB*>(),
01036 BB_DEF_USE_ALLOC(&_mem_pool)),
01037 _bb_use_info_map(100, ptr_hash<BB*>(), std::equal_to<BB*>(),
01038 BB_DEF_USE_ALLOC(&_mem_pool))
01039 {
01040 Invoke_Init_Routines();
01041 }
01042
01043 DAG_BUILDER::DAG_BUILDER(BB* bb,PRDB_GEN *prdb) :
01044 _prdb(prdb),
01045 _num_data_spec_arcs( 0 ),
01046 _num_cntl_spec_arcs( 0 ),
01047 _bb( bb ),
01048 _region( NULL )
01049 {}
01050
01051 DAG_BUILDER::~DAG_BUILDER()
01052 {
01053
01054 if (_region) CG_DEP_Delete_DAG();
01055 }
01056