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 #include "region.h"
00040 #include "region_update.h"
00041 #include "interval_processor.h"
00042 #include "bb.h"
00043 #include "cg_loop.h"
00044 #include "vt_region.h"
00045 #include "ipfec_defs.h"
00046 #include "tracing.h"
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 void
00066 REGION_LOOP_UPDATE::Record_Loop_Region_Boundary(LOOP_REGION *loop){
00067
00068 _bbs_not_in_loop.clear();
00069 _loop_bbs.clear();
00070
00071 if (Get_Trace(TP_A_REGION, TT_RGN_UPDATE_DEBUG)){
00072 fprintf(TFile,"before loop optimization\n");
00073 draw_global_cfg("before loop optimization");
00074 draw_regional_cfg(loop->Parent());
00075 if(loop->Parent()->Parent()){
00076 fprintf(TFile,"draw the root region \n ");
00077 draw_regional_cfg(loop->Tree()->Root());
00078 }
00079 }
00080
00081 for(INNERMOST_REGION_FIRST_ITER iter(_region_tree); iter!=0; ++iter){
00082 REGION *region = *iter;
00083 if(region == loop || region->Is_Contained_By(loop))
00084 continue;
00085 for(SEQ_REGIONAL_CFG_ITER node_iter(region->Regional_Cfg()); node_iter != 0; ++node_iter){
00086 REGIONAL_CFG_NODE *node = *node_iter;
00087 if(! node->Is_Region())
00088 _bbs_not_in_loop.push_back(node->BB_Node());
00089 }
00090 }
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 REGION *
00106 REGION_LOOP_UPDATE::Del_Loop_Region(LOOP_REGION *loop){
00107 Is_True(loop->First_Kid()==NULL, ("loop_region should be leaf region"));
00108 REGION *par = loop->Parent();
00109 _region_tree->Del_Region(loop);
00110 return par;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 void
00126 REGION_LOOP_UPDATE::Find_Loop_BBs(){
00127 for (BB *bb = _first_bb; bb != NULL; bb = BB_next(bb)) {
00128 BOOL find = FALSE;
00129 for(BB_ITER iter=_bbs_not_in_loop.begin(); iter!=_bbs_not_in_loop.end(); ++iter){
00130 if((*iter) == bb){
00131 find = TRUE;
00132 break;
00133 }
00134 }
00135 if(!find)
00136 _loop_bbs.push_back(bb);
00137 }
00138 _bbs_not_in_loop.clear();
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 void
00153 REGION_LOOP_UPDATE::Set_No_Further_Optimization(REGION *par){
00154 for(REGION_KID_ITER rgn_iter(par); rgn_iter!=0; ++rgn_iter){
00155 REGION *rgn = *rgn_iter;
00156 if(rgn->Region_Type()==LOOP){
00157 for(SEQ_REGIONAL_CFG_ITER node_iter(rgn->Regional_Cfg()); node_iter!=0; ++node_iter){
00158 if((*node_iter)->Is_Region()) continue;
00159 BB *bb = (*node_iter)->BB_Node();
00160 if(BB_scheduled(bb))
00161 rgn->Attribute(NO_FURTHER_OPTIMIZATION);
00162 }
00163 }
00164
00165 if(rgn->First_Kid())
00166 Set_No_Further_Optimization(rgn);
00167
00168 }
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 void
00183 REGION_LOOP_UPDATE::Rebuild_Loop_Region(REGION *par, BOOL succ){
00184 if (Get_Trace(TP_A_REGION, TT_RGN_SUMMERY))
00185 fprintf(TFile, "*** beginning of REGION_LOOP_UPDATE::Rebuild_Loop_Region(parent_region_id :%d)\n",
00186 par->Id());
00187
00188 Find_Loop_BBs();
00189
00190
00191
00192 if (Get_Trace(TP_A_REGION, TT_RGN_UPDATE_DEBUG)){
00193 fprintf(TFile,"added bbs are: ");
00194 for(BB_VECTOR_ITER iter=_loop_bbs.begin(); iter!=_loop_bbs.end(); iter++){
00195 fprintf(TFile,"%d ", BB_id(*iter));
00196 }
00197 fprintf(TFile,"\n");
00198 }
00199
00200 NODE_VECTOR *new_nodes = NULL;
00201 new_nodes = CXX_NEW(NODE_VECTOR(), &_m);
00202 par->Regional_Cfg()->Add_BBS_And_Edges(_loop_bbs, new_nodes);
00203
00204 if (Get_Trace(TP_A_REGION, TT_RGN_UPDATE_DEBUG)){
00205 fprintf(TFile,"after add bbs and edges \n");
00206 draw_global_cfg("after add bbs and edges");
00207 draw_regional_cfg(par);
00208 }
00209
00210 par->Regional_Cfg()->Print(TFile);
00211
00212
00213 SEME_REGION *seme=_region_tree->Add_SEME_Region(par, *new_nodes);
00214
00215 INTERVAL_PROCESSOR inter(seme);
00216 inter.Process();
00217
00218
00219 if(par->Region_Type()==LOOP){
00220 LOOP_REGION *par_loop=(LOOP_REGION *)par;
00221 for(TOPOLOGICAL_REGIONAL_CFG_ITER iter(par->Regional_Cfg()); iter!=0; ++iter){
00222 if((*iter)->First_Pred()==NULL)
00223 par_loop->Loop_Head((*iter));
00224 if((*iter)->First_Succ()==NULL)
00225 par_loop->Loop_Tail((*iter));
00226 }
00227 }
00228
00229
00230 if(succ){
00231 seme->Attribute(NO_FURTHER_OPTIMIZATION);
00232 Set_No_Further_Optimization(par);
00233 }
00234
00235 if (Get_Trace(TP_A_REGION, TT_RGN_UPDATE_DEBUG)){
00236 fprintf(TFile,"after loop optimization\n");
00237 draw_regional_cfg(par);
00238 }
00239
00240 if (Get_Trace(TP_A_REGION, TT_RGN_SUMMERY))
00241 fprintf(TFile, "*** end of REGION_LOOP_UPDATE::Rebuild_Loop_Region(parent_region_id :%d)\n",
00242 par->Id());
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 void *Record_And_Del_Loop_Region(LOOP_DESCR *loop, void *tmp){
00263 REGION_LOOP_UPDATE *rgn_loop_update = (REGION_LOOP_UPDATE *)tmp;
00264 BB *bb = BB_SET_Choose(LOOP_DESCR_bbset(loop));
00265 REGION *rgn = Home_Region(bb);
00266
00267 if (!rgn->Region_Type()==LOOP) {
00268 DevWarn("Loop Region Been Decomposed.Will Not Do Anything To It In SWP");
00269
00270 return FALSE;
00271 }
00272
00273 LOOP_REGION *loop_rgn = (LOOP_REGION *)rgn;
00274
00275
00276
00277
00278
00279
00280
00281 if(loop_rgn->First_Kid())
00282 return NULL;
00283
00284
00285
00286
00287
00288
00289 if(loop_rgn->Regional_Cfg_Node()->Is_Entry())
00290 return NULL;
00291
00292
00293 rgn_loop_update->Record_Loop_Region_Boundary(loop_rgn);
00294 void *ret = (void *)(rgn_loop_update->Del_Loop_Region(loop_rgn));
00295
00296 if (Get_Trace(TP_A_REGION, TT_RGN_UPDATE_DEBUG)){
00297 fprintf(TFile,"before loop opt and after del loop region\n");
00298 if(ret)
00299 draw_regional_cfg((REGION *)ret);
00300 }
00301
00302 return ret;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 void Rebuild_Loop_Region(void *tmp_loop_update, void *tmp_par_rgn, BOOL succ){
00316 REGION_LOOP_UPDATE *rgn_loop_update = (REGION_LOOP_UPDATE *)tmp_loop_update;
00317 REGION *par_rgn = (LOOP_REGION *)tmp_par_rgn;
00318 rgn_loop_update->Rebuild_Loop_Region(par_rgn, succ);
00319
00320 }
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 static BOOL Have_No_Across_Opt_In_Path(REGION *ance, REGION *desc){
00340
00341 Is_True(desc->Is_Contained_By(ance),
00342 ("REGION_VERIFY::Have_No_Across_Opt_In_Path"));
00343
00344 REGION *parent = desc->Parent();
00345 while(parent != ance){
00346 if(parent->Is_No_Opt_Across())
00347 return TRUE;
00348 }
00349 return FALSE;
00350 }
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 static BOOL Can_Be_Moved(REGION *src, REGION *target)
00368 {
00369 if (src->Is_No_Opt_Across()||
00370 target->Is_No_Opt_Across())
00371 return FALSE;
00372
00373 REGION *parent = src->Find_Common_Parent(target);
00374 if(parent != src){
00375 if(Have_No_Across_Opt_In_Path(parent, src))
00376 return FALSE;
00377 }
00378
00379 if(parent !=target){
00380 if(Have_No_Across_Opt_In_Path(parent,target))
00381 return FALSE;
00382 }
00383
00384 return true;
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 BOOL Can_Be_Moved(BB * src_bb, BB * target_bb){
00403 return Can_Be_Moved(Home_Region(src_bb), Home_Region(target_bb));
00404 }
00405
00406