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 #define __STDC_LIMIT_MACROS
00043 #include <stdint.h>
00044 #if defined(BUILD_OS_DARWIN)
00045 #include <darwin_elf.h>
00046 #else
00047 #include <elf.h>
00048 #endif
00049 #include <sys/types.h>
00050
00051 #include "defs.h"
00052 #include "stab.h"
00053 #include "wn.h"
00054 #include "pu_info.h"
00055 #include "ir_bwrite.h"
00056 #include "ir_bcom.h"
00057 #include "ipl_summary.h"
00058 #include "ipl_summarize.h"
00059 #include "ipl_array_bread_write.h"
00060 #include "loop_info.h"
00061
00062 ARRAY_SUMMARY_OUTPUT *Array_Summary_Output;
00063
00064 static INT ivar_offset = 0;
00065 static INT regions_offset = 0;
00066
00067
00068
00069
00070 static BOOL
00071 PU_has_messy_regions(ARRAY_SUMMARY* summary)
00072 {
00073 INT i, cfg_node_count;
00074 INT j, ra_count;
00075 INT k, pr_count;
00076 ARRAY_OF_REGION_ARRAYS* ara;
00077 PROJECTED_REGION_INFO_ARRAY* pra;
00078
00079 INT* map = summary->Get_cd_map();
00080
00081
00082 cfg_node_count = summary->Get_cfg_node_array_count();
00083 for (i = 0; i < cfg_node_count; ++i) {
00084
00085 CFG_NODE_INFO* cfg_node = summary->Get_cfg_node_array(i);
00086 if (!cfg_node->Is_else())
00087 cfg_node = summary->Get_cfg_node_array(map[i]);
00088
00089
00090 ara = cfg_node->Get_def_array();
00091 ra_count = ara ? ara->Lastidx()+1 : 0;
00092 for (j = 0; j < ra_count; ++j) {
00093 pra = (*ara)[j].Get_projected_region_array();
00094 pr_count = pra->Lastidx();
00095 for (k = 0; k <= pr_count; ++k) {
00096 if ((*pra)[k].Get_projected_region()->Is_messy_region())
00097 return TRUE;
00098 }
00099 }
00100
00101
00102 ara = cfg_node->Get_use_array();
00103 ra_count = ara ? ara->Lastidx()+1 : 0;
00104 for (j = 0; j < ra_count; ++j) {
00105 pra = (*ara)[j].Get_projected_region_array();
00106 pr_count = pra->Lastidx();
00107 for (k = 0; k <= pr_count; ++k) {
00108 if ((*pra)[k].Get_projected_region()->Is_messy_region())
00109 return TRUE;
00110 }
00111 }
00112
00113
00114 ara = cfg_node->Get_param_array();
00115 ra_count = ara ? ara->Lastidx()+1 : 0;
00116 for (j = 0; j < ra_count; ++j) {
00117 pra = (*ara)[j].Get_projected_region_array();
00118 pr_count = pra->Lastidx();
00119 for (k = 0; k <= pr_count; ++k) {
00120 if ((*pra)[k].Get_projected_region()->Is_messy_region())
00121 return TRUE;
00122 }
00123 }
00124
00125
00126 ara = cfg_node->Get_formal_array();
00127 ra_count = ara ? ara->Lastidx()+1 : 0;
00128 for (j = 0; j < ra_count; ++j) {
00129 pra = (*ara)[j].Get_projected_region_array();
00130 pr_count = pra->Lastidx();
00131 for (k = 0; k <= pr_count; ++k) {
00132 if ((*pra)[k].Get_projected_region()->Is_messy_region())
00133 return TRUE;
00134 }
00135 }
00136
00137
00138 }
00139
00140 return FALSE;
00141 }
00142
00143
00144
00145
00146 void
00147 Init_write_asections(MEM_POOL* pool)
00148 {
00149 Array_Summary_Output = CXX_NEW(ARRAY_SUMMARY_OUTPUT(pool), pool);
00150 }
00151
00152
00153
00154
00155
00156 void
00157 Map_asections(ARRAY_SUMMARY *summary, SUMMARY_PROCEDURE *p)
00158 {
00159 INT start_idx = Array_Summary_Output->Get_cfg_node_count()+1;
00160 p->Set_array_section_index(start_idx);
00161 Array_Summary_Output->Map_summary_info(summary);
00162 INT end_idx = Array_Summary_Output->Get_cfg_node_count()+1;
00163 p->Set_array_section_count(end_idx-start_idx);
00164 if (PU_has_messy_regions(summary))
00165 p->Set_has_messy_regions();
00166 }
00167
00168
00169
00170
00171 void
00172 ARRAY_SUMMARY_OUTPUT::Write_summary(struct output_file *f2,
00173 INT cur_sec_disp)
00174 {
00175 INT size;
00176
00177 Output_File *fl = (Output_File*) f2;
00178
00179 if (Get_term_count() != -1)
00180 {
00181 size = (Get_term_count() + 1) * sizeof(TERM);
00182
00183 offset_term = (INT) ir_b_save_buf (Get_term (0),
00184 size, sizeof(INT64), 0, fl);
00185 offset_term -= cur_sec_disp;
00186 }
00187
00188
00189
00190 if (Get_projected_node_count() != -1)
00191 {
00192 size = (Get_projected_node_count() + 1) * sizeof(PROJECTED_NODE);
00193
00194 offset_projected_node = (INT) ir_b_save_buf (Get_projected_node (0),
00195 size, sizeof(INT64), 0, fl);
00196 offset_projected_node -= cur_sec_disp;
00197 }
00198
00199
00200 if (Get_projected_region_count() != -1)
00201 {
00202 size = (Get_projected_region_count() + 1) * sizeof(PROJECTED_REGION);
00203
00204 offset_projected_region =
00205 (INT) ir_b_save_buf (Get_projected_region (0),
00206 size, sizeof(INT64), 0, fl);
00207 offset_projected_region -= cur_sec_disp;
00208 }
00209
00210
00211 if (Get_region_count() != -1)
00212 {
00213 size = (Get_region_count() + 1) * sizeof(REGION_ARRAYS);
00214
00215 offset_region = (INT) ir_b_save_buf (Get_region_array(0),
00216 size, sizeof(INT64), 0, fl);
00217 offset_region -= cur_sec_disp;
00218 }
00219
00220
00221 if (Get_cfg_node_count() != -1)
00222 {
00223 size = (Get_cfg_node_count() + 1) * sizeof(CFG_NODE_INFO);
00224
00225 offset_cfg_node = (INT) ir_b_save_buf (Get_cfg_node (0),
00226 size, sizeof(INT64), 0, fl);
00227 offset_cfg_node -= cur_sec_disp;
00228 }
00229
00230
00231 if (Get_ivar_count() != -1)
00232 {
00233 size = (Get_ivar_count() + 1) * sizeof(IVAR);
00234
00235 offset_ivar = (INT) ir_b_save_buf (Get_ivar (0),
00236 size, sizeof(INT64), 0, fl);
00237 offset_ivar -= cur_sec_disp;
00238 }
00239
00240
00241 if (Get_loopinfo_count() != -1)
00242 {
00243 size = (Get_loopinfo_count() + 1) * sizeof(LOOPINFO);
00244 offset_loop_info = (INT) ir_b_save_buf (Get_loopinfo (0),
00245 size, sizeof(INT64), 0, fl);
00246 offset_loop_info -= cur_sec_disp;
00247 }
00248
00249
00250 if (Get_scalars_count() != -1)
00251 {
00252 size = (Get_scalars_count() + 1) * sizeof(SCALAR_INFO);
00253 offset_scalars = (INT) ir_b_save_buf (Get_scalars (0),
00254 size, sizeof(INT64), 0, fl);
00255 offset_scalars -= cur_sec_disp;
00256 }
00257 }
00258
00259
00260
00261
00262 void
00263 ARRAY_SUMMARY_OUTPUT::Update_array_sect_header(SUMMARY_FILE_HEADER *header_addr)
00264 {
00265 header_addr->Set_cfg_node_offset(offset_cfg_node);
00266 header_addr->Set_regions_array_offset(offset_region);
00267 header_addr->Set_projected_region_offset(offset_projected_region);
00268 header_addr->Set_projected_array_offset(offset_projected_node);
00269 header_addr->Set_term_array_offset(offset_term);
00270 header_addr->Set_ivar_offset(offset_ivar);
00271 header_addr->Set_loopinfo_offset(offset_loop_info);
00272 header_addr->Set_scalar_node_offset(offset_scalars);
00273
00274 header_addr->Set_cfg_node_entry_size(sizeof(CFG_NODE_INFO));
00275 header_addr->Set_regions_array_entry_size(sizeof(REGION_ARRAYS));
00276 header_addr->Set_projected_region_entry_size(sizeof(PROJECTED_REGION));
00277 header_addr->Set_projected_array_entry_size(sizeof(PROJECTED_NODE));
00278 header_addr->Set_term_array_entry_size(sizeof(TERM));
00279 header_addr->Set_ivar_entry_size(sizeof(IVAR));
00280 header_addr->Set_loopinfo_entry_size(sizeof(LOOPINFO));
00281 header_addr->Set_scalar_node_entry_size(sizeof(SCALAR_INFO));
00282
00283 header_addr->Set_cfg_node_size(Get_cfg_node_count()+1);
00284 header_addr->Set_regions_array_size(Get_region_count()+1);
00285 header_addr->Set_projected_region_size(Get_projected_region_count()+1);
00286 header_addr->Set_projected_array_size(Get_projected_node_count()+1);
00287 header_addr->Set_term_array_size(Get_term_count() + 1);
00288 header_addr->Set_ivar_size(Get_ivar_count() + 1);
00289 header_addr->Set_loopinfo_size(Get_loopinfo_count() + 1);
00290 header_addr->Set_scalar_node_size(Get_scalars_count() + 1);
00291 }
00292
00293
00294
00295
00296
00297 static void
00298 update_actual_indices(ARRAY_SUMMARY *summary)
00299 {
00300 INT count = 0;
00301 INT_IDS* actual_scalar_info_map = summary->Get_actual_scalar_info_map();
00302 INT actual_count = summary->Get_actual_count();
00303 INT start_idx = summary->Get_actual_start_idx();
00304 INT end_idx = start_idx + actual_count;
00305
00306 for (INT i= start_idx; i<end_idx; ++ i)
00307 {
00308 SUMMARY_ACTUAL* actual = Summary->Get_actual(i);
00309 if (actual_scalar_info_map[count].Get_id() > 0)
00310 {
00311 INT cd_idx = actual_scalar_info_map[count].Get_cd_idx();
00312 INT scalar_offset = actual_scalar_info_map[count].Get_id();
00313 CFG_NODE_INFO *cfg_node = summary->Get_cfg_node_array(cd_idx);
00314 INT cfg_offset = cfg_node->Get_scalar_index();
00315 if (actual->Get_pass_type() != PASS_ARRAY_SECTION)
00316 actual->Set_index(scalar_offset+ cfg_offset-1);
00317 }
00318 ++count;
00319 }
00320 }
00321
00322
00323
00324
00325 static void
00326 update_formal_indices(ARRAY_SUMMARY *summary,
00327 INT array_of_region_arrays)
00328 {
00329 INT idx_formal = summary->Get_formal_start_idx();
00330 INT formal_count = summary->Get_formal_count();
00331 for (INT i = idx_formal; i < idx_formal + formal_count; i++) {
00332 SUMMARY_FORMAL* sf = Summary->Get_formal(i);
00333 if (sf->Get_region_index() >= 0)
00334 sf->Set_region_index(array_of_region_arrays + sf->Get_region_index());
00335 }
00336 }
00337
00338
00339
00340
00341 void
00342 ARRAY_SUMMARY_OUTPUT::Map_summary_info(ARRAY_SUMMARY *summary)
00343 {
00344 INT idx, id;
00345 REGION_ARRAYS* rarray;
00346 INT count, offset;
00347 SCALAR_INFO *item, *v;
00348 BOOL Do_mapping = FALSE;
00349 INT total_pass_count = 0;
00350
00351 offset = 0;
00352
00353
00354
00355 INT cfg_node_count = summary->Get_cfg_node_array_count();
00356 INT lastidx = _cfg_nodes->Lastidx() + 1;
00357 INT* map = summary->Get_cd_map();
00358 BOOL found_scalar_actuals = FALSE;
00359 INT local_regions_count = 0;
00360 INT i,j;
00361
00362
00363 for (i=0; i< cfg_node_count; ++i)
00364 {
00365
00366 CFG_NODE_INFO* cfg_node = summary->Get_cfg_node_array(i);
00367 if (!cfg_node->Is_else())
00368 cfg_node = summary->Get_cfg_node_array(map[i]);
00369
00370 idx = _cfg_nodes->Newidx();
00371 CFG_NODE_INFO* cfg_node_out = &(*_cfg_nodes)[idx];
00372 cfg_node_out->Init_Out();
00373
00374 if (cfg_node->Is_if()) cfg_node_out->Set_type_if();
00375 else if (cfg_node->Is_do_loop()) cfg_node_out->Set_type_do_loop();
00376 else if (cfg_node->Is_entry()) cfg_node_out->Set_type_entry();
00377 else if (cfg_node->Is_else()) cfg_node_out->Set_type_else();
00378
00379 if (cfg_node_out->Has_calls()) cfg_node_out->Set_has_calls();
00380 if (cfg_node_out->Is_executed()) cfg_node_out->Set_is_executed();
00381
00382 cfg_node_out->Set_cd_index(cfg_node->Get_cd_index());
00383
00384
00385 ARRAY_OF_REGION_ARRAYS* def_array = cfg_node->Get_def_array();
00386 if (def_array)
00387 count = def_array->Lastidx() + 1;
00388 else
00389 count = 0;
00390 for (j=0; j<count;++j)
00391 {
00392 rarray = &(*def_array)[j];
00393 id = Map_region_arrays(rarray);
00394 if (j==0)
00395 {
00396 cfg_node_out->Set_def_count(count);
00397 cfg_node_out->Set_def_index(id);
00398 }
00399 }
00400
00401
00402 ARRAY_OF_REGION_ARRAYS* use_array = cfg_node->Get_use_array();
00403 if (use_array)
00404 count = use_array->Lastidx() + 1;
00405 else
00406 count = 0;
00407 for (j=0; j<count;++j)
00408 {
00409 rarray = &(*use_array)[j];
00410 id = Map_region_arrays(rarray);
00411 if (j == 0)
00412 {
00413 cfg_node_out->Set_use_count(count);
00414 cfg_node_out->Set_use_index(id);
00415 }
00416 }
00417
00418
00419 ARRAY_OF_REGION_ARRAYS* param_array =
00420 cfg_node->Get_param_array();
00421
00422 if (param_array)
00423 count = param_array->Lastidx() + 1;
00424 else
00425 count = 0;
00426
00427 INT id_base = -1;
00428 for (j=0; j<count;++j)
00429 {
00430 rarray = &(*param_array)[j];
00431 id = Map_region_arrays(rarray);
00432 if (id_base == -1)
00433 id_base = id;
00434 if (j == 0)
00435 {
00436 cfg_node_out->Set_param_count(count);
00437 cfg_node_out->Set_param_index(id);
00438 }
00439 }
00440
00441
00442 if (id_base != -1) {
00443 INT k;
00444 DYN_ARRAY<SUMMARY_ACTUAL*> sa_actuals(summary->Get_local_pool());
00445
00446 for (k = 0; k < count; k++) {
00447 REGION_ARRAYS* ra = &(*param_array)[k];
00448 PROJECTED_REGION_INFO_ARRAY* pria = ra->Get_projected_region_array();
00449 PROJECTED_REGION_INFO* pri = &(*pria)[0];
00450 PROJECTED_REGION* pr = pri->Get_projected_region();
00451 INT callsite_index = pr->Get_callsite_id();
00452 SUMMARY_CALLSITE* sc = Summary->Get_callsite(callsite_index);
00453 INT idx_actual = sc->Get_actual_index();
00454 INT actual_count = sc->Get_param_count();
00455 for (j = idx_actual; j < idx_actual + actual_count; j++) {
00456 SUMMARY_ACTUAL* sa = Summary->Get_actual(j);
00457 if (sa->Get_pass_type() == PASS_ARRAY_SECTION
00458 && sa->Get_index() == k) {
00459 INT actual_index = sa_actuals.Newidx();
00460 sa_actuals[actual_index] = sa;
00461 break;
00462 }
00463 }
00464 FmtAssert(j < idx_actual + actual_count,
00465 ("Map_summary_info(): Expected to find SUMMARY_ACTUAL"));
00466 }
00467
00468 for (k = 0; k < count; k++) {
00469 SUMMARY_ACTUAL* sa = sa_actuals[k];
00470 sa->Set_index(id_base + sa->Get_index());
00471 }
00472 }
00473
00474
00475 ARRAY_OF_REGION_ARRAYS* formal_array =
00476 cfg_node->Get_formal_array();
00477
00478 if (formal_array)
00479 count = formal_array->Lastidx() + 1;
00480 else
00481 count = 0;
00482
00483 id_base = -1;
00484 for (j=0; j<count;++j)
00485 {
00486 rarray = &(*formal_array)[j];
00487 id = Map_region_arrays(rarray);
00488 if (id_base == -1)
00489 id_base = id;
00490 if (j == 0)
00491 {
00492 cfg_node_out->Set_formal_count(count);
00493 cfg_node_out->Set_formal_index(id);
00494 }
00495 }
00496
00497 if (id_base != -1) {
00498 INT idx_formal = summary->Get_formal_start_idx();
00499 INT formal_count = summary->Get_formal_count();
00500
00501 for (INT k = idx_formal; k < idx_formal + formal_count; k++) {
00502 SUMMARY_FORMAL* sf = Summary->Get_formal(k);
00503 if (sf->Get_region_index() >= 0)
00504 sf->Set_region_index(id_base + sf->Get_region_index());
00505 }
00506 }
00507
00508
00509
00510 LOOPINFO *loop_info;
00511 if (cfg_node->Is_do_loop())
00512 {
00513
00514 loop_info = cfg_node->Get_loopinfo();
00515 if (loop_info)
00516 {
00517 INT lindex = Map_loop_info(loop_info);
00518 cfg_node_out->Set_loop_index(lindex);
00519 }
00520 }
00521
00522 if (cfg_node->Is_if())
00523 {
00524 cfg_node_out->Set_else_index(cfg_node->Get_else_index() +
00525 lastidx);
00526 CFG_NODE_INFO *cfg_node_else =
00527 summary->Get_cfg_node_array(cfg_node->Get_else_index());
00528 cfg_node_else->Set_if_index(i);
00529 }
00530 else if (cfg_node->Is_else())
00531 {
00532 cfg_node_out->Set_if_index(cfg_node->Get_if_index() +
00533 lastidx);
00534 }
00535
00536
00537 INT_ARRAY* scalar_array = cfg_node->Get_scalar_array();
00538 if (scalar_array)
00539 count = cfg_node->Get_scalar_array()->Lastidx() + 1;
00540 else
00541 count = 0;
00542 if (count > 0)
00543 found_scalar_actuals = TRUE;
00544
00545 cfg_node_out->Set_scalar_count(count);
00546
00547 offset = 0;
00548 for (j=0; j<count;++j)
00549 {
00550 if (j==0)
00551 offset = _scalar_items->Lastidx()+1;
00552 item = &(*scalar_array)[j];
00553 id = _scalar_items->Newidx();
00554 v = &(*_scalar_items)[id];
00555 v->Set_id(item->Get_id());
00556 v->Set_type(item->Get_type());
00557 v->Set_callsite_id(item->Get_callsite_id());
00558
00559
00560
00561 if (item->Is_passed_ref() || item->Is_may_passed_ref())
00562 {
00563 Do_mapping = TRUE;
00564 }
00565 }
00566 cfg_node_out->Set_scalar_index(offset);
00567 cfg_node->Set_scalar_index(offset);
00568 }
00569
00570
00571 if (found_scalar_actuals && Do_mapping)
00572 {
00573 update_actual_indices(summary);
00574 }
00575 }
00576
00577
00578
00579
00580
00581 static void
00582 Mark_used_formal_symbols(ACCESS_VECTOR* av)
00583 {
00584
00585 if (av->Too_Messy) return;
00586
00587
00588 if (av->Contains_Lin_Symb()) {
00589 INTSYMB_ITER iter(av->Lin_Symb);
00590 for (INTSYMB_NODE* node=iter.First(); !iter.Is_Empty(); node=iter.Next()) {
00591 ST* s = node->Symbol.St();
00592 Mark_formal_summary_symbol(s);
00593 }
00594 }
00595
00596
00597 if (av->Contains_Non_Lin_Symb()) {
00598 SUMPROD_ITER iter(av->Non_Lin_Symb);
00599 for (SUMPROD_NODE* node=iter.First(); !iter.Is_Empty(); node=iter.Next()) {
00600 SYMBOL_ITER sym_iter(node->Prod_List);
00601 for (SYMBOL_NODE* sym_node = sym_iter.First();
00602 !sym_iter.Is_Empty();
00603 sym_node = sym_iter.Next()) {
00604 ST* s = sym_node->Symbol.St();
00605 Mark_formal_summary_symbol(s);
00606 }
00607 }
00608 }
00609 }
00610
00611
00612
00613
00614
00615 static void
00616 Mark_used_formal_symbols(ACCESS_ARRAY* aa)
00617 {
00618
00619 if (!aa->Too_Messy) {
00620 for (UINT16 i = 0; i < aa->Num_Vec(); ++i) {
00621 Mark_used_formal_symbols(aa->Dim(i));
00622 }
00623 }
00624 }
00625
00626
00627
00628
00629
00630 static void
00631 Mark_used_formal_symbols(DO_LOOP_INFO_BASE* dli)
00632 {
00633 Mark_used_formal_symbols(dli->Get_lb());
00634 Mark_used_formal_symbols(dli->Get_ub());
00635 Mark_used_formal_symbols(dli->Get_step());
00636 }
00637
00638
00639
00640
00641 INT
00642 ARRAY_SUMMARY_OUTPUT::Map_loop_info(LOOPINFO *l)
00643 {
00644
00645 DO_LOOP_INFO_BASE* dli = IPL_Loopinfo_Map->Find(l);
00646 if (dli) {
00647 Mark_used_formal_symbols(dli);
00648 }
00649
00650 INT idx = _loopinfo_nodes->Newidx();
00651 LOOPINFO* l_out = &(*_loopinfo_nodes)[idx];
00652 BZERO(l_out, sizeof(LOOPINFO));
00653 l_out->Set_nest_level(l->Get_nest_level());
00654 l_out->Set_flags(l->Get_flags());
00655
00656 if (!l->Is_messy_ub()) {
00657 LINEX* upper = l->Get_upper_linex();
00658 for (INT j = 0; j <= upper->Num_terms(); ++j) {
00659 Map_term(upper->Get_term(j), upper->Get_term(j));
00660 }
00661 INT reuse_linex_idx = Search_for_terms(upper);
00662 if (reuse_linex_idx == 0) {
00663 for (INT j = 0; j <= upper->Num_terms(); ++j) {
00664 _terms->AddElement(*(upper->Get_term(j)));
00665 }
00666 INT first_term_idx = _terms->Lastidx() - upper->Num_terms();
00667 Insert_terms(upper->Get_term(0), first_term_idx, upper->Num_terms());
00668 l_out->Set_ub_term_index(first_term_idx);
00669 }
00670 else {
00671 l_out->Set_ub_term_index(reuse_linex_idx-1);
00672 }
00673 l_out->Set_ub_term_count(upper->Num_terms()+1);
00674 }
00675
00676 if (!l->Is_messy_lb()) {
00677 LINEX* lower = l->Get_lower_linex();
00678 for (INT j = 0; j <= lower->Num_terms(); ++j) {
00679 Map_term(lower->Get_term(j), lower->Get_term(j));
00680 }
00681 INT reuse_linex_idx = Search_for_terms(lower);
00682 if (reuse_linex_idx == 0) {
00683 for (INT j = 0; j <= lower->Num_terms(); ++j) {
00684 _terms->AddElement(*(lower->Get_term(j)));
00685 }
00686 INT first_term_idx = _terms->Lastidx() - lower->Num_terms();
00687 Insert_terms(lower->Get_term(0), first_term_idx, lower->Num_terms());
00688 l_out->Set_lb_term_index(first_term_idx);
00689 }
00690 else {
00691 l_out->Set_lb_term_index(reuse_linex_idx-1);
00692 }
00693 l_out->Set_lb_term_count(lower->Num_terms()+1);
00694 }
00695
00696 if (!l->Is_messy_step()) {
00697 LINEX* step = l->Get_step_linex();
00698 for (INT j = 0; j <= step->Num_terms(); ++j) {
00699 Map_term(step->Get_term(j), step->Get_term(j));
00700 }
00701 INT reuse_linex_idx = Search_for_terms(step);
00702 if (reuse_linex_idx == 0) {
00703 for (INT j = 0; j <= step->Num_terms(); ++j) {
00704 _terms->AddElement(*(step->Get_term(j)));
00705 }
00706 INT first_term_idx = _terms->Lastidx() - step->Num_terms();
00707 Insert_terms(step->Get_term(0), first_term_idx, step->Num_terms());
00708 l_out->Set_step_term_index(first_term_idx);
00709 }
00710 else {
00711 l_out->Set_step_term_index(reuse_linex_idx-1);
00712 }
00713 l_out->Set_step_term_count(step->Num_terms()+1);
00714 }
00715
00716 return idx+1;
00717 }
00718
00719
00720
00721
00722
00723 INT
00724 ARRAY_SUMMARY_OUTPUT::Map_region_arrays(REGION_ARRAYS* rarray)
00725 {
00726 INT idx = _region_arrays->Newidx();
00727 REGION_ARRAYS* r = &(*_region_arrays)[idx];
00728 r->Copy_write(rarray);
00729
00730 PROJECTED_REGION_INFO_ARRAY* proj_regions =
00731 rarray->Get_projected_region_array();
00732
00733 for (INT i = 0; i <= proj_regions->Lastidx(); ++i) {
00734 PROJECTED_REGION* proj_reg = (*proj_regions)[i].Get_projected_region();
00735 INT id = Map_projected_region(proj_reg);
00736 if (i == 0) {
00737 r->Set_idx(id);
00738 r->Set_count(proj_regions->Lastidx() + 1);
00739 }
00740 }
00741
00742 return idx;
00743 }
00744
00745
00746
00747
00748 INT
00749 ARRAY_SUMMARY_OUTPUT::Map_projected_region(PROJECTED_REGION *proj_reg)
00750 {
00751
00752 ACCESS_ARRAY* aa = IPL_Access_Array_Map->Find(proj_reg);
00753 if (aa) {
00754 Mark_used_formal_symbols(aa);
00755 }
00756
00757 INT idx = _projected_regions->Newidx();
00758 PROJECTED_REGION* p = &(*_projected_regions)[idx];
00759
00760 p->Copy_write(proj_reg);
00761
00762 if (proj_reg->Get_projected_array()) {
00763 p->Set_id(Map_proj_array(proj_reg->Get_projected_array()));
00764 }
00765 else {
00766 p->Set_id(-1);
00767 }
00768
00769 return idx;
00770 }
00771
00772
00773
00774
00775 INT
00776 ARRAY_SUMMARY_OUTPUT::Map_proj_array(PROJECTED_ARRAY* proj_array)
00777 {
00778 for (INT i = 0; i <= proj_array->Lastidx(); ++i) {
00779
00780 PROJECTED_NODE* p = &(*_project_nodes)[_project_nodes->Newidx()];
00781 BZERO (p, sizeof(PROJECTED_NODE));
00782
00783 PROJECTED_NODE* p_in = &(*proj_array)[i];
00784 p->Set_flags(p_in->Get_flags());
00785
00786 LINEX* upper = p_in->Get_upper_linex();
00787 if (!p_in->Is_messy_ub() && upper->Num_terms() != -1) {
00788 for (INT j = 0; j <= upper->Num_terms(); ++j) {
00789 Map_term(upper->Get_term(j), upper->Get_term(j));
00790 }
00791 INT reuse_linex_idx = Search_for_terms(upper);
00792 if (reuse_linex_idx == 0) {
00793 for (INT j = 0; j <= upper->Num_terms(); ++j) {
00794 _terms->AddElement(*(upper->Get_term(j)));
00795 }
00796 INT first_term_idx = _terms->Lastidx() - upper->Num_terms();
00797 Insert_terms(upper->Get_term(0), first_term_idx, upper->Num_terms());
00798 p->Set_ub_term_index(first_term_idx);
00799 }
00800 else {
00801 p->Set_ub_term_index(reuse_linex_idx-1);
00802 }
00803 p->Set_ub_term_count(upper->Num_terms()+1);
00804 }
00805
00806 LINEX* lower = p_in->Get_lower_linex();
00807 if (!p_in->Is_messy_lb() && lower->Num_terms() != -1) {
00808 for (INT j = 0; j <= lower->Num_terms(); ++j) {
00809 Map_term(lower->Get_term(j), lower->Get_term(j));
00810 }
00811 INT reuse_linex_idx = Search_for_terms(lower);
00812 if (reuse_linex_idx == 0) {
00813 for (INT j = 0; j <= lower->Num_terms(); ++j) {
00814 _terms->AddElement(*(lower->Get_term(j)));
00815 }
00816 INT first_term_idx = _terms->Lastidx() - lower->Num_terms();
00817 Insert_terms(lower->Get_term(0), first_term_idx, lower->Num_terms());
00818 p->Set_lb_term_index(first_term_idx);
00819 }
00820 else {
00821 p->Set_lb_term_index(reuse_linex_idx-1);
00822 }
00823 p->Set_lb_term_count(lower->Num_terms()+1);
00824 }
00825
00826 LINEX* step = p_in->Get_step_linex();
00827 if (!p_in->Is_messy_step() && step->Num_terms() != -1) {
00828 for (INT j = 0; j <= step->Num_terms(); ++j) {
00829 Map_term(step->Get_term(j), step->Get_term(j));
00830 }
00831 INT reuse_linex_idx = Search_for_terms(step);
00832 if (reuse_linex_idx == 0) {
00833 for (INT j = 0; j <= step->Num_terms(); ++j) {
00834 _terms->AddElement(*(step->Get_term(j)));
00835 }
00836 INT first_term_idx = _terms->Lastidx() - step->Num_terms();
00837 Insert_terms(step->Get_term(0), first_term_idx, step->Num_terms());
00838 p->Set_step_term_index(first_term_idx);
00839 }
00840 else {
00841 p->Set_step_term_index(reuse_linex_idx-1);
00842 }
00843 p->Set_step_term_count(step->Num_terms()+1);
00844 }
00845
00846 LINEX* segment_length = p_in->Get_segment_length_linex();
00847 if (segment_length) {
00848
00849
00850 Is_True(segment_length->Is_const(), ("segment length must be constant"));
00851
00852 INT reuse_linex_idx = Search_for_terms(segment_length);
00853 if (reuse_linex_idx == 0) {
00854 _terms->AddElement(*(segment_length->Get_term(0)));
00855 Insert_terms(segment_length->Get_term(0), _terms->Lastidx(), 0);
00856 p->Set_segment_length_term_index(_terms->Lastidx());
00857 }
00858 else {
00859 p->Set_segment_length_term_index(reuse_linex_idx-1);
00860 }
00861 p->Set_segment_length_term_count(1);
00862 }
00863
00864 LINEX* segment_stride = p_in->Get_segment_stride_linex();
00865 if (segment_stride) {
00866
00867
00868 Is_True(segment_stride->Is_const(), ("segment stride must be constant"));
00869
00870 INT reuse_linex_idx = Search_for_terms(segment_stride);
00871 if (reuse_linex_idx == 0) {
00872 _terms->AddElement(*(segment_stride->Get_term(0)));
00873 Insert_terms(segment_stride->Get_term(0), _terms->Lastidx(), 0);
00874 p->Set_segment_stride_term_index(_terms->Lastidx());
00875 }
00876 else {
00877 p->Set_segment_stride_term_index(reuse_linex_idx-1);
00878 }
00879 p->Set_segment_stride_term_count(1);
00880 }
00881
00882 }
00883
00884 return (proj_array->Lastidx() < 0 ?
00885 -1 :
00886 _project_nodes->Lastidx() - proj_array->Lastidx());
00887 }
00888
00889
00890
00891
00892 void
00893 ARRAY_SUMMARY_OUTPUT::Map_term(TERM* t_in, TERM* t_out)
00894 {
00895 new (t_out) TERM(t_in);
00896 }
00897
00898
00899
00900
00901 void
00902 ARRAY_SUMMARY_OUTPUT::Map_ivar_array(IVAR_ARRAY *ivar_array)
00903 {
00904 INT last_idx = ivar_array->Lastidx();
00905 for (INT i = 0; i <= last_idx; ++i) {
00906 _ivars->AddElement((*ivar_array)[i]);
00907 }
00908
00909 if (last_idx >= 0) {
00910 ivar_offset = _ivars->Lastidx() - last_idx;
00911 }
00912 }
00913
00914
00915
00916
00917 UINT64
00918 ARRAY_SUMMARY_OUTPUT::Get_key(TERM *t, INT num_terms)
00919 {
00920 UINT64 key = 0;
00921
00922 key |= ((UINT64) num_terms << 56);
00923 key |= ((UINT64) t->Get_type() << 48);
00924 key |= ((UINT64) t->Get_desc() << 32);
00925 key |= ((UINT64) t->Get_coeff());
00926
00927 return key;
00928 }
00929
00930
00931
00932
00933
00934
00935
00936 INT
00937 ARRAY_SUMMARY_OUTPUT::Search_for_terms(LINEX *l)
00938 {
00939
00940 TERM* t = l->Get_term(0);
00941 UINT64 key = Get_key(t, l->Num_terms());
00942 INTEGER_ARRAY* int_array = Get_term_hash_table()->Find(key);
00943
00944 if (int_array) {
00945 for (INT i = 0; i <= int_array->Lastidx(); ++i) {
00946 INT id = (*int_array)[i];
00947 if (Get_term(id)->Is_equal(t, l->Num_terms())) {
00948
00949 return id + 1;
00950 }
00951 }
00952 }
00953
00954 return 0;
00955 }
00956
00957
00958
00959
00960 void
00961 ARRAY_SUMMARY_OUTPUT::Insert_terms(TERM* t, INT idx, INT count)
00962 {
00963 UINT64 key = Get_key(t, count);
00964 TERM_HASH_TABLE* hash_table = Get_term_hash_table();
00965 INTEGER_ARRAY* int_array = hash_table->Find(key);
00966
00967 if (int_array) {
00968 for (INT i = 0; i <= int_array->Lastidx(); ++i) {
00969 if (t->Is_equal(Get_term((*int_array)[i]), count)) {
00970 return;
00971 }
00972 }
00973
00974 int_array->AddElement(idx);
00975 }
00976 else {
00977
00978
00979 int_array = CXX_NEW(INTEGER_ARRAY(_m),_m);
00980 int_array->AddElement(idx);
00981 hash_table->Enter(key, int_array);
00982 }
00983 }
00984
00985
00986
00987
00988
00989 void
00990 ARRAY_SUMMARY_OUTPUT::Trace(FILE *f, const void *sbase)
00991 {
00992 const char *section_base = (char *)sbase;
00993 Elf64_Word* offset = (Elf64_Word*)section_base;
00994 SUMMARY_FILE_HEADER *file_header =
00995 (SUMMARY_FILE_HEADER*)(section_base + *offset);
00996 TERM* term_array;
00997 PROJECTED_NODE *projected_node_array;
00998 IVAR* ivar_array;
00999 REGION_ARRAYS* regions_array;
01000 PROJECTED_REGION* projected_region_array;
01001 CFG_NODE_INFO* cfg_node_array;
01002 LOOPINFO *loopinfo_array;
01003
01004
01005 if (file_header->Get_ivar_size() != 0) {
01006 ivar_array = (IVAR *)
01007 (section_base + file_header->Get_ivar_offset());
01008 Print_ivar_array ( f, file_header->Get_ivar_size(), ivar_array);
01009 }
01010
01011
01012 if (file_header->Get_term_array_size() != 0) {
01013 term_array = (TERM *)
01014 (section_base + file_header->Get_term_array_offset());
01015 Print_term_array ( f, file_header->Get_term_array_size(), term_array,
01016 ivar_array);
01017 }
01018
01019
01020 if (file_header->Get_cfg_node_size() != 0) {
01021 cfg_node_array = (CFG_NODE_INFO *)
01022 (section_base + file_header->Get_cfg_node_offset());
01023 Print_cfg_node_array (f, file_header->Get_cfg_node_size(), cfg_node_array);
01024 }
01025
01026
01027 if (file_header->Get_regions_array_size() != 0) {
01028 regions_array = ( REGION_ARRAYS*)
01029 (section_base + file_header->Get_regions_array_offset());
01030 Print_regions_array ( f, file_header->Get_regions_array_size(),
01031 regions_array);
01032 }
01033
01034
01035 if (file_header->Get_projected_region_size() != 0) {
01036 projected_region_array = ( PROJECTED_REGION*)
01037 (section_base + file_header->Get_projected_region_offset());
01038 Print_projected_region_array (f, file_header->Get_projected_region_size(),
01039 projected_region_array);
01040 }
01041
01042
01043 if (file_header->Get_projected_array_size() != 0) {
01044 projected_node_array = ( PROJECTED_NODE*)
01045 (section_base + file_header->Get_projected_array_offset());
01046 Print_projected_array ( f, file_header->Get_projected_array_size(),
01047 projected_node_array);
01048
01049 }
01050
01051
01052 if (file_header->Get_loopinfo_size() != 0) {
01053 loopinfo_array = (LOOPINFO *)
01054 (section_base + file_header->Get_loopinfo_offset());
01055 Print_loopinfo_array (f, file_header->Get_loopinfo_size(), loopinfo_array);
01056 }
01057
01058
01059 if (file_header->Get_scalar_node_size() != 0) {
01060 SCALAR_INFO* scalar_array = (SCALAR_INFO*)
01061 (section_base + file_header->Get_scalar_offset());
01062 Print_scalar_array ( f, file_header->Get_scalar_node_size(), scalar_array);
01063 }
01064 }
01065
01066
01067
01068
01069 void
01070 ARRAY_SUMMARY_OUTPUT::Trace(FILE *f)
01071 {
01072
01073 if (Get_cfg_node_count() >= 0)
01074 Print_cfg_node_array(f, Get_cfg_node_count()+1, Get_cfg_node(0));
01075
01076
01077 if (Get_region_count() >= 0)
01078 Print_regions_array(f, Get_region_count()+1, Get_region_array(0));
01079
01080
01081 if (Get_projected_region_count() >= 0)
01082 Print_projected_region_array(f,
01083 Get_projected_region_count()+1,
01084 Get_projected_region(0));
01085
01086
01087 if (Get_projected_node_count() >= 0)
01088 Print_projected_array(f,
01089 Get_projected_node_count()+1,
01090 Get_projected_node(0));
01091
01092
01093 if (Get_loopinfo_count() >= 0)
01094 Print_loopinfo_array(f, Get_loopinfo_count()+1, Get_loopinfo(0));
01095
01096
01097 if (Get_term_count() >= 0)
01098 Print_term_array(f,
01099 Get_term_count()+1,
01100 Get_term(0),
01101 Get_ivar(0));
01102
01103
01104 if (Get_ivar_count() >= 0)
01105 Print_ivar_array(f, Get_ivar_count()+1, Get_ivar(0));
01106
01107
01108 if (Get_scalars_count() >= 0)
01109 Print_scalar_array(f, Get_scalars_count()+1, Get_scalars(0));
01110 }
01111
01112
01113
01114
01115 void
01116 ARRAY_SUMMARY_OUTPUT::Print_loopinfo_array(FILE *fp, INT size,
01117 LOOPINFO *loop)
01118 {
01119 fprintf ( fp, "%sStart loopinfo array\n%s", SBar, SBar );
01120 for ( INT i=0; i<size; ++i )
01121 {
01122 fprintf(fp, "LOOP[%d]: ", i);
01123 loop[i].Print_file ( fp);
01124 }
01125 fprintf ( fp, "%sEnd loopinfo array\n%s", SBar, SBar );
01126 }
01127
01128
01129
01130
01131
01132 void
01133 ARRAY_SUMMARY_OUTPUT::Print_scalar_array(FILE *fp, INT size, SCALAR_INFO *scalars)
01134 {
01135 fprintf ( fp, "%sStart scalar array\n%s", SBar, SBar );
01136
01137 for ( INT i=0; i<size; ++i )
01138 {
01139 SCALAR_INFO* scalar = &scalars[i];
01140
01141 fprintf(fp, "SCALAR[%d]: symbol_id = %d : ", i,
01142 scalars[i].Get_id());
01143 if (scalar->Is_may_kill())
01144 fprintf(fp, "may kill, ");
01145 if (scalar->Is_may_use())
01146 fprintf(fp, "may use, ");
01147 if (scalar->Is_may_reduc())
01148 fprintf(fp, "may reduc, ");
01149 if (scalar->Is_kill())
01150 fprintf(fp, "must kill, ");
01151 if (scalar->Is_use())
01152 fprintf(fp, "must use, ");
01153 if (scalar->Is_reduc())
01154 fprintf(fp, "must reduc, ");
01155 if (scalar->Is_passed_ref())
01156 fprintf(fp, "must passed ref, ");
01157 if (scalar->Is_may_passed_ref())
01158 fprintf(fp, "may passed ref, ");
01159 if (scalar->Is_euse())
01160 fprintf(fp, "must euse, " );
01161 if (scalar->Is_array_may_reduc())
01162 fprintf(fp, "may reduc, ");
01163 if (scalar->Is_array_reduc())
01164 fprintf(fp, "must array reduc, " );
01165 if (scalar->Is_array_may_reduc())
01166 fprintf(fp, "may array reduc, " );
01167 fprintf(fp, "callsite id = %d \n", scalars[i].Get_callsite_id());
01168 }
01169
01170 fprintf ( fp, "%sEnd scalar array\n%s", SBar, SBar );
01171 }
01172
01173
01174
01175
01176 void
01177 ARRAY_SUMMARY_OUTPUT::Print_term_array(FILE *fp, INT size, TERM *term,
01178 IVAR*)
01179 {
01180 fprintf ( fp, "%sStart term array\n%s", SBar, SBar );
01181 for ( INT i=0; i<size; ++i )
01182 {
01183 fprintf(fp, "TERM[%d]: ", i);
01184 term[i].Print_file (fp);
01185 }
01186 fprintf ( fp, "%sEnd term array\n%s", SBar, SBar );
01187 }
01188
01189
01190
01191
01192 void
01193 ARRAY_SUMMARY_OUTPUT::Print_projected_array(FILE *fp, INT size,
01194 PROJECTED_NODE* node)
01195 {
01196 fprintf ( fp, "%sStart projected node array\n%s", SBar, SBar );
01197 for ( INT i=0; i<size; ++i )
01198 {
01199 fprintf(fp, "PROJ_NODE[%d]: ", i);
01200 node[i].Print_file ( fp);
01201 }
01202 fprintf ( fp, "%sEnd projected node array\n%s", SBar, SBar );
01203 }
01204
01205
01206
01207 void
01208 ARRAY_SUMMARY_OUTPUT::Print_projected_region_array(FILE *fp, INT size,
01209 PROJECTED_REGION *node)
01210 {
01211 fprintf ( fp, "%sStart projected region array\n%s", SBar, SBar );
01212 for ( INT i=0; i<size; ++i )
01213 {
01214 fprintf(fp, "PROJ_REGION[%d]: ", i);
01215 node[i].Print_file ( fp);
01216 }
01217 fprintf ( fp, "%sEnd projected region array\n%s", SBar, SBar );
01218 }
01219
01220
01221
01222
01223 void
01224 ARRAY_SUMMARY_OUTPUT::Print_regions_array(FILE *fp, INT size,
01225 REGION_ARRAYS* node)
01226 {
01227 fprintf ( fp, "%sStart regions array\n%s", SBar, SBar );
01228 for ( INT i=0; i<size; ++i )
01229 {
01230 fprintf(fp, "REGION[%d]: ", i);
01231 node[i].Print_file ( fp);
01232 }
01233 fprintf ( fp, "%sEnd regions array\n%s", SBar, SBar );
01234 }
01235
01236
01237
01238
01239 void
01240 ARRAY_SUMMARY_OUTPUT::Print_cfg_node_array(FILE *fp, INT size,
01241 CFG_NODE_INFO* node)
01242 {
01243 fprintf ( fp, "%sStart cfg node array\n%s", SBar, SBar );
01244 for ( INT i=0; i<size; ++i )
01245 {
01246 fprintf(fp, "CFG_NODE[%d]: ", i);
01247 node[i].Print_file ( fp);
01248 }
01249 fprintf ( fp, "%sEnd cfg node array\n%s", SBar, SBar );
01250 }
01251
01252
01253
01254
01255 void
01256 ARRAY_SUMMARY_OUTPUT::Print_ivar_array(FILE *fp, INT size,
01257 IVAR* node)
01258 {
01259 fprintf ( fp, "%sStart ivar node array\n%s", SBar, SBar );
01260 for ( INT i=0; i<size; ++i )
01261 {
01262 fprintf(fp, "IVAR[%d]: ", i);
01263 node[i].Print ( fp);
01264 }
01265 fprintf ( fp, "%sEnd ivar node array\n%s", SBar, SBar );
01266 }