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
00054
00055
00056
00057
00058
00059
00060
00061
00062 #include "defs.h"
00063 #include "wn.h"
00064 #include "cg.h"
00065 #include "cg_internal.h"
00066 #include "cg_flags.h"
00067 #include "config.h"
00068 #include "config_list.h"
00069 #include "tracing.h"
00070 #include "timing.h"
00071 #include "strtab.h"
00072 #include "cgir.h"
00073 #include "erglob.h"
00074 #include "ercg.h"
00075 #include "data_layout.h"
00076 #include "whirl2ops.h"
00077 #include "calls.h"
00078 #include "bitset.h"
00079 #include "tn_set.h"
00080 #include "gtn_universe.h"
00081 #include "bb_set.h"
00082 #include "register.h"
00083 #include "gra.h"
00084 #include "freq.h"
00085 #include "fb_whirl.h"
00086 #include "lra.h"
00087 #include "cgemit.h"
00088 #include "cg_loop.h"
00089 #include "glob.h"
00090 #include "cgexp.h"
00091 #include "igls.h"
00092 #include "tn_map.h"
00093 #include "cg_region.h"
00094 #include "wn_util.h"
00095 #include "cg_spill.h"
00096 #include "localize.h"
00097 #include "gra_live.h"
00098 #include "opt_alias_interface.h"
00099 #include "ir_reader.h"
00100 #include "cflow.h"
00101 #include "dwarf_DST_mem.h"
00102 #include "region_util.h"
00103 #include "eh_region.h"
00104 #include "reg_live.h"
00105 #include "findloops.h"
00106 #include "cgdriver.h"
00107 #include "label_util.h"
00108 #include "cgtarget.h"
00109 #include "ebo.h"
00110 #include "hb.h"
00111 #include "pqs_cg.h"
00112 #include "tag.h"
00113 #ifdef TARG_IA64
00114 #include "ipfec.h"
00115 #include "ipfec_defs.h"
00116 #include "ipfec_options.h"
00117 #include "region_update.h"
00118 #include "region_verify.h"
00119 #include "vt_region.h"
00120 #include "recovery.h"
00121 #include "edge_profile.h"
00122 #include "val_prof.h"
00123 #include "bb_verifier.h"
00124 #include "config_opt.h"
00125 #include "be_util.h"
00126 #include "stride_prefetch.h"
00127 #include "cache_analysis.h"
00128 #include "multi_branch.h"
00129
00130 #define _value_profile_before_region_formation
00131 #define can_invoke_profile_with_current_cg_opt_level (CG_opt_level>1)
00132
00133 #endif
00134 #ifdef KEY
00135 #include "cg_gcov.h"
00136 #endif
00137 #ifdef TARG_NVISA
00138 #include "dominate.h"
00139 #include "vector_loadstore.h"
00140 #endif
00141 #if defined(TARG_SL)
00142 #include "region.h"
00143 #include "region_update.h"
00144 #include "scheduler.h"
00145 #include "disp_instr.h"
00146 #endif
00147
00148 MEM_POOL MEM_local_region_pool;
00149 MEM_POOL MEM_local_region_nz_pool;
00150
00151 BOOL Trace_REGION_Interface = FALSE;
00152
00153 #ifdef TARG_IA64
00154 INT32 current_PU_handle = 0;
00155 INT32 rse_budget;
00156 #endif
00157
00158 BOOL PU_Has_Calls;
00159 BOOL PU_References_GP;
00160 #ifdef TARG_IA64
00161 BOOL GRA_optimize_restore_pr;
00162 BOOL GRA_optimize_restore_b0_ar_pfs;
00163 BOOL GRA_optimize_restore_ar_lc;
00164 BOOL EBO_data_spec;
00165
00166 typedef mempool_allocator<INT> INT_ALLOC;
00167 typedef std::vector<INT, INT_ALLOC> INT_CONTAINER;
00168 #endif
00169 #if defined(TARG_IA64) || defined(TARG_SL) || defined(TARG_MIPS)
00170 BOOL RGN_Formed = FALSE;
00171 #endif
00172
00173 #ifdef KEY
00174 BOOL PU_Has_Exc_Handler;
00175 BOOL PU_Has_Nonlocal_Goto_Target;
00176 BOOL CG_file_scope_asm_seen = FALSE;
00177 #endif
00178
00179 BOOL gra_pre_create = TRUE;
00180 #ifdef TARG_X8664
00181 BOOL PU_References_GOT;
00182 #endif
00183
00184 BOOL edge_done = FALSE;
00185 BOOL CG_PU_Has_Feedback;
00186 RID *Current_Rid;
00187
00188 TN_MAP TN_To_PREG_Map;
00189 #ifdef TARG_X8664
00190 BB_MAP BBs_Map = NULL;
00191 #endif
00192
00193 #ifdef TARG_X8664
00194 extern BOOL cg_load_execute_overridden;
00195 #endif
00196
00197
00198 struct ALIAS_MANAGER *Alias_Manager;
00199
00200 static BOOL Orig_Enable_SWP;
00201 #ifdef TARG_IA64
00202 extern BOOL gra_self_recursive;
00203 extern BOOL fat_self_recursive;
00204 #endif
00205
00206 #if defined(TARG_SL) || defined(TARG_MIPS)
00207 REGISTER_SET caller_saved_regs_used[ISA_REGISTER_CLASS_MAX+1];
00208 #endif
00209
00210
00211 void
00212 CG_PU_Initialize (WN *wn_pu)
00213 {
00214 static INT pu_num;
00215
00216 MEM_POOL_Push ( &MEM_phase_pool );
00217 MEM_POOL_Push ( &MEM_local_pool );
00218 MEM_POOL_Push ( &MEM_phase_nz_pool );
00219 MEM_POOL_Push ( &MEM_local_nz_pool );
00220
00221 PU_Has_Calls = FALSE;
00222 PU_References_GP = FALSE;
00223
00224 #if defined(TARG_SL) || defined(TARG_MIPS)
00225 ISA_REGISTER_CLASS rc;
00226 FOR_ALL_ISA_REGISTER_CLASS(rc)
00227 caller_saved_regs_used[rc] = REGISTER_SET_EMPTY_SET;
00228 #endif
00229
00230 #ifdef TARG_IA64
00231 GRA_optimize_restore_pr = TRUE;
00232 GRA_optimize_restore_b0_ar_pfs = TRUE;
00233 GRA_optimize_restore_ar_lc = TRUE;
00234 EBO_data_spec=FALSE;
00235 #endif
00236
00237 #ifdef KEY
00238 PU_Has_Exc_Handler = FALSE;
00239 PU_Has_Nonlocal_Goto_Target = PU_has_nonlocal_goto_label(Get_Current_PU());
00240 #endif
00241
00242 #ifdef TARG_X8664
00243 if (! cg_load_execute_overridden) {
00244 if ((Is_Target_EM64T() || Is_Target_Core() || Is_Target_Wolfdale()) &&
00245 PU_src_lang(Get_Current_PU()) != PU_C_LANG) {
00246 CG_load_execute = 0;
00247 } else if (! Is_Target_32bit() &&
00248 (PU_src_lang(Get_Current_PU()) == PU_F77_LANG ||
00249 PU_src_lang(Get_Current_PU()) == PU_F90_LANG)) {
00250 CG_load_execute = 2;
00251 } else {
00252 CG_load_execute = 1;
00253 }
00254 }
00255
00256 PU_References_GOT = FALSE;
00257
00258 if (CG_localize_x87_tns && Is_Target_SSE2()) {
00259 fprintf(stderr,
00260 "Ignoring CG_localize_x87_tns since it has no effect under SSE2\n");
00261 CG_localize_x87_tns = FALSE;
00262 }
00263 if (CG_x87_store && Is_Target_SSE2()) {
00264 fprintf(stderr,
00265 "Ignoring CG_x87_store since it has no effect under SSE2\n");
00266 CG_x87_store = FALSE;
00267 }
00268
00269
00270 if (!LOCS_Scheduling_Algorithm_set) {
00271 if (Is_Target_32bit()) {
00272
00273 LOCS_Scheduling_Algorithm = 1;
00274 } else {
00275
00276 LOCS_Scheduling_Algorithm = PU_ftn_lang(Get_Current_PU()) ? 2 : 0;
00277 }
00278 }
00279
00280 if (PU_cxx_lang(Get_Current_PU()) && Is_Target_64bit()) {
00281 if (!GRA_prioritize_by_density_set)
00282 GRA_prioritize_by_density = TRUE;
00283 if (!GRA_optimize_boundary_set)
00284 GRA_optimize_boundary = TRUE;
00285 }
00286 #endif
00287
00288 Regcopies_Translated = FALSE;
00289 #if defined(TARG_SL)
00290
00291
00292
00293 bool skip = false;
00294
00295 if( CG_skip_before > 0 ) {
00296 if( CG_skip_after < INT32_MAX ) {
00297 if( pu_num > CG_skip_after && pu_num < CG_skip_before )
00298 skip = true;
00299 } else if ( pu_num < CG_skip_before ){
00300 skip = true;
00301 }
00302 } else {
00303 if( CG_skip_after >= 0 )
00304 if( pu_num > CG_skip_after )
00305 skip = true;
00306 }
00307
00308 if( CG_skip_equal >= 0 ) {
00309 if( pu_num == CG_skip_equal )
00310 skip = true;
00311 }
00312
00313 CG_Configure_Opt_Level( skip ? 0 : Opt_Level);
00314 #else
00315 CG_Configure_Opt_Level(( pu_num < CG_skip_before
00316 || pu_num > CG_skip_after
00317 || pu_num == CG_skip_equal)
00318 ? 0 : Opt_Level);
00319 #endif // TARG_SL
00320 pu_num++;
00321
00322 if (PU_has_syscall_linkage(Get_Current_PU())) {
00323
00324 Orig_Enable_SWP = Enable_SWP;
00325 Enable_SWP = FALSE;
00326 }
00327
00328 Reuse_Temp_TNs = (CG_opt_level == 0);
00329 if (Get_Trace (TP_CGEXP, 1024)) Reuse_Temp_TNs = FALSE;
00330
00331 CGTARG_Initialize();
00332 BB_PU_Initialize ();
00333 Init_TNs_For_PU ();
00334 LOOP_DESCR_Init_For_PU();
00335 TN_MAP_Init();
00336 BB_MAP_Init();
00337 #ifdef TARG_IA64
00338 REGION_MAP_Init();
00339 #endif
00340 OP_MAP_Init();
00341 CFLOW_Initialize();
00342 #if !defined (TARG_NVISA)
00343 CGSPILL_Initialize_For_PU ();
00344 CG_LOOP_Init();
00345 HB_Init();
00346 if (Enable_CG_Peephole) EBO_Init();
00347 #endif
00348 Init_Label_Info();
00349
00350 #ifdef EMULATE_LONGLONG
00351 extern void Init_TN_Pair();
00352 Init_TN_Pair ();
00353 #endif
00354
00355
00356 REGISTER_Pu_Begin();
00357
00358 Init_Entry_Exit_Code (wn_pu);
00359 REGISTER_Reset_FP();
00360
00361 #ifndef TARG_NVISA
00362
00363 GTN_UNIVERSE_Pu_Begin();
00364
00365 Trace_REGION_Interface = Get_Trace( TP_REGION, TT_REGION_CG_DEBUG ) ||
00366 Get_Trace(TP_REGION, TT_REGION_BOUND_DEBUG );
00367
00368 Init_gen_quad_preg();
00369 #endif
00370
00371
00372
00373
00374 if (Get_Trace (TKIND_ALLOC, TP_CG)) {
00375
00376 MEM_Tracing_Enable();
00377 }
00378
00379 }
00380
00381 void
00382 CG_PU_Finalize(void)
00383 {
00384 TAG_Finish();
00385 OP_MAP_Finish();
00386 #ifndef TARG_NVISA
00387 GTN_UNIVERSE_Pu_End ();
00388 CGSPILL_Finalize_For_PU();
00389 if (Enable_CG_Peephole) EBO_Finalize();
00390
00391 if (PU_has_syscall_linkage(Get_Current_PU())) {
00392 Enable_SWP = Orig_Enable_SWP;
00393 }
00394 #endif
00395
00396
00397
00398 TN_MAP_Delete(TN_To_PREG_Map);
00399 TN_To_PREG_Map = NULL;
00400
00401 #ifdef TARG_X8664
00402 BB_MAP_Delete( BBs_Map );
00403 BBs_Map = NULL;
00404
00405 Expand_Finish();
00406 #endif
00407
00408 Free_BB_Memory();
00409 MEM_POOL_Pop ( &MEM_local_pool );
00410 MEM_POOL_Pop ( &MEM_local_nz_pool );
00411 MEM_POOL_Pop ( &MEM_phase_pool );
00412 MEM_POOL_Pop ( &MEM_phase_nz_pool );
00413 #ifdef TARG_SL
00414 Expand_Finish();
00415 #endif
00416 }
00417
00418
00419 static void
00420 CG_Region_Initialize (WN *rwn, struct ALIAS_MANAGER *alias_mgr)
00421 {
00422 MEM_POOL_Push (&MEM_local_region_pool);
00423 MEM_POOL_Push (&MEM_local_region_nz_pool);
00424 Init_CG_Expand ();
00425 #ifndef TARG_NVISA
00426 FREQ_Region_Initialize ();
00427 BB_REGION_Initialize ();
00428 LRA_Init();
00429 GRA_Initialize();
00430 #endif
00431 Init_TNs_For_REGION ();
00432
00433
00434
00435
00436
00437
00438 PREG_NUM last_preg_num;
00439 last_preg_num = Get_Preg_Num (PREG_Table_Size(CURRENT_SYMTAB))+1;
00440 PREG_To_TN_Array = (TN **) Pu_Alloc (sizeof (TN *) * last_preg_num);
00441 PREG_To_TN_Mtype = (TYPE_ID *) Pu_Alloc (sizeof (TYPE_ID) * last_preg_num);
00442
00443 PREG_To_TN_Clear();
00444 if (TN_To_PREG_Map == NULL)
00445 TN_To_PREG_Map = TN_MAP_Create();
00446
00447 #ifdef TARG_X8664
00448 if( BBs_Map == NULL ){
00449 BBs_Map = BB_MAP_Create();
00450 }
00451 #endif
00452
00453 TN_CORRESPOND_Free();
00454
00455 #ifndef TARG_NVISA
00456 GTN_UNIVERSE_REGION_Begin();
00457 #endif
00458
00459 Whirl2ops_Initialize(alias_mgr);
00460
00461 Current_Rid = REGION_get_rid( rwn );
00462
00463 #ifdef TARG_X8664
00464 Expand_Start();
00465 #endif
00466
00467 #if defined(TARG_SL)
00468 extern void Initial_var2spe();
00469 Initial_var2spe();
00470 Expand_Start();
00471 #endif
00472
00473 }
00474
00475
00476
00477
00478
00479
00480 static void
00481 CG_Region_Finalize (WN *result_before, WN *result_after,
00482 WN *rwn, struct ALIAS_MANAGER *am, BOOL generate_glue_code)
00483 {
00484 RID *rid;
00485 CGRIN *cgrin;
00486 WN *entry_fixup, *exit_fixup;
00487 INT32 i, num_exits;
00488
00489 Is_True(REGION_consistency_check(rwn),("CG_Region_Finalize"));
00490 rid = REGION_get_rid( rwn );
00491 cgrin = RID_cginfo( rid );
00492 FmtAssert(rid != NULL && cgrin != NULL,
00493 ("CG_Region_Finalize, inconsistent region"));
00494
00495 REGION_set_level(rid, RL_CGSCHED);
00496
00497 #ifndef TARG_NVISA
00498 if (generate_glue_code) {
00499
00500 entry_fixup = CGRIN_entry_glue( cgrin );
00501 REGION_Entry_PREG_Whirl( rid, entry_fixup, CGRIN_tns_in( cgrin ), am );
00502 if ( Trace_REGION_Interface ) {
00503 fprintf( TFile, "<region> Entry glue code for RGN %d\n", RID_id(rid) );
00504 fdump_tree( TFile, entry_fixup );
00505 }
00506 WN_INSERT_BlockFirst( result_before, entry_fixup );
00507
00508 num_exits = RID_num_exits( rid );
00509 for (i=0; i<num_exits; i++) {
00510 exit_fixup = CGRIN_exit_glue_i( cgrin, i );
00511 REGION_Exit_PREG_Whirl( rid, i, exit_fixup,
00512 CGRIN_tns_out_i( cgrin, i ), am );
00513 if ( Trace_REGION_Interface ) {
00514 fprintf( TFile, "<region> Exit glue code for exit %d RGN %d\n",
00515 i, RID_id(rid) );
00516 fdump_tree( TFile, exit_fixup );
00517 }
00518 WN_INSERT_BlockLast( result_after, exit_fixup );
00519 }
00520 }
00521 #endif
00522
00523 Whirl2ops_Finalize();
00524
00525 MEM_POOL_Pop (&MEM_local_region_pool);
00526 MEM_POOL_Pop (&MEM_local_region_nz_pool);
00527 }
00528
00529 static int trace_count = 0;
00530 static void Check_for_Dump_ALL(INT32 pass, BB *bb, char *s )
00531 {
00532 trace_count++;
00533 char count_buf[20];
00534 int count = sprintf(count_buf, "%d: ", trace_count);
00535 char phase_buf[20+30]= "Tracing";
00536 strcat(phase_buf, count_buf);
00537 strcat(phase_buf, s);
00538 Set_Error_Phase(phase_buf);
00539 Check_for_Dump(pass, bb);
00540 }
00541
00542 #if defined(TARG_SL)
00543
00544
00545
00546 void
00547 Check_Minor_Region()
00548 {
00549 for(BB* bb = REGION_First_BB; bb; bb = BB_next(bb))
00550 {
00551 if(BB_rid(bb) && RID_TYPE_minor(BB_rid(bb)) && BB_call(bb))
00552 Fail_FmtAssertion("An function call BB:%d in minor region", BB_id(bb));
00553 }
00554 return;
00555 }
00556 #endif
00557
00558
00559 #if defined(TARG_SL)
00560 void
00561 Collect_Simd_Register_Usage()
00562 {
00563 if(!Get_Trace(TP_TEMP, 0x1))
00564 return;
00565
00566 vector < mTN_NUM > regs_read;
00567 vector < mTN_NUM > regs_write;
00568 vector < mTN_NUM >::iterator iter;
00569 vector < ST* > callee_in_pu;
00570 vector < ST* >::iterator st_iter;
00571 BB *bb;
00572 OP *op;
00573 for(bb = REGION_First_BB; bb; bb = BB_next(bb))
00574 {
00575
00576
00577 if(BB_call(bb))
00578 {
00579 ANNOTATION *callant = ANNOT_Get(BB_annotations(bb), ANNOT_CALLINFO);
00580 CALLINFO *callinfo = ANNOT_callinfo(callant);
00581 ST *st = CALLINFO_call_st(callinfo);
00582 callee_in_pu.push_back(st);
00583 }
00584 FOR_ALL_BB_OPs(bb, op)
00585 {
00586 for(INT i = 0; i < OP_results(op); i++) {
00587 TN* tn = OP_result(op, i);
00588 if(TN_is_register(tn) && (TN_register_class(tn) == ISA_REGISTER_CLASS_cop_vreg))
00589 regs_write.push_back((TN_register(tn) - 1));
00590 }
00591 for(INT i = 0; i < OP_opnds(op); i++) {
00592 TN* tn = OP_opnd(op, i);
00593 if(TN_is_register(tn) && (TN_register_class(tn) == ISA_REGISTER_CLASS_cop_vreg))
00594 regs_read.push_back((TN_register(tn) - 1));
00595 }
00596 }
00597 }
00598
00599 fprintf(TFile, "%sFunction %s : \n", DBar, ST_name(Get_Current_PU_ST()));
00600
00601 if(!regs_read.empty()) {
00602 sort(regs_read.begin(), regs_read.end());
00603 regs_read.erase(unique(regs_read.begin(), regs_read.end()), regs_read.end());
00604 fprintf(TFile, "read_simd_reg: ");
00605 for(iter = regs_read.begin(); iter != regs_read.end(); iter++)
00606 fprintf(TFile, "%d ", *iter);
00607 fprintf(TFile, "\n");
00608 }
00609
00610 if(!regs_write.empty()) {
00611 sort(regs_write.begin(), regs_write.end());
00612 regs_write.erase(unique(regs_write.begin(), regs_write.end()), regs_write.end());
00613 fprintf(TFile, "write_simd_reg: ");
00614 for(iter = regs_write.begin(); iter != regs_write.end(); iter++) {
00615 fprintf(TFile, "%d ", *iter);
00616 }
00617 fprintf(TFile, "\n");
00618 }
00619
00620 fprintf(TFile, "callee:\n");
00621
00622 for(st_iter = callee_in_pu.begin(); st_iter != callee_in_pu.end(); st_iter++)
00623 {
00624 fprintf(TFile, " %s\n", ST_name(*st_iter));
00625 }
00626 return;
00627 }
00628 #endif
00629
00630
00631 #ifdef TARG_IA64
00632 static void Config_Ipfec_Flags() {
00633
00634
00635 Copy_Ipfec_Flags();
00636
00637
00638 IPFEC_Enable_Edge_Profile = IPFEC_Enable_Edge_Profile ||
00639 ((Instrumentation_Enabled || Instrumentation_Enabled_Before)
00640 && (Instrumentation_Phase_Num==4 && Instrumentation_Type_Num & CG_EDGE_PROFILE));
00641
00642 IPFEC_Enable_Value_Profile= IPFEC_Enable_Value_Profile || ( (Instrumentation_Enabled || Instrumentation_Enabled_Before)
00643 && (Instrumentation_Phase_Num==4 && Instrumentation_Type_Num & CG_VALUE_PROFILE) );
00644 IPFEC_Enable_Stride_Profile= IPFEC_Enable_Stride_Profile || ( (Instrumentation_Enabled || Instrumentation_Enabled_Before)
00645 && (Instrumentation_Phase_Num==4 && Instrumentation_Type_Num & CG_STRIDE_PROFILE) );
00646 IPFEC_Enable_Value_Profile_Annot = IPFEC_Enable_Value_Profile_Annot || Feedback_Enabled[PROFILE_PHASE_BEFORE_REGION];
00647 IPFEC_Enable_Stride_Profile_Annot = IPFEC_Enable_Stride_Profile_Annot || Feedback_Enabled[PROFILE_PHASE_BEFORE_REGION];
00648 IPFEC_Enable_Edge_Profile_Annot = IPFEC_Enable_Edge_Profile_Annot || Feedback_Enabled[PROFILE_PHASE_BEFORE_REGION];
00649 IPFEC_Enable_Opt_after_schedule=IPFEC_Enable_Opt_after_schedule && CG_Enable_Ipfec_Phases && CG_opt_level > 1;
00650 IPFEC_Enable_Region_Formation = IPFEC_Enable_Region_Formation && CG_Enable_Ipfec_Phases && CG_opt_level > 1;
00651 IPFEC_Enable_If_Conversion = IPFEC_Enable_If_Conversion && CG_Enable_Ipfec_Phases;
00652 IPFEC_Force_If_Conv = IPFEC_Force_If_Conv && CG_Enable_Ipfec_Phases;
00653 IPFEC_Relaxed_If_Conv = IPFEC_Relaxed_If_Conv && CG_Enable_Ipfec_Phases;
00654 IPFEC_Force_Para_Comp_Gen = IPFEC_Force_Para_Comp_Gen && CG_Enable_Ipfec_Phases;
00655 IPFEC_Para_Comp_Gen = IPFEC_Para_Comp_Gen && CG_Enable_Ipfec_Phases;
00656 IPFEC_Disable_Merge_BB = IPFEC_Disable_Merge_BB && CG_Enable_Ipfec_Phases;
00657 IPFEC_Enable_PRDB = IPFEC_Enable_PRDB && CG_Enable_Ipfec_Phases && IPFEC_Enable_Region_Formation && (IPFEC_Enable_Prepass_GLOS || IPFEC_Enable_Postpass_LOCS);
00658 IPFEC_Enable_BB_Verify = IPFEC_Enable_BB_Verify && CG_Enable_Ipfec_Phases;
00659 IPFEC_Enable_Prepass_GLOS = IPFEC_Enable_Prepass_GLOS && CG_Enable_Ipfec_Phases;
00660 IPFEC_Enable_Postpass_GLOS = IPFEC_Enable_Postpass_GLOS && CG_Enable_Ipfec_Phases;
00661 IPFEC_Enable_Prepass_LOCS = IPFEC_Enable_Prepass_LOCS && CG_Enable_Ipfec_Phases;
00662 IPFEC_Enable_Postpass_LOCS = IPFEC_Enable_Postpass_LOCS && CG_Enable_Ipfec_Phases;
00663 IPFEC_Enable_Speculation = IPFEC_Enable_Speculation && CG_Enable_Ipfec_Phases;
00664 IPFEC_Enable_Data_Speculation = IPFEC_Enable_Data_Speculation && IPFEC_Enable_Speculation;
00665 IPFEC_Enable_Cntl_Speculation = IPFEC_Enable_Cntl_Speculation && IPFEC_Enable_Speculation;
00666 IPFEC_Enable_Compressed_Template = IPFEC_Enable_Compressed_Template && CG_Enable_Ipfec_Phases;
00667 IPFEC_Enable_Pre_Bundling = IPFEC_Enable_Pre_Bundling && CG_Enable_Ipfec_Phases;
00668 IPFEC_Force_CHK_Fail = IPFEC_Force_CHK_Fail && IPFEC_Enable_Speculation;
00669 IPFEC_Glos_Enable_Cntl_Spec_If_Converted_Code = IPFEC_Glos_Enable_Cntl_Spec_If_Converted_Code && IPFEC_Enable_Cntl_Speculation;
00670 IPFEC_Enable_Cascade = IPFEC_Enable_Cascade && IPFEC_Enable_Speculation;
00671 IPFEC_Hold_Uses = IPFEC_Hold_Uses && IPFEC_Enable_Speculation;
00672 IPFEC_Chk_Compact = IPFEC_Chk_Compact && IPFEC_Enable_Speculation;
00673 IPFEC_Enable_Safety_Load = IPFEC_Enable_Safety_Load && IPFEC_Enable_Speculation;
00674 IPFEC_Profitability = IPFEC_Profitability && CG_Enable_Ipfec_Phases;
00675
00676 IPFEC_Enable_Multi_Branch = IPFEC_Enable_Multi_Branch && CG_Enable_Ipfec_Phases;
00677 IPFEC_Enable_Pre_Multi_Branch = IPFEC_Enable_Pre_Multi_Branch && CG_Enable_Ipfec_Phases;
00678 IPFEC_Enable_Post_Multi_Branch = IPFEC_Enable_Post_Multi_Branch && CG_Enable_Ipfec_Phases;
00679
00680 ORC_Enable_Cache_Analysis = ORC_Enable_Cache_Analysis && CG_Enable_Ipfec_Phases;
00681
00682 if (IPFEC_Chk_Compact && locs_skip_bb) {
00683 DevWarn("Although chk_compact is turned on, it should be turned off since some BBs are forced to be skipped in local scheduling phase!");
00684 IPFEC_Chk_Compact = 0;
00685 }
00686 if (IPFEC_Chk_Compact && !IPFEC_Enable_Postpass_LOCS) {
00687 DevWarn("Although chk_compact is turned on, it should be turned off since postpass local scheduling is disabled!");
00688 IPFEC_Chk_Compact = 0;
00689 }
00690 }
00691 #endif
00692
00693
00694
00695
00696
00697 WN *
00698 CG_Generate_Code(
00699 WN *rwn,
00700 struct ALIAS_MANAGER *alias_mgr,
00701 DST_IDX pu_dst,
00702 BOOL region )
00703 {
00704 #ifdef TARG_IA64
00705 BOOL value_profile_need_gra = FALSE;
00706
00707 RGN_Formed = FALSE;
00708 #endif
00709
00710 BOOL orig_reuse_temp_tns = Reuse_Temp_TNs;
00711 Alias_Manager = alias_mgr;
00712
00713 Set_Error_Phase( "Code Generation" );
00714 Start_Timer( T_CodeGen_CU );
00715
00716 #ifdef TARG_X8664
00717
00718
00719 if (!CG_emit_unwind_info_Set)
00720 CG_emit_unwind_info = Force_Frame_Pointer;
00721
00722
00723
00724 {
00725 static BOOL min_stack_size = CG_min_stack_size;
00726 CG_min_stack_size = min_stack_size;
00727 if (!strcmp(Cur_PU_Name, "MAIN__") ||
00728 !strcmp(Cur_PU_Name, "main"))
00729 CG_min_stack_size = FALSE;
00730 }
00731 #endif
00732
00733
00734
00735
00736 CG_PU_Has_Feedback = ((Cur_PU_Feedback != NULL) && CG_enable_feedback);
00737 BOOL frequency_verify = Get_Trace( TP_FEEDBACK, TP_CG_FEEDBACK );
00738
00739 #ifdef TARG_IA64
00740 if (FALSE) {
00741 ST *func_st = Get_Current_PU_ST();
00742 rse_budget = PU_gp_group(Pu_Table [ST_pu (func_st)]);
00743 if (rse_budget == 0) DevWarn("FAINT THE RSE BUDGET IS ZERO!");
00744 }
00745 #endif
00746
00747 CG_Region_Initialize ( rwn, alias_mgr );
00748
00749 Set_Error_Phase ( "Code_Expansion" );
00750 Start_Timer ( T_Expand_CU );
00751
00752
00753
00754 if (WN_operator(rwn) == OPR_FUNC_ENTRY &&
00755 ST_asm_function_st(*WN_st(rwn))) {
00756 FmtAssert(Assembly && !Object_Code,
00757 ("Cannot produce non-assembly output with file-scope asm"));
00758 fprintf(Asm_File, "\n%s\n", ST_name(WN_st(rwn)));
00759 #ifdef KEY
00760
00761
00762
00763
00764
00765
00766 if (LANG_Enable_Global_Asm)
00767 CG_file_scope_asm_seen = TRUE;
00768 #endif
00769 return rwn;
00770 }
00771
00772 #if defined (TARG_SL)
00773 if(CG_stack_layout)
00774 Pre_Allocate_Objects( rwn );
00775 #endif
00776
00777 Convert_WHIRL_To_OPs ( rwn );
00778
00779 #ifndef TARG_NVISA
00780
00781 #if defined(TARG_SL)
00782 Check_Minor_Region();
00783 #endif
00784
00785 #ifdef TARG_X8664
00786 if (CG_x87_store) {
00787 extern void Add_Float_Stores();
00788 Add_Float_Stores();
00789 }
00790 #endif
00791
00792 #if defined(KEY) && !defined(TARG_SL)
00793 extern BOOL profile_arcs;
00794 if (flag_test_coverage || profile_arcs)
00795
00796
00797 CG_Gcov_Generation();
00798 if (profile_arcs)
00799 CG_Instrument_Arcs();
00800 #endif
00801
00802
00803 Split_BBs();
00804
00805 if ( ! CG_localize_tns ) {
00806
00807
00808
00809 Localize_or_Replace_Dedicated_TNs();
00810 }
00811
00812
00813
00814 if (CG_PU_Has_Feedback) {
00815 Set_Error_Phase ("FREQ");
00816 Start_Timer (T_Freq_CU);
00817 FREQ_Incorporate_Feedback ( rwn );
00818 Stop_Timer (T_Freq_CU);
00819 Set_Error_Phase ( "Code_Expansion" );
00820 if (frequency_verify)
00821 FREQ_Verify("Feedback Incorporation");
00822 }
00823
00824
00825
00826
00827
00828 EH_Prune_Range_List();
00829
00830 #if defined(TARG_IA64)
00831
00832 pu_need_LSDA = !PU_Need_Not_Create_LSDA ();
00833 #endif
00834
00835
00836 if (Get_Trace (TP_EH, 0x0002)) {
00837 fprintf (TFile, "\n=======================================================================\n");
00838 fprintf (TFile, "\t EH RANGE INFO for PU: %s \n", ST_name(Get_Current_PU_ST()));
00839 fprintf (TFile, "\t (After EH_Prune_Range_List) \t\n");
00840 fprintf (TFile, "=======================================================================\n");
00841 EH_Print_Range_List ();
00842 }
00843
00844 Optimize_Tail_Calls( Get_Current_PU_ST() );
00845 #endif // !TARG_NVISA
00846
00847 Init_Callee_Saved_Regs_for_REGION( Get_Current_PU_ST(), region );
00848 #ifdef TARG_IA64
00849
00850
00851
00852
00853 Config_Ipfec_Flags();
00854 #endif
00855 Generate_Entry_Exit_Code ( Get_Current_PU_ST(), region );
00856 #ifdef TARG_IA64
00857 if (!CG_localize_tns) {
00858 CGTARG_Add_Implict_Operands ();
00859 }
00860 #endif
00861 Stop_Timer ( T_Expand_CU );
00862 Check_for_Dump ( TP_CGEXP, NULL );
00863
00864 #ifndef TARG_NVISA // nvisa just emits initial assembly
00865
00866 #ifdef TARG_IA64
00867 if (IPFEC_Enable_Edge_Profile && can_invoke_profile_with_current_cg_opt_level )
00868 {
00869 Set_Error_Phase ( "edge profile instrument" );
00870 Start_Timer ( T_Ipfec_Profiling_CU );
00871 CG_Edge_Profile_Instrument(RID_cginfo(Current_Rid),PROFILE_PHASE_BEFORE_REGION);
00872 Stop_Timer( T_Ipfec_Profiling_CU );
00873 Check_for_Dump(TP_A_PROF, NULL);
00874 Set_Frame_Has_Calls(TRUE);
00875 } else if (IPFEC_Enable_Edge_Profile_Annot && can_invoke_profile_with_current_cg_opt_level ) {
00876 Set_Error_Phase ( "edge profile annotation" );
00877 CG_Edge_Profile_Annotation(RID_cginfo(Current_Rid),PROFILE_PHASE_BEFORE_REGION);
00878 Check_for_Dump(TP_A_PROF, NULL);
00879
00880 }
00881
00882 #ifdef _value_profile_before_region_formation
00883 if ((IPFEC_Enable_Value_Profile||IPFEC_Enable_Stride_Profile) && can_invoke_profile_with_current_cg_opt_level )
00884 {
00885 Set_Error_Phase ( "value profile instrument" );
00886 if (EBO_Opt_Level != 0)
00887 {
00888 DevWarn("Value profiling need -CG:ebo_level=0!! Set ebo_level to 0!!");
00889 EBO_Opt_Level = 0;
00890 }
00891
00892
00893
00894 inst2prof_list.clear();
00895 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld1,0,FALSE),&MEM_pu_pool) );
00896 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld2,0,FALSE),&MEM_pu_pool) );
00897 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld4,0,FALSE),&MEM_pu_pool) );
00898 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld8,0,FALSE),&MEM_pu_pool) );
00899
00900 UINT32 Min_Instr_Pu_Id, Max_Instr_Pu_Id;
00901 Min_Instr_Pu_Id = Value_Instr_Pu_Id >> 16;
00902 Max_Instr_Pu_Id = Value_Instr_Pu_Id & 0xffff;
00903 Is_True((current_PU_handle<=Max_Instr_Pu_Id)&&(current_PU_handle>=Min_Instr_Pu_Id),("The number of PU exceed the boundery !"));
00904 Start_Timer ( T_Ipfec_Profiling_CU );
00905 CG_VALUE_Instrument(RID_cginfo(Current_Rid),PROFILE_PHASE_BEFORE_REGION,IPFEC_Enable_Stride_Profile, IPFEC_Enable_Value_Profile);
00906 value_profile_need_gra = TRUE;
00907 Stop_Timer( T_Ipfec_Profiling_CU );
00908 Check_for_Dump(TP_A_PROF, NULL);
00909 } else if ((IPFEC_Enable_Value_Profile_Annot||IPFEC_Enable_Stride_Profile_Annot)&& can_invoke_profile_with_current_cg_opt_level ) {
00910
00911
00912 inst2prof_list.clear();
00913 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld1,0,FALSE),&MEM_pu_pool) );
00914 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld2,0,FALSE),&MEM_pu_pool) );
00915 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld4,0,FALSE),&MEM_pu_pool) );
00916 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld8,0,FALSE),&MEM_pu_pool) );
00917
00918 Set_Error_Phase ( "value profile annotation" );
00919 UINT32 Min_Instr_Pu_Id, Max_Instr_Pu_Id;
00920 Min_Instr_Pu_Id = Value_Instr_Pu_Id >> 16;
00921 Max_Instr_Pu_Id = Value_Instr_Pu_Id & 0xffff;
00922 Is_True((current_PU_handle<=Max_Instr_Pu_Id)&&(current_PU_handle>=Min_Instr_Pu_Id),("The number of PU exceed the boundery !"));
00923
00924 }
00925 #endif
00926 if (CG_localize_tns && !value_profile_need_gra ) {
00927 #else // TARG_IA64
00928 if (CG_localize_tns
00929 #ifdef TARG_X8664
00930 || CG_localize_x87_tns
00931 #endif
00932 ) {
00933 #endif // TARG_IA64
00934
00935 Set_Error_Phase ( "Localize" );
00936 Start_Timer ( T_Localize_CU );
00937 #ifdef KEY // gra_live is called even if localize is on
00938 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
00939 #endif
00940 Localize_Any_Global_TNs(region ? REGION_get_rid( rwn ) : NULL);
00941 Stop_Timer ( T_Localize_CU );
00942 Check_for_Dump ( TP_LOCALIZE, NULL );
00943 } else {
00944
00945
00946 Set_Error_Phase( "Global Live Range Analysis");
00947 Start_Timer( T_GLRA_CU );
00948 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
00949 Stop_Timer ( T_GLRA_CU );
00950 Check_for_Dump ( TP_FIND_GLOB, NULL );
00951 }
00952
00953 if (Enable_CG_Peephole) {
00954 Set_Error_Phase("Extended Block Optimizer");
00955 Start_Timer(T_EBO_CU);
00956 EBO_Pre_Process_Region (region ? REGION_get_rid(rwn) : NULL);
00957 if (CG_opt_level > 1
00958 #ifdef TARG_IA64
00959 || value_profile_need_gra
00960 #endif
00961 ) {
00962
00963
00964 GRA_LIVE_Recalc_Liveness(region ? REGION_get_rid( rwn) : NULL);
00965
00966
00967 GRA_LIVE_Rename_TNs();
00968 }
00969 Stop_Timer ( T_EBO_CU );
00970 Check_for_Dump ( TP_EBO, NULL );
00971 }
00972
00973
00974 if (CG_opt_level > 0 && CFLOW_opt_before_cgprep) {
00975
00976
00977 CFLOW_Optimize( (CFLOW_ALL_OPTS|CFLOW_IN_CGPREP)
00978 #if defined(TARG_SL)
00979 & ~(CFLOW_COLD_REGION)
00980 #endif
00981 & ~(CFLOW_FREQ_ORDER | CFLOW_REORDER),
00982 "CFLOW (first pass)");
00983 if (frequency_verify && CG_PU_Has_Feedback)
00984 FREQ_Verify("CFLOW (first pass)");
00985 #if defined(TARG_SL)
00986 Check_for_Dump_ALL ( TP_CGEXP, NULL,"CFLOW 1" );
00987 #endif
00988 }
00989
00990 #ifdef TARG_IA64
00991 extern void Perform_Loop_Invariant_Code_Motion (void);
00992 if (IPFEC_Enable_LICM && CG_opt_level > 1) {
00993 Perform_Loop_Invariant_Code_Motion ();
00994 }
00995
00996 if (CG_Enable_Ipfec_Phases && CG_opt_level > 1 &&
00997 (IPFEC_Enable_If_Conversion || IPFEC_Enable_PRDB ||
00998 IPFEC_Enable_Prepass_GLOS || IPFEC_Enable_Postpass_GLOS))
00999 IPFEC_Enable_Region_Formation = TRUE;
01000
01001 REGION_TREE *region_tree = NULL;
01002 if (IPFEC_Enable_Region_Formation) {
01003
01004 Set_Error_Phase("Ipfec region formation");
01005 Start_Timer(T_Ipfec_Region_CU);
01006 region_tree=CXX_NEW(REGION_TREE(REGION_First_BB),&MEM_pu_pool);
01007 Stop_Timer(T_Ipfec_Region_CU);
01008 RGN_Formed = TRUE;
01009 }
01010 #endif
01011
01012
01013 if (CG_opt_level > 1) {
01014
01015
01016
01017
01018
01019 #ifdef TARG_IA64
01020 if (!CG_PU_Has_Feedback && !IPFEC_Enable_Edge_Profile_Annot) {
01021 #else
01022 if (!CG_PU_Has_Feedback) {
01023 #endif
01024 Set_Error_Phase("FREQ");
01025 Start_Timer (T_Freq_CU);
01026 FREQ_Compute_BB_Frequencies();
01027 Stop_Timer (T_Freq_CU);
01028 if (frequency_verify)
01029 FREQ_Verify("Heuristic Frequency Computation");
01030 }
01031
01032 #ifdef TARG_IA64
01033 if (IPFEC_Enable_Region_Formation) {
01034
01035 Set_Error_Phase("Ipfec region formation");
01036 Start_Timer(T_Ipfec_Region_CU);
01037 REGION *root = region_tree->Root();
01038 IPFEC_Enable_Region_Decomposition = TRUE;
01039 if (IPFEC_Enable_Region_Decomposition) {
01040 region_tree->Decomposition();
01041 GRA_LIVE_Recalc_Liveness(region ? REGION_get_rid(rwn) : NULL);
01042 }
01043
01044 Stop_Timer(T_Ipfec_Region_CU);
01045
01046 #ifdef Is_True_On
01047 if (Get_Trace(TP_IPFEC,TT_IPFEC_GRAPHIC)) {
01048 printf("After Region Formation draw global cfg\n");
01049 draw_global_cfg("after Decompose_Region_To_SEME");
01050 printf("After Region Formation draw region tree\n");
01051 draw_region_tree(region_tree->Root(),"After Region Formation");
01052 }
01053 Verify_Region_Tree(region_tree, REGION_First_BB);
01054 #endif
01055 }
01056
01057
01058 if (IPFEC_Enable_Stride_Prefetch && IPFEC_Enable_Stride_Profile_Annot){
01059 Set_Error_Phase( "Stride prefetch \n");
01060 Stride_Region(region_tree, IPFEC_Enable_Stride_Prefetch);
01061 }
01062 #endif
01063
01064
01065
01066
01067 #ifdef KEY
01068
01069 if (1) {
01070 #else
01071 if (CGTARG_Can_Predicate()) {
01072 #endif
01073 #ifdef TARG_IA64
01074 if (IPFEC_Enable_If_Conversion) {
01075 Set_Error_Phase( "Ipfec if conversion");
01076 IF_CONVERTOR convertor(region_tree);
01077 #ifdef Is_True_On
01078 if (IPFEC_Enable_BB_Verify) {
01079 BB_Verify_Flags();
01080 }
01081 if (Get_Trace(TP_IPFEC,TT_IPFEC_GRAPHIC)) {
01082 printf("After If Conversion draw global cfg\n");
01083 draw_global_cfg("after if conversion");
01084 printf("After If Conversion draw tree\n");
01085 draw_region_tree(region_tree->Root(),"After If Conversion");
01086 }
01087 Verify_Region_Tree(region_tree, REGION_First_BB);
01088 #endif
01089 #endif // TARG_IA64
01090
01091 #ifdef TARG_IA64
01092 }
01093 else if (!IPFEC_Enable_Region_Formation) {
01094
01095
01096 HB_Form_Hyperblocks(region ? REGION_get_rid(rwn) : NULL, NULL);
01097 if (!PQSCG_pqs_valid()) {
01098 PQSCG_reinit(REGION_First_BB);
01099 }
01100 #else
01101
01102 HB_Form_Hyperblocks(region ? REGION_get_rid(rwn) : NULL, NULL);
01103 #ifdef KEY
01104
01105
01106
01107
01108 HB_Reinit_Pred();
01109
01110 hammock_region = FALSE;
01111 #endif
01112 if (!PQSCG_pqs_valid()) {
01113 PQSCG_reinit(REGION_First_BB);
01114 #endif // TARG_IA64
01115 }
01116 if (frequency_verify)
01117 FREQ_Verify("Hyberblock Formation");
01118 }
01119 #ifdef TARG_IA64
01120 if (!CG_localize_tns || value_profile_need_gra ) {
01121
01122
01123 Set_Error_Phase( "Global Live Range Analysis");
01124 Start_Timer( T_GLRA_CU );
01125 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
01126 Stop_Timer ( T_GLRA_CU );
01127 Check_for_Dump ( TP_FIND_GLOB, NULL );
01128 }
01129
01130 if (ORC_Enable_Cache_Analysis) Cache_Location_Analysis();
01131 #endif
01132
01133 if (CG_enable_loop_optimizations) {
01134 #ifdef KEY
01135
01136
01137
01138
01139 if (CG_localize_tns
01140 #ifdef TARG_X8664
01141 || CG_localize_x87_tns
01142 #endif
01143 ){
01144 Set_Error_Phase( "Global Live Range Analysis" );
01145 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
01146 }
01147 #endif
01148 Set_Error_Phase("CGLOOP");
01149 Start_Timer(T_Loop_CU);
01150 #ifdef TARG_IA64
01151 if (IPFEC_Enable_Region_Formation) {
01152 REGION_LOOP_UPDATE *rgn_loop_update;
01153 rgn_loop_update = CXX_NEW(REGION_LOOP_UPDATE(region_tree,REGION_First_BB),&MEM_pu_pool);
01154 Perform_Loop_Optimizations(rgn_loop_update);
01155 CXX_DELETE(rgn_loop_update, &MEM_pu_pool);
01156 #ifdef Is_True_On
01157 if (Get_Trace(TP_IPFEC,TT_IPFEC_GRAPHIC)) {
01158 draw_global_cfg("after loop opt");
01159 draw_region_tree(region_tree->Root());
01160 }
01161 Verify_Region_Tree(region_tree, REGION_First_BB);
01162 #endif
01163 } else {
01164 Perform_Loop_Optimizations();
01165 }
01166 #else
01167
01168 Perform_Loop_Optimizations();
01169 #endif // TARG_IA64
01170
01171 GRA_LIVE_Recalc_Liveness(region ? REGION_get_rid( rwn) : NULL);
01172 GRA_LIVE_Rename_TNs();
01173 Stop_Timer(T_Loop_CU);
01174 Check_for_Dump(TP_CGLOOP, NULL);
01175 if (frequency_verify)
01176 FREQ_Verify("CGLOOP");
01177
01178 #ifdef KEY
01179
01180
01181
01182
01183 if (CG_localize_tns
01184 #ifdef TARG_X8664
01185 || CG_localize_x87_tns
01186 #endif
01187 ){
01188 Set_Error_Phase ( "Localize (after CGLOOP)" );
01189 Start_Timer ( T_Localize_CU );
01190 Localize_Any_Global_TNs(region ? REGION_get_rid( rwn ) : NULL);
01191 Stop_Timer ( T_Localize_CU );
01192 Check_for_Dump ( TP_LOCALIZE, NULL );
01193 }
01194 #endif
01195 }
01196
01197
01198 if (CFLOW_opt_after_cgprep) {
01199 #if defined (TARG_SL)
01200 CFLOW_Optimize( (CFLOW_ALL_OPTS|CFLOW_IN_CGPREP)
01201 & ~(CFLOW_COLD_REGION)
01202 & ~(CFLOW_FREQ_ORDER),
01203 "CFLOW (second pass)");
01204 #else
01205 CFLOW_Optimize(CFLOW_ALL_OPTS, "CFLOW (second pass)");
01206 #endif
01207 #if defined(TARG_SL)
01208 Check_for_Dump_ALL ( TP_CGEXP, NULL,"CFLOW 1" );
01209 #endif
01210 if (frequency_verify)
01211 FREQ_Verify("CFLOW (second pass)");
01212 #ifdef TARG_IA64
01213 #ifdef Is_True_On
01214 if (Get_Trace(TP_IPFEC,TT_IPFEC_GRAPHIC)) {
01215 draw_global_cfg("after cflow opt");
01216 draw_region_tree(region_tree->Root());
01217 }
01218 if (IPFEC_Enable_Region_Formation)
01219 Verify_Region_Tree(region_tree, REGION_First_BB);
01220 #endif
01221 #endif
01222 }
01223
01224 if (Enable_CG_Peephole) {
01225 Set_Error_Phase( "Extended Block Optimizer");
01226 Start_Timer( T_EBO_CU );
01227 EBO_Process_Region (region ? REGION_get_rid(rwn) : NULL);
01228 PQSCG_reinit(REGION_First_BB);
01229 Stop_Timer ( T_EBO_CU );
01230 Check_for_Dump ( TP_EBO, NULL );
01231 }
01232 }
01233
01234
01235 #ifdef TARG_IA64
01236 BOOL locs_bundle_value = LOCS_Enable_Bundle_Formation;
01237 BOOL emit_bundle_value = EMIT_explicit_bundles;
01238 LOCS_Enable_Bundle_Formation = IPFEC_Enable_Pre_Bundling;
01239 EMIT_explicit_bundles = IPFEC_Enable_Pre_Bundling;
01240 #endif
01241 if (!Get_Trace (TP_CGEXP, 1024))
01242 Reuse_Temp_TNs = TRUE;
01243
01244 if (CGSPILL_Enable_Force_Rematerialization)
01245 CGSPILL_Force_Rematerialization();
01246
01247 if (!region) {
01248
01249 Adjust_GP_Setup_Code( Get_Current_PU_ST(), FALSE );
01250
01251 Adjust_LC_Setup_Code();
01252
01253
01254
01255 }
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268 #ifdef TARG_IA64
01269 if (!CG_localize_tns) {
01270
01271
01272
01273
01274
01275
01276
01277 }
01278
01279
01280 gra_self_recursive = FALSE;
01281 fat_self_recursive = FALSE;
01282
01283 if (CG_opt_level > 1 && IPFEC_Enable_PRDB) PRDB_Init(region_tree);
01284
01285 if (IPFEC_Enable_Prepass_GLOS && CG_opt_level > 1) {
01286 Start_Timer( T_GLRA_CU );
01287 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
01288 Stop_Timer ( T_GLRA_CU );
01289
01290 if(Enable_CG_Peephole)
01291 EBO_Pre_Process_Region (region ? REGION_get_rid(rwn) : NULL);
01292 Check_Self_Recursive();
01293 Global_Insn_Sched(region_tree, TRUE);
01294 } else if (IPFEC_Enable_Prepass_LOCS) {
01295 Local_Insn_Sched(TRUE);
01296 } else {
01297 IGLS_Schedule_Region (TRUE );
01298 }
01299
01300
01301 if (CG_opt_level > 1 && IPFEC_Enable_PRDB) PRDB_Init(region_tree);
01302
01303
01304
01305
01306
01307 if (IPFEC_Enable_Prepass_GLOS && CG_opt_level > 1) {
01308 BOOL need_recalc_liveness = (Generate_Recovery_Code() > 0);
01309 if (need_recalc_liveness)
01310 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
01311 }
01312
01313 if (IPFEC_Enable_Opt_after_schedule) {
01314 BOOL tmp = CG_localize_tns ;
01315 CG_localize_tns = TRUE;
01316 CFLOW_Optimize(CFLOW_BRANCH|CFLOW_UNREACHABLE|CFLOW_MERGE|CFLOW_REORDER ,
01317 "CFLOW (third pass)");
01318 CG_localize_tns = tmp ;
01319 }
01320
01321 if (CG_opt_level > 1 && IPFEC_Enable_Post_Multi_Branch) {
01322 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
01323 Post_Multi_Branch_Collect();
01324 }
01325 #ifdef Is_True_On
01326 if (IPFEC_Enable_BB_Verify) {
01327 BB_Verify_Flags();
01328 }
01329 #endif
01330
01331 LOCS_Enable_Bundle_Formation = locs_bundle_value;
01332 EMIT_explicit_bundles = emit_bundle_value;
01333 #ifndef _value_profile_before_region_formation
01334 if (IPFEC_Enable_Value_Profile && can_invoke_profile_with_current_cg_opt_level )
01335 {
01336 Set_Error_Phase ( "value profile instrument" );
01337 if (EBO_Opt_Level != 0)
01338 {
01339 DevWarn("Value profiling need -CG:ebo_level=0!! Set ebo_level to 0!!");
01340 EBO_Opt_Level = 0;
01341 }
01342
01343
01344 inst2prof_list.clear();
01345 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld1,0,FALSE),&MEM_pu_pool) );
01346 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld2,0,FALSE),&MEM_pu_pool) );
01347 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld4,0,FALSE),&MEM_pu_pool) );
01348 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld8,0,FALSE),&MEM_pu_pool) );
01349 UINT32 Min_Instr_Pu_Id, Max_Instr_Pu_Id;
01350 UINT64 tmpmask=1;
01351 tmpmask = tmpmask << current_PU_handle;
01352 Min_Instr_Pu_Id = Value_Instr_Pu_Id >> 16;
01353 Max_Instr_Pu_Id = Value_Instr_Pu_Id & 0xffff;
01354 if (current_PU_handle >= Min_Instr_Pu_Id
01355 && current_PU_handle <= Max_Instr_Pu_Id
01356 && ((unsigned long long)( tmpmask &~ Value_Instr_Pu_Id_Mask )) )
01357 {
01358 Start_Timer ( T_Ipfec_Profiling_CU );
01359 CG_VALUE_Instrument(RID_cginfo(Current_Rid),PROFILE_PHASE_LAST,FALSE,FALSE);
01360 value_profile_need_gra = TRUE;
01361 Stop_Timer( T_Ipfec_Profiling_CU );
01362 }
01363 Check_for_Dump(TP_A_PROF, NULL);
01364
01365 } else if (IPFEC_Enable_Value_Profile_Annot && can_invoke_profile_with_current_cg_opt_level ) {
01366
01367
01368 inst2prof_list.clear();
01369 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld1,0,FALSE),&MEM_pu_pool) );
01370 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld2,0,FALSE),&MEM_pu_pool) );
01371 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld4,0,FALSE),&MEM_pu_pool) );
01372 inst2prof_list.push_back( CXX_NEW(INST_TO_PROFILE(TOP_ld8,0,FALSE),&MEM_pu_pool) );
01373
01374 Set_Error_Phase ( "value profile annotation" );
01375 UINT32 Min_Instr_Pu_Id, Max_Instr_Pu_Id;
01376 UINT64 tmpmask=1;
01377 tmpmask = tmpmask << current_PU_handle;
01378 Min_Instr_Pu_Id = Value_Instr_Pu_Id >> 16;
01379 Max_Instr_Pu_Id = Value_Instr_Pu_Id & 0xffff;
01380 if (current_PU_handle >= Min_Instr_Pu_Id
01381 && current_PU_handle <= Max_Instr_Pu_Id
01382 && ((unsigned long long)( tmpmask &~ Value_Instr_Pu_Id_Mask )) )
01383 {
01384
01385 }
01386 }
01387 DevWarn("Now we are testing instrumentation after RegionFormation!");
01388 #endif
01389 current_PU_handle++;
01390 #endif // TARG_IA64
01391
01392 #ifdef KEY
01393
01394
01395
01396
01397
01398
01399
01400 #ifdef TARG_SL //fork_joint
01401
01402
01403
01404 if(CG_opt_level > 1) {
01405 GRA_LIVE_Recalc_Liveness(region ? REGION_get_rid( rwn) : NULL);
01406 GRA_LIVE_Rename_TNs();
01407 }
01408
01409 BOOL should_do_gcm;
01410 should_do_gcm = GCM_Enable_Scheduling & RGN_Enable_All_Scheduling;
01411
01412 if(should_do_gcm && CG_opt_level > 1) {
01413 IGLS_Schedule_Region( TRUE );
01414 }
01415 Check_for_Dump_ALL ( TP_CGEXP, NULL, "GCM" );
01416
01417 if( RGN_Enable_All_Scheduling &&
01418 CG_Enable_Regional_Local_Sched &&
01419 LOCS_PRE_Enable_Scheduling &&
01420 CG_opt_level > 1 ){
01421 Local_Insn_Sched( TRUE );
01422 }
01423 Check_for_Dump_ALL ( TP_CGEXP, NULL, "Pre LIS" );
01424
01425
01426
01427
01428
01429
01430
01431
01432 if( CG_Enable_Regional_Global_Sched &&
01433 CG_Enable_REGION_formation &&
01434 CG_opt_level > 1) {
01435 CFLOW_Optimize( CFLOW_BRANCH | CFLOW_UNREACHABLE | CFLOW_MERGE |
01436 CFLOW_REORDER, "CFLOW (third pass)");
01437 }
01438
01439 Check_for_Dump_ALL ( TP_CGEXP, NULL, "after Sched" );
01440 #else
01441 GRA_LIVE_Recalc_Liveness(region ? REGION_get_rid( rwn) : NULL);
01442 GRA_LIVE_Rename_TNs();
01443 IGLS_Schedule_Region (TRUE );
01444 #endif // TARG_SL
01445 #endif
01446
01447 #ifdef TARG_IA64
01448 if (!CG_localize_tns || value_profile_need_gra )
01449 #else
01450 if (!CG_localize_tns)
01451 #endif
01452 {
01453
01454
01455
01456
01457 if (GRA_recalc_liveness) {
01458 Start_Timer( T_GLRA_CU);
01459 GRA_LIVE_Recalc_Liveness(region ? REGION_get_rid( rwn) : NULL);
01460 Stop_Timer ( T_GLRA_CU );
01461 Check_for_Dump (TP_FIND_GLOB, NULL);
01462 #ifdef TARG_IA64
01463 } else if (!(IPFEC_Enable_Prepass_GLOS && (CG_opt_level > 1 || value_profile_need_gra))) {
01464 GRA_LIVE_Recalc_Liveness(region ? REGION_get_rid( rwn) : NULL);
01465 #else
01466 } else {
01467 #endif
01468 GRA_LIVE_Rename_TNs ();
01469 }
01470
01471 #ifdef TARG_IA64
01472 if (GRA_redo_liveness || IPFEC_Enable_Prepass_GLOS && (CG_opt_level > 1 || value_profile_need_gra)) {
01473 #else
01474 if (GRA_redo_liveness
01475 #ifdef KEY
01476
01477 || GRA_optimize_boundary
01478 #endif
01479 )
01480 {
01481 #endif
01482 Start_Timer( T_GLRA_CU );
01483 GRA_LIVE_Init(region ? REGION_get_rid( rwn ) : NULL);
01484 Stop_Timer ( T_GLRA_CU );
01485 Check_for_Dump ( TP_FIND_GLOB, NULL );
01486 #if defined(TARG_SL)
01487 Check_for_Dump_ALL ( TP_CGEXP, NULL, "GLRA" );
01488 #endif
01489 }
01490
01491 GRA_Allocate_Global_Registers( region );
01492 }
01493
01494 LRA_Allocate_Registers (!region);
01495
01496 #if defined(TARG_SL)
01497 if (Run_ipisr)
01498 IPISR_Insert_Spills();
01499 #endif
01500
01501 #ifdef TARG_IA64
01502 if (!CG_localize_tns || value_profile_need_gra) {
01503 #else
01504 if (!CG_localize_tns ) {
01505 #endif
01506 Set_Error_Phase ( "GRA_Finish" );
01507
01508 GRA_Finalize_Grants();
01509 }
01510
01511 #if defined(KEY) && !defined(TARG_SL)
01512
01513
01514 if (CFLOW_opt_after_cgprep &&
01515 !CG_localize_tns) {
01516 CFLOW_Optimize(CFLOW_BRANCH|CFLOW_UNREACHABLE, "CFLOW (third pass)");
01517 }
01518 #endif
01519
01520 if (!region) {
01521
01522 Adjust_GP_Setup_Code( Get_Current_PU_ST(), TRUE );
01523
01524
01525
01526
01527
01528
01529 Set_Frame_Len (Finalize_Stack_Frame());
01530 Set_Error_Phase ( "Final SP adjustment" );
01531 Adjust_Entry_Exit_Code ( Get_Current_PU_ST() );
01532 }
01533
01534 #if defined(TARG_SL)
01535 Check_for_Dump_ALL ( TP_CGEXP, NULL, "Adj Ent/exit" );
01536 #endif
01537 #ifdef TARG_IA64
01538 if (CG_opt_level > 0 && Enable_EBO_Post_Proc_Rgn) {
01539 #else
01540 if (Enable_CG_Peephole) {
01541 #endif
01542 Set_Error_Phase("Extended Block Optimizer");
01543 Start_Timer(T_EBO_CU);
01544 EBO_Post_Process_Region (region ? REGION_get_rid(rwn) : NULL);
01545 Stop_Timer ( T_EBO_CU );
01546 Check_for_Dump ( TP_EBO, NULL );
01547 }
01548
01549 #ifdef TARG_IA64
01550 if (IPFEC_Enable_Postpass_LOCS) {
01551 if (IPFEC_sched_care_machine!=Sched_care_bundle) {
01552 Local_Insn_Sched(FALSE);
01553 CGGRP_Bundle();
01554 }
01555 else if (CG_opt_level <1){
01556 IPFEC_sched_care_machine = Sched_care_nothing;
01557 CGGRP_Bundle();
01558 }
01559 else{
01560 Local_Insn_Sched(FALSE);
01561 }
01562 } else {
01563 if (PRDB_Valid()) Delete_PRDB();
01564 IGLS_Schedule_Region (FALSE );
01565 }
01566 #ifdef Is_True_On
01567 if (IPFEC_Enable_BB_Verify) {
01568 BB_Verify_Flags();
01569 }
01570 #endif
01571
01572 if(PRDB_Valid()) Delete_PRDB();
01573 if (IPFEC_Force_CHK_Fail)
01574 Force_Chk_Fail();
01575
01576 if (CG_opt_level > 1 && IPFEC_Enable_Post_Multi_Branch) {
01577 Post_Multi_Branch();
01578 }
01579 Reuse_Temp_TNs = orig_reuse_temp_tns;
01580
01581 if (PRDB_Valid()) Delete_PRDB();
01582 if (IPFEC_Enable_Region_Formation) {
01583
01584
01585
01586
01587 IPFEC_Enable_Region_Formation = FALSE;
01588 CFLOW_Delete_Empty_BB();
01589 IPFEC_Enable_Region_Formation = TRUE;
01590 }
01591 #else // TARG_IA64
01592
01593 #if defined (TARG_SL)
01594 if (!region) {
01595 CFLOW_Optimize(CFLOW_FREQ_ORDER, "CFLOW (forth pass)");
01596 CFLOW_Optimize(CFLOW_BRANCH | CFLOW_UNREACHABLE | CFLOW_COLD_REGION, "CFLOW (fifth pass)");
01597 }
01598
01599
01600 if (!region && CG_Gen_16bit && (CG_opt_level > 1)) {
01601 Replace_Size16_Instr();
01602 Check_for_Dump_ALL ( TP_CGEXP, NULL, "gen16bit op" );
01603 }
01604
01605 if (RGN_Enable_All_Scheduling) {
01606 if( CG_Enable_Regional_Local_Sched &&
01607 LOCS_POST_Enable_Scheduling &&
01608 CG_opt_level > 1) {
01609 Local_Insn_Sched(FALSE);
01610 Check_for_Dump_ALL ( TP_CGEXP, NULL, "Post LIS" );
01611 }
01612 }
01613
01614 if (CG_Enable_Macro_Instr_Combine && CG_opt_level > 1)
01615 Move_Macro_Insn_Together();
01616
01617 if (!region && CG_Gen_16bit)
01618 Guarantee_Paired_instr16();
01619 if (CG_check_quadword) {
01620 Check_Br16();
01621 }
01622
01623 #else
01624 IGLS_Schedule_Region (FALSE );
01625 #endif
01626
01627 #if defined(TARG_MIPS) && !defined(TARG_SL)
01628
01629
01630
01631 if (Enable_CG_Peephole) {
01632 Set_Error_Phase("Extended Block Optimizer (after second insn scheduling)");
01633 Start_Timer(T_EBO_CU);
01634 EBO_Post_Process_Region_2 (region ? REGION_get_rid(rwn) : NULL);
01635 Stop_Timer ( T_EBO_CU );
01636 Check_for_Dump ( TP_EBO, NULL );
01637 }
01638 #endif
01639
01640 #ifdef TARG_X8664
01641 {
01642
01643 extern void Convert_x87_Regs( MEM_POOL* );
01644 Convert_x87_Regs( &MEM_local_region_pool );
01645
01646
01647
01648
01649 if( Is_Target_32bit() ){
01650 for( BB* bb = REGION_First_BB; bb != NULL; bb = BB_next(bb) ){
01651 if( BB_call(bb) )
01652 Adjust_SP_After_Call( bb );
01653 }
01654 }
01655 }
01656 #endif
01657
01658 #if defined(KEY) && (defined(TARG_MIPS) && !defined(TARG_SL))
01659 CFLOW_Fixup_Long_Branches();
01660 #endif
01661
01662 Reuse_Temp_TNs = orig_reuse_temp_tns;
01663
01664 #endif // TARG_IA64
01665
01666 #else // TARG_NVISA
01667
01668
01669 if (CG_opt_level > 0 && CFLOW_opt_before_cgprep) {
01670
01671
01672 CFLOW_Optimize( (CFLOW_ALL_OPTS|CFLOW_IN_CGPREP)
01673 & ~(CFLOW_FREQ_ORDER | CFLOW_REORDER),
01674 "CFLOW (first pass)");
01675 }
01676
01677 if (CG_opt_level > 0) {
01678
01679
01680 Calculate_Dominators();
01681
01682
01683
01684 Set_Error_Phase("Create Unique Defs");
01685 Create_Unique_Defs_For_TNs();
01686 Check_for_Dump ( TP_EBO, NULL );
01687
01688
01689
01690
01691
01692
01693 if (CG_vector_loadstore) {
01694
01695 Set_Error_Phase("Extended Block Optimizer - vectors");
01696 Create_Vector_Load_Stores();
01697 Check_for_Dump ( TP_EBO, NULL );
01698 }
01699
01700
01701
01702 if (CG_use_16bit_ops) {
01703 Set_Error_Phase("Use 16bit Ops");
01704 Use_16bit_Ops();
01705 Check_for_Dump ( TP_EBO, NULL );
01706 }
01707 }
01708
01709
01710
01711 Set_Error_Phase ( "Register Allocation" );
01712 Assign_Virtual_Registers();
01713 Check_for_Dump (TP_ALLOC, NULL);
01714
01715 if (CG_opt_level > 0) {
01716
01717 Start_Timer(T_EBO_CU);
01718
01719
01720 REG_LIVE_Analyze_Region();
01721 (void) LOOP_DESCR_Detect_Loops (&MEM_local_pool);
01722
01723 if (CG_optimize_copies) {
01724
01725 Set_Error_Phase("Optimize Copies");
01726 Optimize_Copy_Usage();
01727 Check_for_Dump ( TP_EBO, NULL );
01728 }
01729
01730 if (CG_rematerialize_grf) {
01731
01732
01733
01734 Set_Error_Phase("Extended Block Optimizer - rematerialize");
01735 Rematerialize_GRF();
01736 Check_for_Dump ( TP_EBO, NULL );
01737 }
01738 REG_LIVE_Finish();
01739 Free_Dominators_Memory();
01740
01741 Stop_Timer ( T_EBO_CU );
01742 }
01743 #endif // TARG_NVISA
01744
01745 if (region) {
01746 #ifdef TARG_NVISA
01747 FmtAssert(FALSE, ("regions not supported"));
01748 return rwn;
01749 #else
01750
01751
01752
01753
01754 WN *inner_body, *outer_body, *exitBlock, *comment;
01755 WN *rwn_new, *result_block_before, *result_block_after;
01756 RID *rid_orig;
01757 char str[100];
01758
01759 Is_True(REGION_consistency_check(rwn),("CG_Generate_Code"));
01760 rid_orig = REGION_get_rid(rwn);
01761
01762
01763
01764
01765 outer_body = WN_CreateBlock();
01766
01767 WN_INSERT_BlockFirst(outer_body, rwn);
01768
01769 exitBlock = CGRIN_nested_exit(RID_cginfo(rid_orig));
01770 WN_region_exits(rwn) = exitBlock;
01771
01772 rwn_new = outer_body;
01773
01774
01775 inner_body = WN_CreateBlock();
01776 WN_region_body(rwn) = inner_body;
01777 sprintf(str,"RGN %d has been lowered to MOPs, level=%s",
01778 RID_id(rid_orig), RID_level_str(rid_orig));
01779 comment = WN_CreateComment(str);
01780 WN_INSERT_BlockFirst(inner_body, comment);
01781
01782
01783
01784
01785
01786
01787 result_block_before = WN_CreateBlock();
01788 result_block_after = WN_CreateBlock();
01789
01790
01791 Set_Error_Phase("Region Finalize");
01792 Start_Timer(T_Region_Finalize_CU);
01793 CG_Region_Finalize( result_block_before, result_block_after,
01794 rwn, alias_mgr, TRUE );
01795 Stop_Timer(T_Region_Finalize_CU);
01796
01797
01798 REGION_update_alias_info(result_block_before, alias_mgr);
01799 REGION_update_alias_info(result_block_after, alias_mgr);
01800
01801
01802 WN_INSERT_BlockFirst( rwn_new, result_block_before );
01803 WN_INSERT_BlockLast( rwn_new, result_block_after );
01804
01805 GRA_LIVE_Finish_REGION();
01806 PQSCG_term();
01807
01808 Stop_Timer ( T_CodeGen_CU );
01809 Set_Error_Phase ( "Codegen Driver" );
01810
01811 #ifdef TARG_IA64
01812 if(IPFEC_Enable_Region_Formation) CXX_DELETE(region_tree, &MEM_pu_pool);
01813 #endif
01814
01815 return rwn_new;
01816 #endif // TARG_NVISA
01817 }
01818
01819 #if defined(TARG_IA64)
01820 else {
01821
01822 if (Get_Trace (TP_EH, 0x0001)) {
01823 Print_PU_EH_Entry(Get_Current_PU(), WN_st(rwn), TFile);
01824 }
01825
01826
01827
01828
01829
01830 if (PU_has_exc_scopes(Get_Current_PU()) &&
01831 pu_need_LSDA ) {
01832 EH_Write_Range_Table(rwn);
01833 }
01834
01835 if (Get_Trace (TP_EH, 0x0008)) {
01836 EH_Dump_LSDA (TFile);
01837 }
01838 #else
01839 else {
01840 #if !defined(TARG_NVISA)
01841 if (PU_has_exc_scopes(Get_Current_PU())) {
01842 EH_Write_Range_Table(rwn);
01843 }
01844 #endif
01845 #endif //TARG_IA64 This is not a good merge compared to the code in trunk
01846
01847 #if defined(TARG_SL)
01848 Collect_Simd_Register_Usage();
01849
01850 if (Is_Target_Sl1_pcore() || Is_Target_Sl1_dsp()) {
01851 SL1_patch();
01852 }
01853 #endif
01854
01855
01856
01857
01858
01859
01860
01861
01862 Set_Error_Phase ( "Assembly" );
01863 Start_Timer ( T_Emit_CU );
01864 #ifdef TARG_IA64
01865 if (Create_Cycle_Output)
01866 Cycle_Count_Initialize(Get_Current_PU_ST(), region);
01867
01868
01869
01870 Instru_Call_Mcount();
01871 #endif
01872 EMT_Emit_PU (Get_Current_PU_ST(), pu_dst, rwn);
01873 Check_for_Dump (TP_EMIT, NULL);
01874 Stop_Timer ( T_Emit_CU );
01875
01876 #ifndef TARG_NVISA
01877 #ifdef TARG_IA64
01878 if (ORC_Enable_Cache_Analysis) Cache_Analysis_End();
01879 #endif
01880 Set_Error_Phase("Region Finalize");
01881 Start_Timer(T_Region_Finalize_CU);
01882 CG_Region_Finalize( NULL, NULL, rwn, alias_mgr,
01883 FALSE );
01884 Stop_Timer(T_Region_Finalize_CU);
01885
01886 GRA_LIVE_Finish_PU();
01887 PQSCG_term();
01888 #endif // TARG_NVISA
01889
01890
01891 if ( List_Symbols )
01892 Print_symtab (Lst_File, CURRENT_SYMTAB);
01893
01894 Stop_Timer ( T_CodeGen_CU );
01895 Set_Error_Phase ( "Codegen Driver" );
01896 #ifdef TARG_IA64
01897 if(IPFEC_Enable_Region_Formation) CXX_DELETE(region_tree, &MEM_pu_pool);
01898 #endif
01899 return rwn;
01900 }
01901 }
01902
01903
01904
01905
01906
01907 void
01908 Trace_IR(
01909 #ifdef TARG_IA64
01910 INT phase,
01911 const char *pname,
01912 BB *cur_bb,
01913 BOOL after)
01914 #else
01915 INT phase,
01916 const char *pname,
01917 BB *cur_bb)
01918 #endif
01919 {
01920 INT cur_bb_id = cur_bb ? BB_id(cur_bb) : 0;
01921 if ( Get_Trace(TKIND_IR, phase)
01922 && (cur_bb_id == 0 || Get_BB_Trace(cur_bb_id)))
01923 {
01924 #ifdef TARG_IA64
01925 if(after)
01926 fprintf(TFile, "\n%s%s\tIR after %s(BEGIN) PU:%d\n%s%s\n ",
01927 DBar, DBar, pname, Current_PU_Count(), DBar, DBar);
01928 else
01929 fprintf(TFile, "\n%s%s\tIR before %s(BEGIN) PU:%d\n%s%s\n ",
01930 DBar, DBar, pname, Current_PU_Count(), DBar, DBar);
01931 #else
01932 fprintf(TFile, "\n%s%s\tIR after %s\n%s%s\n",
01933 DBar, DBar, pname, DBar, DBar);
01934 #endif
01935 if (cur_bb != NULL) {
01936 Print_BB(cur_bb);
01937 } else {
01938 BB *bb;
01939 for (bb = REGION_First_BB; bb; bb = BB_next(bb)) {
01940 if (Get_BB_Trace(BB_id(bb)) && Get_Trace(TKIND_IR, phase)) {
01941 Print_BB(bb);
01942 }
01943 }
01944 }
01945 fprintf(TFile, "%s%s\n", DBar, DBar);
01946 #ifdef TARG_IA64
01947 if(after)
01948 fprintf(TFile, "\n%s%s\tIR after %s(END) PU:%d\n%s%s\n ",
01949 DBar, DBar, pname, Current_PU_Count(), DBar, DBar);
01950 else
01951 fprintf(TFile, "\n%s%s\tIR before %s(END) PU:%d\n%s%s\n ",
01952 DBar, DBar, pname, Current_PU_Count(), DBar, DBar);
01953 #endif
01954 }
01955 }
01956
01957 static void
01958 Trace_TN (
01959 INT phase,
01960 const char *pname )
01961 {
01962 if ( Get_Trace ( TKIND_TN, phase ) ) {
01963 fprintf ( TFile, "\n%s%s\tTNs after %s\n%s%s\n",
01964 DBar, DBar, pname, DBar, DBar );
01965 Print_TNs ();
01966 }
01967 }
01968
01969 static void
01970 Trace_ST (
01971 INT phase,
01972 const char *pname )
01973 {
01974 if ( Get_Trace ( TKIND_SYMTAB, phase ) ) {
01975 fprintf ( TFile, "\n%s%s\tSymbol table after %s\n%s%s\n",
01976 DBar, DBar, pname, DBar, DBar );
01977 SYMTAB_IDX level = CURRENT_SYMTAB;
01978 while (level >= GLOBAL_SYMTAB) {
01979 Print_symtab (TFile, level);
01980 --level;
01981 }
01982 }
01983 }
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995 void
01996 Check_for_Dump ( INT32 pass, BB *bb )
01997 {
01998 if (bb == NULL || Get_BB_Trace(BB_id(bb))) {
01999 const char *s = Get_Error_Phase();
02000
02001
02002
02003 Trace_ST ( pass, s );
02004
02005
02006
02007 Trace_TN ( pass, s );
02008
02009
02010
02011 Trace_IR ( pass, s, bb );
02012
02013
02014
02015 Trace_Memory_Allocation ( pass, s );
02016 }
02017 }
02018
02019 BOOL
02020 Get_Trace ( INT func, INT arg, BB *bb )
02021 {
02022 BOOL result = Get_Trace(func, arg);
02023
02024
02025 if ( result && bb ) {
02026 result = Get_BB_Trace ( BB_id(bb) );
02027 }
02028
02029 return result;
02030 }
02031
02032
02033 void
02034 CG_Dump_Region(FILE *fd, WN *wn)
02035 {
02036 RID *rid = REGION_get_rid(wn);
02037 Is_True(rid != NULL, ("CG_Dump_Region, NULL RID"));
02038 if (rid && RID_level(rid) >= RL_CGSCHED) {
02039 CGRIN *cgrin = RID_cginfo(rid);
02040 if (cgrin && CGRIN_entry(cgrin)) {
02041 BB *bb;
02042 for (bb=CGRIN_entry(cgrin); bb; bb=BB_next(bb))
02043 Print_BB( bb );
02044 }
02045 }
02046 }
02047
02048 void
02049 CG_Dump_Cur_Region()
02050 {
02051 BB *bb;
02052 for( bb=REGION_First_BB; bb; bb=BB_next(bb) ){
02053 Print_BB( bb );
02054 }
02055 }
02056
02057
02058 extern void
02059 CG_Change_Elf_Symbol_To_Undefined (ST *st)
02060 {
02061 EMT_Change_Symbol_To_Undefined(st);
02062 }
02063