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
00048
00049
00050
00051
00052
00053 #ifdef USE_PCH
00054 #include "opt_pch.h"
00055 #endif // USE_PCH
00056 #pragma hdrstop
00057
00058
00059 #ifdef _KEEP_RCS_ID
00060 #define opt_rvilr_CXX "opt_rvilr.cxx"
00061 static char *rcs_id = opt_rvilr_CXX"$Revision$";
00062 #endif
00063
00064 #include "defs.h"
00065 #include "errors.h"
00066 #include "erglob.h"
00067 #include "tracing.h"
00068 #include "wn.h"
00069 #include "cxx_memory.h"
00070
00071 #include "opt_defs.h"
00072 #include "opt_config.h"
00073 #include "opt_base.h"
00074 #include "opt_bb.h"
00075 #include "opt_rvilr.h"
00076 #include "opt_rvitab.h"
00077 #include "opt_rvi.h"
00078 #include "opt_util.h"
00079 #include "bb_node_set.h"
00080 #include "idx_32_set.h"
00081
00082
00083
00084
00085
00086
00087 class RVI_LR_INFO {
00088 private:
00089 BOOL _bb_mu_ref;
00090 BOOL _bb_chi_def;
00091 INT _pred_in;
00092 INT _pred_out;
00093 BOOL _pred_out_chi;
00094 BOOL _pred_out_succ_out;
00095 BOOL _pred_out_deep;
00096 BOOL _succ_has_load;
00097 INT _succ_in;
00098 INT _succ_out;
00099 BOOL _succ_out_pred_out;
00100 BOOL _succ_out_deep;
00101 BOOL _succ_out_live_out;
00102
00103 RVI_LR_INFO(const RVI_LR_INFO&);
00104 RVI_LR_INFO& operator = (const RVI_LR_INFO&);
00105
00106 public:
00107
00108 RVI_LR_INFO( void )
00109 {
00110 _bb_mu_ref = FALSE;
00111 _bb_chi_def = FALSE;
00112 _pred_in = 0;
00113 _pred_out = 0;
00114 _pred_out_chi = FALSE;
00115 _pred_out_succ_out = FALSE;
00116 _pred_out_deep = FALSE;
00117 _succ_has_load = FALSE;
00118 _succ_in = 0;
00119 _succ_out = 0;
00120 _succ_out_pred_out = FALSE;
00121 _succ_out_deep = FALSE;
00122 _succ_out_live_out = FALSE;
00123 }
00124 ~RVI_LR_INFO( void ) {}
00125
00126 BOOL Bb_mu_ref( void ) const
00127 { return _bb_mu_ref; }
00128 void Set_bb_mu_ref( void )
00129 { _bb_mu_ref = TRUE; }
00130 BOOL Bb_chi_def( void ) const
00131 { return _bb_chi_def; }
00132 void Set_bb_chi_def( void )
00133 { _bb_chi_def = TRUE; }
00134 INT Pred_in( void ) const
00135 { return _pred_in; }
00136 void Set_pred_in( INT num )
00137 { _pred_in = num; }
00138 INT Pred_out( void ) const
00139 { return _pred_out; }
00140 void Set_pred_out( INT num )
00141 { _pred_out = num; }
00142 BOOL Pred_out_chi( void ) const
00143 { return _pred_out_chi; }
00144 void Set_pred_out_chi( void )
00145 { _pred_out_chi = TRUE; }
00146 BOOL Pred_out_succ_out( void ) const
00147 { return _pred_out_succ_out; }
00148 void Set_pred_out_succ_out( void )
00149 { _pred_out_succ_out = TRUE; }
00150 BOOL Pred_out_deep( void ) const
00151 { return _pred_out_deep; }
00152 void Set_pred_out_deep( void )
00153 { _pred_out_deep = TRUE; }
00154 BOOL Succ_has_load( void ) const
00155 { return _succ_has_load; }
00156 void Set_succ_has_load( void )
00157 { _succ_has_load = TRUE; }
00158 INT Succ_in( void ) const
00159 { return _succ_in; }
00160 void Set_succ_in( INT num )
00161 { _succ_in = num; }
00162 INT Succ_out( void ) const
00163 { return _succ_out; }
00164 void Set_succ_out( INT num )
00165 { _succ_out = num; }
00166 BOOL Succ_out_pred_out( void ) const
00167 { return _succ_out_pred_out; }
00168 void Set_succ_out_pred_out( void )
00169 { _succ_out_pred_out = TRUE; }
00170 BOOL Succ_out_deep( void ) const
00171 { return _succ_out_deep; }
00172 void Set_succ_out_deep( void )
00173 { _succ_out_deep = TRUE; }
00174 BOOL Succ_out_live_out( void ) const
00175 { return _succ_out_live_out; }
00176 void Set_succ_out_live_out( void )
00177 { _succ_out_live_out = TRUE; }
00178
00179
00180 BOOL Load_should_be_in_pred( void ) const;
00181 BOOL Store_should_be_in_succ( void ) const;
00182
00183 void Print( void ) const;
00184 };
00185
00186
00187
00188
00189
00190 void
00191 RVI_LRBB::Print( FILE *fp ) const
00192 {
00193 fprintf( fp, "BB:%d, %d loads, %d stores",
00194 _bb->Id(), _load_cnt, _store_cnt );
00195 if ( First_is_store() )
00196 fprintf( fp, " STR" );
00197 if ( Need_store_bot() )
00198 fprintf( fp, " ND_STR_BOT" );
00199 if ( Need_store_succ() )
00200 fprintf( fp, " ND_STR_SUCC" );
00201 if ( Need_store_iref() )
00202 fprintf( fp, " ND_STR_IREF" );
00203 if ( Need_load_here() )
00204 fprintf( fp, " ND_LOD_HERE" );
00205 if ( Need_load_pred() )
00206 fprintf( fp, " ND_LOD_PRED" );
00207 if ( Need_load_chi() )
00208 fprintf( fp, " ND_LOD_CHI" );
00209
00210 fprintf( fp, "\n" );
00211 }
00212
00213
00214
00215
00216
00217 RVI_LRBB *
00218 RVI_LRBB_LIST::Find( const BB_NODE *bb )
00219 {
00220 RVI_LRBB_ITER lrbb_iter;
00221 RVI_LRBB *lrbb;
00222
00223 FOR_ALL_NODE( lrbb, lrbb_iter, Init(this) ) {
00224 if ( bb == lrbb->Bb() )
00225 return lrbb;
00226 }
00227
00228 return NULL;
00229 }
00230
00231
00232
00233
00234
00235 RVI_LR::RVI_LR( IDX_32 bitpos, const CFG *cfg, MEM_POOL *pool ) :
00236 _bitpos(bitpos)
00237 {
00238 _block_set = CXX_NEW(BB_NODE_SET(cfg->Total_bb_count(), cfg, pool,
00239 BBNS_EMPTY), pool);
00240 _preg = 0;
00241 _load_cnt = 0;
00242 _store_cnt = 0;
00243 _flags = LRF_NONE;
00244 }
00245
00246
00247
00248
00249
00250 void
00251 RVI_LR::Print( FILE *fp )
00252 {
00253 RVI_LRBB_ITER lrbb_iter;
00254 RVI_LRBB *lrbb;
00255
00256 fprintf( fp, " Bitpos:%d", Bitpos() );
00257
00258 if ( Preg() != 0 ) {
00259 fprintf( fp, " Preg:%d", Preg() );
00260 }
00261 if ( Load_cnt() != 0 ) {
00262 fprintf( fp, " Load_cnt:%d", Load_cnt() );
00263 }
00264 if ( Store_cnt() != 0 ) {
00265 fprintf( fp, " Store_cnt:%d", Store_cnt() );
00266 }
00267 if ( Replace_anything() ) {
00268 fprintf( fp, " Replace" );
00269 }
00270 if ( Need_home() ) {
00271 fprintf( fp, " Need_home" );
00272 }
00273 if ( Predout_nostore() ) {
00274 fprintf( fp, " Predout_nostore" );
00275 }
00276
00277 fprintf( fp, "\n" );
00278
00279 FOR_ALL_NODE( lrbb, lrbb_iter, Init(Blocks()) ) {
00280 lrbb->Print( fp );
00281 }
00282 }
00283
00284
00285
00286
00287
00288
00289
00290 void
00291 RVI::Build_up_live_range( RVI_LR *live_range, BB_NODE *bb,
00292 RVI_LRBB_LIST *appearances,
00293 BB_NODE_SET *visited_bbs, MEM_POOL *pool ) const
00294 {
00295
00296 if ( visited_bbs->MemberP( bb ) )
00297 return;
00298
00299 IDX_32 bitpos = live_range->Bitpos();
00300
00301
00302 visited_bbs->Union1D( bb );
00303
00304
00305 RVI_LRBB *lrbb = NULL;
00306 if ( bb->Loc_appear()->MemberP( bitpos ) ) {
00307
00308 RVI_LRBB_ITER lrbb_iter;
00309 RVI_LRBB *prev = NULL;
00310
00311 FOR_ALL_NODE( lrbb, lrbb_iter, Init(appearances) ) {
00312 if ( lrbb->Bb() == bb ) {
00313 lrbb = appearances->Remove( prev, lrbb );
00314 break;
00315 }
00316 else {
00317 prev = lrbb;
00318 }
00319 }
00320 Is_True( lrbb != NULL,
00321 ("Build_up_live_range: bitpos %d, bb:%d does not appear",
00322 bitpos, bb->Id()) );
00323 }
00324
00325
00326 if ( bb->Defreach()->MemberP( bitpos ) ) {
00327
00328
00329 Is_True( !live_range->Block_set()->MemberP( bb ),
00330 ("RVI::Build_up_live_range: BB:%d already a member for bit %d",
00331 bb->Id(), bitpos) );
00332
00333
00334 if ( lrbb == NULL ) {
00335
00336
00337 lrbb = CXX_NEW(RVI_LRBB(bb),pool);
00338 }
00339
00340
00341 live_range->Blocks()->Prepend( lrbb );
00342 live_range->Block_set()->Union1D( bb );
00343
00344
00345
00346 BB_NODE *pred, *succ;
00347 BB_LIST_ITER bb_list_iter;
00348 FOR_ALL_ELEM( pred, bb_list_iter, Init(bb->Pred()) ) {
00349 if ( ! visited_bbs->MemberP( pred ) ) {
00350
00351
00352
00353
00354
00355
00356 BOOL visit_pred = TRUE;
00357 if ( visit_pred && Has_end_chi_list(pred) ) {
00358 const IDX_32_SET *pred_chi = Bb_end_chi_list(pred);
00359 if ( pred_chi != NULL && pred_chi->MemberP(bitpos) ) {
00360 if ( pred->Last_stid_bitpos() == bitpos ) {
00361
00362
00363
00364 }
00365 else {
00366 visit_pred = FALSE;
00367 }
00368 }
00369 }
00370
00371 if ( visit_pred ) {
00372 Build_up_live_range( live_range, pred, appearances,
00373 visited_bbs, pool );
00374 }
00375 }
00376
00377 if ( ! live_range->Block_set()->MemberP( pred ) ) {
00378
00379
00380
00381 if ( ! lrbb->First_is_store() ) {
00382 live_range->Set_predout_nostore();
00383 }
00384 }
00385 }
00386
00387
00388
00389
00390
00391
00392 BOOL visit_succs = TRUE;
00393 if ( visit_succs && Has_end_chi_list(bb) ) {
00394 const IDX_32_SET *pred_chi = Bb_end_chi_list(bb);
00395 if ( pred_chi != NULL && pred_chi->MemberP(bitpos) ) {
00396 if ( bb->Last_stid_bitpos() == bitpos ) {
00397
00398
00399 }
00400 else {
00401 visit_succs = FALSE;
00402 }
00403 }
00404 }
00405
00406 if ( visit_succs ) {
00407 FOR_ALL_ELEM( succ, bb_list_iter, Init(bb->Succ()) ) {
00408 if ( ! visited_bbs->MemberP( succ ) ) {
00409 Build_up_live_range( live_range, succ, appearances,
00410 visited_bbs, pool );
00411 }
00412 }
00413 }
00414
00415 }
00416 }
00417
00418
00419
00420
00421
00422 void
00423 RVI::Build_live_ranges( RVI_NODE *rvi_node, MEM_POOL *pool ) const
00424 {
00425 RVI_LRBB *lrbb, *prev_lrbb;
00426 BB_NODE_SET visited( Cfg()->Last_bb_id()+1, Cfg(), pool, BBNS_EMPTY );
00427
00428
00429
00430
00431
00432
00433 prev_lrbb = NULL;
00434 while ( (lrbb = rvi_node->Appearances()->Head()) != NULL ) {
00435
00436 Is_True( lrbb != prev_lrbb,
00437 ("RVI::Build_live_range (rvi_node:%d): no progress made (bb:%d)",
00438 rvi_node->Bitpos(), lrbb->Bb()->Id()) );
00439 prev_lrbb = lrbb;
00440
00441 if ( rvi_node->Live_ranges() == NULL ) {
00442 rvi_node->Set_live_ranges(CXX_NEW(RVI_LR_LIST(), pool));
00443 }
00444
00445
00446 RVI_LR *lr = CXX_NEW(RVI_LR(rvi_node->Bitpos(),Cfg(),pool), pool);
00447 rvi_node->Live_ranges()->Prepend(lr);
00448
00449
00450 Build_up_live_range( lr, lrbb->Bb(),
00451 rvi_node->Appearances(), &visited, pool );
00452 }
00453 }
00454
00455
00456
00457
00458
00459
00460
00461 void
00462 RVI_LR::Analyze_preds( const BB_NODE *bb, const RVI *rvi,
00463 RVI_LR_INFO *lr_info )
00464 {
00465 BB_LIST_ITER bb_pred_iter;
00466 BB_NODE *pred;
00467 FOR_ALL_ELEM( pred, bb_pred_iter, Init(bb->Pred()) ) {
00468 BOOL pred_in_lr = Block_set()->MemberP( pred );
00469
00470
00471 if ( rvi->Has_end_chi_list(pred) ) {
00472 const IDX_32_SET *pred_chi = rvi->Bb_end_chi_list(pred);
00473 if ( pred_chi != NULL && pred_chi->MemberP(Bitpos()) ) {
00474
00475
00476 pred_in_lr = FALSE;
00477 lr_info->Set_pred_out_chi();
00478 }
00479 }
00480
00481 if ( pred_in_lr ) {
00482 lr_info->Set_pred_in( lr_info->Pred_in() + 1 );
00483 }
00484 else {
00485
00486 lr_info->Set_pred_out( lr_info->Pred_out() + 1 );
00487
00488
00489 if ( pred->Loopdepth() > bb->Loopdepth() )
00490 lr_info->Set_pred_out_deep();
00491
00492
00493
00494 if ( ! lr_info->Pred_out_succ_out() ) {
00495 BB_LIST_ITER bb_predsucc_iter;
00496 BB_NODE *predsucc;
00497 FOR_ALL_ELEM( predsucc, bb_predsucc_iter, Init(pred->Succ()) ) {
00498 if ( ! Block_set()->MemberP( predsucc ) ) {
00499 lr_info->Set_pred_out_succ_out();
00500 }
00501 else if ( predsucc != bb ) {
00502
00503
00504
00505
00506 RVI_LRBB *predsucc_lrbb = Blocks()->Find( predsucc );
00507 if ( predsucc_lrbb->First_is_store() ||
00508 predsucc_lrbb->Need_load_here() )
00509 {
00510
00511
00512
00513 lr_info->Set_pred_out_succ_out();
00514 }
00515 }
00516 }
00517 }
00518 }
00519 }
00520 }
00521
00522
00523
00524
00525
00526
00527
00528 void
00529 RVI_LR::Analyze_succs( const BB_NODE *bb, const RVI *rvi,
00530 RVI_LR_INFO *lr_info )
00531 {
00532 BOOL maybe_live_out = FALSE;
00533
00534
00535 if ( rvi->Has_end_mu_list(bb) ) {
00536 const IDX_32_SET *bb_mu = rvi->Bb_end_mu_list(bb);
00537 if ( bb_mu != NULL && bb_mu->MemberP(Bitpos()) ) {
00538 lr_info->Set_bb_mu_ref();
00539 }
00540 }
00541
00542
00543 if ( rvi->Has_end_chi_list(bb) ) {
00544 const IDX_32_SET *bb_chi = rvi->Bb_end_chi_list(bb);
00545 if ( bb_chi != NULL && bb_chi->MemberP(Bitpos()) ) {
00546 lr_info->Set_bb_chi_def();
00547 Is_True( bb->Last_stid_bitpos() != Bitpos(),
00548 ("RVI_LR::Analyze_succs: Bb_end_chi_list kills last_stid") );
00549 }
00550 }
00551
00552
00553 if ( bb->Live_out()->MemberP( Bitpos() ) ) {
00554 maybe_live_out = TRUE;
00555
00556
00557 if ( rvi->Is_exit_block(bb) ) {
00558 lr_info->Set_succ_out_live_out();
00559 }
00560 }
00561
00562
00563
00564 if ( ! lr_info->Bb_mu_ref() || bb->Last_stid_bitpos() == Bitpos() ) {
00565 BB_LIST_ITER bb_succ_iter;
00566 BB_NODE *succ;
00567 FOR_ALL_ELEM( succ, bb_succ_iter, Init(bb->Succ()) ) {
00568 BOOL succ_in_lr = Block_set()->MemberP( succ );
00569
00570 if ( succ_in_lr ) {
00571 lr_info->Set_succ_in( lr_info->Succ_in() + 1 );
00572
00573 RVI_LRBB *succlrbb = Blocks()->Find( succ );
00574 Is_True( succlrbb != NULL,
00575 ("RVI_LR::Analyze_succs: successor BB:%d has no lrbb",
00576 succ->Id()) );
00577
00578 if ( succlrbb->Need_load_here() ) {
00579 lr_info->Set_succ_has_load();
00580 }
00581 else if ( succlrbb->Need_load_chi() &&
00582 lr_info->Bb_chi_def() )
00583 {
00584
00585
00586
00587
00588
00589 lr_info->Set_succ_has_load();
00590 }
00591 }
00592 else {
00593
00594 lr_info->Set_succ_out( lr_info->Succ_out() + 1 );
00595
00596
00597 if ( succ->Loopdepth() > bb->Loopdepth() )
00598 lr_info->Set_succ_out_deep();
00599
00600 if ( maybe_live_out ) {
00601
00602 if ( succ->Loc_upwd()->MemberP( Bitpos() ) ) {
00603
00604
00605 lr_info->Set_succ_out_live_out();
00606 }
00607 else if ( succ->Live_out()->MemberP( Bitpos() ) ) {
00608
00609
00610 if ( ! succ->Loc_def()->MemberP( Bitpos() ) ) {
00611 lr_info->Set_succ_out_live_out();
00612 }
00613 }
00614 }
00615
00616
00617
00618
00619 if ( ! lr_info->Succ_out_pred_out() ) {
00620 BB_LIST_ITER bb_succpred_iter;
00621 BB_NODE *succpred;
00622 FOR_ALL_ELEM(succpred, bb_succpred_iter, Init(succ->Pred())) {
00623 if ( ! Block_set()->MemberP( succpred ) ) {
00624 lr_info->Set_succ_out_pred_out();
00625 }
00626 else {
00627
00628
00629
00630
00631 if ( rvi->Has_end_chi_list(succpred) ) {
00632 const IDX_32_SET *succpred_chi =
00633 rvi->Bb_end_chi_list(succpred);
00634 if ( succpred_chi != NULL &&
00635 succpred_chi->MemberP(Bitpos()) )
00636 {
00637
00638
00639
00640 lr_info->Set_succ_out_pred_out();
00641 }
00642 }
00643 }
00644 }
00645
00646 }
00647 }
00648 }
00649
00650 }
00651 }
00652
00653
00654
00655
00656
00657
00658 inline BOOL
00659 RVI_LR_INFO::Load_should_be_in_pred( void ) const
00660 {
00661
00662
00663 if ( Pred_out_succ_out() )
00664 return FALSE;
00665
00666
00667
00668
00669
00670 if ( Pred_out() == 0 || Pred_out() > Pred_in() )
00671 return FALSE;
00672
00673
00674 if ( Pred_out_deep() )
00675 return FALSE;
00676
00677 return TRUE;
00678 }
00679
00680
00681
00682
00683
00684
00685 inline BOOL
00686 RVI_LR_INFO::Store_should_be_in_succ( void ) const
00687 {
00688
00689
00690 if ( Succ_out_pred_out() )
00691 return FALSE;
00692
00693
00694
00695
00696
00697 if ( Succ_out() == 0 || Succ_out() > Succ_in() )
00698 return FALSE;
00699
00700
00701 if ( Succ_out_deep() )
00702 return FALSE;
00703
00704 return TRUE;
00705 }
00706
00707
00708
00709
00710 void
00711 RVI_LR_INFO::Print( void ) const
00712 {
00713 fprintf( TFile, " p-in:%d p-out:%d s-in:%d s-out:%d\n",
00714 Pred_in(), Pred_out(), Succ_in(), Succ_out() );
00715
00716 if ( Bb_mu_ref() )
00717 fprintf( TFile, " Bb_mu_ref" );
00718
00719 if ( Bb_chi_def() )
00720 fprintf( TFile, " Bb_chi_def" );
00721
00722 if ( Pred_out_chi() )
00723 fprintf( TFile, " Pred_out_chi" );
00724
00725 if ( Pred_out_succ_out() )
00726 fprintf( TFile, " Pred_out_succ_out" );
00727
00728 if ( Pred_out_deep() )
00729 fprintf( TFile, " Pred_out_deep" );
00730
00731 if ( Succ_has_load() )
00732 fprintf( TFile, " Succ_has_load" );
00733
00734 if ( Succ_out_pred_out() )
00735 fprintf( TFile, " Succ_out_pred_out" );
00736
00737 if ( Succ_out_deep() )
00738 fprintf( TFile, " Succ_out_deep" );
00739
00740 if ( Succ_out_live_out() )
00741 fprintf( TFile, " Succ_out_live_out" );
00742
00743 fprintf( TFile, "\n" );
00744 }
00745
00746
00747
00748
00749
00750 BOOL
00751 RVI_LR::Do_anything( void )
00752 {
00753
00754 if ( Load_cnt() > 1 || Store_cnt() > 1 )
00755 return TRUE;
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 RVI_LRBB_ITER lrbb_iter;
00766 RVI_LRBB *lrbb, *first_lrbb = NULL;
00767 INT count = 0;
00768 FOR_ALL_NODE( lrbb, lrbb_iter, Init( Blocks() ) ) {
00769 count++;
00770
00771
00772 if ( count > 1 )
00773 return TRUE;
00774
00775
00776
00777 BB_NODE *bb = lrbb->Bb();
00778 if ( bb->Loopdepth() > 0 )
00779 return TRUE;
00780
00781
00782
00783
00784 first_lrbb = lrbb;
00785 }
00786
00787
00788
00789 if ( Load_cnt() == 1 && Store_cnt() == 1 ) {
00790
00791
00792 if ( ! (first_lrbb->Need_store() && first_lrbb->Need_load()) ) {
00793 return TRUE;
00794 }
00795 }
00796
00797 return FALSE;
00798 }
00799
00800
00801
00802
00803
00804 void
00805 RVI::Analyze_live_range( RVI_LR *live_range ) const
00806 {
00807 RVI_LRBB_ITER lrbb_iter;
00808 RVI_LRBB *lrbb;
00809 BOOL need_home = FALSE;
00810 IDX_32 bitpos = live_range->Bitpos();
00811
00812
00813 FOR_ALL_NODE( lrbb, lrbb_iter, Init( live_range->Blocks() ) ) {
00814 BB_NODE *bb = lrbb->Bb();
00815 UINT loads = lrbb->Load_cnt();
00816 if ( loads > 0 ) {
00817 live_range->Set_load_cnt(live_range->Load_cnt() + loads );
00818 }
00819 UINT stores = lrbb->Store_cnt();
00820 if ( stores > 0 ) {
00821 live_range->Set_store_cnt( live_range->Store_cnt() + stores );
00822 }
00823 }
00824
00825
00826
00827
00828
00829
00830 if ( live_range->Load_cnt() > 0 || live_range->Predout_nostore() ) {
00831 FOR_ALL_NODE( lrbb, lrbb_iter, Init( live_range->Blocks() ) ) {
00832 BB_NODE *bb = lrbb->Bb();
00833
00834 RVI_LR_INFO lr_info;
00835 live_range->Analyze_preds( bb, this, &lr_info );
00836
00837 #ifdef DEBUGGING
00838 if(Tracing()){
00839 fprintf( TFile, "Analyze_preds for bitpos:%d in bb:%d\n", bitpos,
00840 bb->Id());
00841 lr_info.Print();
00842 }
00843 #endif // DEBUGGING
00844
00845 if ( lr_info.Pred_out() > 0 ) {
00846
00847 if ( ! lrbb->First_is_store() ) {
00848
00849
00850
00851 if ( lr_info.Load_should_be_in_pred() ) {
00852 if ( lr_info.Pred_out_chi() ) {
00853
00854
00855 lrbb->Set_need_load_chi();
00856 }
00857 else {
00858 lrbb->Set_need_load_pred();
00859 }
00860 }
00861 else {
00862 lrbb->Set_need_load_here();
00863 }
00864
00865
00866 need_home = TRUE;
00867 }
00868 }
00869 }
00870 }
00871
00872
00873
00874 if ( live_range->Store_cnt() > 0 ) {
00875 FOR_ALL_NODE( lrbb, lrbb_iter, Init( live_range->Blocks() ) ) {
00876 BB_NODE *bb = lrbb->Bb();
00877
00878
00879 if ( bb->Unstored_defs()->MemberP(bitpos) ||
00880 bb->Last_stid_bitpos() == bitpos )
00881 {
00882
00883
00884
00885 if ( lrbb->Need_load_here() && lrbb->Store_cnt() == 0 )
00886 continue;
00887
00888 RVI_LR_INFO lr_info;
00889 live_range->Analyze_succs( bb, this, &lr_info );
00890
00891 #ifdef DEBUGGING
00892 if(Tracing()){
00893 fprintf( TFile, "Analyze_succs for bitpos:%d in bb:%d\n", bitpos,
00894 bb->Id());
00895 lr_info.Print();
00896 }
00897 #endif // DEBUGGING
00898
00899
00900
00901 BOOL may_need_to_store_after = TRUE;
00902
00903
00904
00905 if ( lr_info.Bb_mu_ref() &&
00906 bb->Unstored_defs()->MemberP(bitpos) )
00907 {
00908 lrbb->Set_need_store_iref();
00909
00910 need_home = TRUE;
00911
00912
00913
00914
00915
00916
00917
00918 {
00919 BB_NODE *bb = lrbb->Bb();
00920 RVI_LR_INFO lr_info;
00921 live_range->Analyze_preds(bb, this, &lr_info);
00922 if (lr_info.Pred_out() > 0) {
00923
00924 BOOL need_load_pred = TRUE;
00925 if (bb->Loc_mu_wn() != NULL) {
00926 for (WN *stmt = WN_prev(bb->Loc_mu_wn()); stmt != NULL; stmt = WN_prev(stmt)) {
00927 if (WN_operator(stmt) == OPR_STID && Get_bitpos(stmt) == bitpos) {
00928 need_load_pred = FALSE;
00929 break;
00930 }
00931 }
00932 }
00933 if (need_load_pred)
00934 lrbb->Set_need_load_pred();
00935 }
00936 }
00937
00938
00939
00940 if ( bb->Last_stid_bitpos() != bitpos ) {
00941 may_need_to_store_after = FALSE;
00942 }
00943 }
00944
00945 if ( may_need_to_store_after ) {
00946
00947
00948
00949
00950 if ( bb->Last_stid_bitpos() == bitpos &&
00951 bb->Last_stid_has_chi() )
00952 {
00953 may_need_to_store_after = FALSE;
00954
00955
00956 need_home = TRUE;
00957 }
00958 }
00959
00960 #ifdef DEBUGGING
00961 if(Tracing()){
00962 fprintf( TFile, " may_need_to_store_after=%d\n",
00963 may_need_to_store_after );
00964 }
00965 #endif // DEBUGGING
00966
00967 if ( may_need_to_store_after ) {
00968 if ( lr_info.Succ_has_load() ) {
00969 if ( lr_info.Bb_chi_def() ) {
00970 lrbb->Set_need_store_iref();
00971 }
00972 else {
00973 lrbb->Set_need_store_bot();
00974 }
00975
00976
00977 need_home = TRUE;
00978 }
00979 else if ( lr_info.Succ_out() > 0 ) {
00980
00981 if ( lr_info.Succ_out_live_out() ) {
00982
00983
00984
00985 if ( lr_info.Bb_chi_def() ) {
00986 lrbb->Set_need_store_iref();
00987 }
00988 else if ( lr_info.Store_should_be_in_succ() ) {
00989 lrbb->Set_need_store_succ();
00990 }
00991 else {
00992 lrbb->Set_need_store_bot();
00993 }
00994
00995
00996 need_home = TRUE;
00997 }
00998 }
00999 }
01000 }
01001 }
01002 }
01003
01004
01005
01006 if ( live_range->Do_anything() ) {
01007 live_range->Set_replace_anything();
01008
01009
01010
01011
01012 if ( need_home ) {
01013 live_range->Set_need_home();
01014 }
01015 }
01016
01017 }
01018