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 #define __STDC_LIMIT_MACROS
00041 #include <stdint.h>
00042 #if defined(BUILD_OS_DARWIN)
00043 #include <darwin_elf.h>
00044 #else
00045 #include <elf.h>
00046 #endif
00047 #include <cmplrs/host.h>
00048 #include "assert.h"
00049 #define USE_STANDARD_TYPES
00050 #include "defs.h"
00051 #include "cxx_memory.h"
00052 #include "cxx_hash.h"
00053 #include "erglob.h"
00054 #include "glob.h"
00055 #include "mempool.h"
00056 #include "sparse_bv.h"
00057 #include "tracing.h"
00058 #include "strtab.h"
00059 #include "stab.h"
00060 #include "wn.h"
00061 #include "const.h"
00062 #include "pu_info.h"
00063 #include "irbdata.h"
00064 #include "dwarf_DST_mem.h"
00065 #include "ipc_defs.h"
00066 #include "ipc_weak.h"
00067 #include "ipc_file.h"
00068 #include "opt_du.h"
00069 #include "opt_alias_interface.h"
00070 #include "dep_graph.h"
00071 #include "prompf.h"
00072 #include "wb_util.h"
00073 #include "wb_browser.h"
00074 #include "wb.h"
00075 #include "wb_ipa.h"
00076 #include "cg_browser.h"
00077 #include "ipaa.h"
00078 #include "ipa_section_annot.h"
00079 #include "ipa_df.h"
00080 #include "ipa_cprop.h"
00081 #include "ipl_summary.h"
00082 #include "tlog.h"
00083 #include "ipa_summary.h"
00084 #include "ipc_symtab_merge.h"
00085
00086
00087
00088
00089
00090
00091 char* CG_BROWSER::Ivar_Name(INT i)
00092 {
00093 INT32 ivar_array_size;
00094 IVAR* ivar = IPA_get_ivar_array(Cnode(), ivar_array_size);
00095 FmtAssert(0 <= i && i < ivar_array_size,
00096 ("CG_BROWSER::Ivar_Name: Index out of range"));
00097 if (ivar[i].Is_Formal()) {
00098 SUMMARY_FORMAL* formals = IPA_get_formal_array(Cnode());
00099 INT32 formal_index = Cnode()->Summary_Proc()->Get_formal_index()
00100 + ivar[i].Formal_Position();
00101 INT32 symbol_index = formals[formal_index].Get_symbol_index();
00102 return Symbol_Name(symbol_index);
00103 }
00104 else {
00105 return ST_name(ivar[i].St_Idx());
00106 }
00107 }
00108
00109
00110
00111
00112
00113
00114 INT CG_BROWSER::Print_Linex(char* cp,
00115 INT cc,
00116 LINEX* lx)
00117 {
00118 INT term_count = 0;
00119 INT i;
00120
00121 for (i = 0; i <= lx->Num_terms(); i++) {
00122 TERM* tm = lx->Get_term(i);
00123 if (tm->Get_type() == LTKIND_LINDEX) {
00124 if (tm->Get_coeff() == 1)
00125 cc += sprintf(cp + cc, "%s%%%d", term_count > 0 ? "+" : "",
00126 tm->Get_desc());
00127 else if (tm->Get_coeff() > 0)
00128 cc += sprintf(cp + cc, "%s%d*%d", term_count > 0 ? "+" : "",
00129 tm->Get_coeff(), tm->Get_desc());
00130 else if (tm->Get_coeff() == -1)
00131 cc += sprintf(cp + cc, "-%d", tm->Get_desc());
00132 else if (tm->Get_coeff() < 0)
00133 cc += sprintf(cp + cc, "%d*%d", tm->Get_coeff(), tm->Get_desc());
00134 if (tm->Get_coeff() != 0)
00135 term_count++;
00136 }
00137 }
00138 for (i = 0; i <= lx->Num_terms(); i++) {
00139 TERM* tm = lx->Get_term(i);
00140 if (tm->Get_type() == LTKIND_SUBSCR) {
00141 if (tm->Get_coeff() == 1)
00142 cc += sprintf(cp + cc, "%s$%d", term_count > 0 ? "+" : "",
00143 tm->Get_desc());
00144 else if (tm->Get_coeff() > 0)
00145 cc += sprintf(cp + cc, "%s%d*$%d", term_count > 0 ? "+" : "",
00146 tm->Get_coeff(), tm->Get_desc());
00147 else if (tm->Get_coeff() == -1)
00148 cc += sprintf(cp + cc, "-$%d", tm->Get_desc());
00149 else if (tm->Get_coeff() < 0)
00150 cc += sprintf(cp + cc, "%d*$%d", tm->Get_coeff(), tm->Get_desc());
00151 if (tm->Get_coeff() != 0)
00152 term_count++;
00153 }
00154 }
00155 for (i = 0; i <= lx->Num_terms(); i++) {
00156 TERM* tm = lx->Get_term(i);
00157 if (tm->Get_type() == LTKIND_IV) {
00158 if (tm->Get_coeff() == 1)
00159 cc += sprintf(cp + cc, "%s%s", term_count > 0 ? "+" : "",
00160 Ivar_Name(tm->Get_desc()));
00161 else if (tm->Get_coeff() > 0)
00162 cc += sprintf(cp + cc, "%s%d*%s", term_count > 0 ? "+" : "",
00163 tm->Get_coeff(), Ivar_Name(tm->Get_desc()));
00164 else if (tm->Get_coeff() == -1)
00165 cc += sprintf(cp + cc, "-%s", Ivar_Name(tm->Get_desc()));
00166 else if (tm->Get_coeff() < 0)
00167 cc += sprintf(cp + cc, "%d*%s", tm->Get_coeff(),
00168 Ivar_Name(tm->Get_desc()));
00169 if (tm->Get_coeff() != 0)
00170 term_count++;
00171 }
00172 }
00173 INT const_value = 0;
00174 for (i = 0; i <= lx->Num_terms(); i++) {
00175 TERM* tm = lx->Get_term(i);
00176 if (tm->Get_type() == LTKIND_CONST)
00177 const_value += tm->Get_coeff();
00178 }
00179 if (term_count == 0 || const_value != 0) {
00180 if (const_value > 0 && term_count > 0)
00181 cc += sprintf(cp + cc, "+%d", const_value);
00182 else
00183 cc += sprintf(cp + cc, "%d", const_value);
00184 }
00185 return cc;
00186 }
00187
00188
00189
00190
00191
00192
00193 INT CG_BROWSER::Print_Projected_Node_Lower_Bound(char* cp,
00194 INT cc,
00195 PROJECTED_NODE* pn)
00196 {
00197 LINEX* lx_lower = pn->Get_lower_linex();
00198 if (pn->Is_messy_lb()) {
00199 cc += sprintf(cp + cc, "<MESSY>");
00200 } else {
00201 cc = Print_Linex(cp, cc, lx_lower);
00202 }
00203 return cc;
00204 }
00205
00206
00207
00208
00209
00210
00211 INT CG_BROWSER::Print_Projected_Node_Upper_Bound(char* cp,
00212 INT cc,
00213 PROJECTED_NODE* pn)
00214 {
00215 LINEX* lx_upper = pn->Get_upper_linex();
00216 if (pn->Is_messy_ub()) {
00217 cc += sprintf(cp + cc, "<MESSY>");
00218 } else {
00219 cc = Print_Linex(cp, cc, lx_upper);
00220 }
00221 return cc;
00222 }
00223
00224
00225
00226
00227
00228
00229 INT CG_BROWSER::Print_Projected_Node_Step(char* cp,
00230 INT cc,
00231 PROJECTED_NODE* pn)
00232 {
00233 LINEX* lx_step = pn->Get_step_linex();
00234 if (pn->Is_messy_step()) {
00235 cc += sprintf(cp + cc, "<MESSY>");
00236 } else {
00237 cc = Print_Linex(cp, cc, lx_step);
00238 }
00239 return cc;
00240 }
00241
00242
00243
00244
00245
00246
00247 INT CG_BROWSER::Print_Projected_Node_Segment_Length(char* cp,
00248 INT cc,
00249 PROJECTED_NODE* pn)
00250 {
00251 LINEX* lx_segment_length = pn->Get_segment_length_linex();
00252 cc = Print_Linex(cp, cc, lx_segment_length);
00253 return cc;
00254 }
00255
00256
00257
00258
00259
00260
00261 INT CG_BROWSER::Print_Projected_Node_Segment_Stride(char* cp,
00262 INT cc,
00263 PROJECTED_NODE* pn)
00264 {
00265 LINEX* lx_segment_stride = pn->Get_segment_stride_linex();
00266 cc = Print_Linex(cp, cc, lx_segment_stride);
00267 return cc;
00268 }
00269
00270
00271
00272
00273
00274
00275 INT CG_BROWSER::Print_Projected_Node(char* cp,
00276 INT cc,
00277 PROJECTED_NODE* pn)
00278 {
00279 cc = Print_Projected_Node_Lower_Bound(cp, cc, pn);
00280 cc += sprintf(cp + cc, ":");
00281 cc = Print_Projected_Node_Upper_Bound(cp, cc, pn);
00282 cc += sprintf(cp + cc, ":");
00283 cc = Print_Projected_Node_Step(cp, cc, pn);
00284 if (pn->Get_segment_length_linex() > 0) {
00285 cc += sprintf(cp + cc, ":");
00286 cc = Print_Projected_Node_Segment_Length(cp, cc, pn);
00287 }
00288 if (pn->Get_segment_stride_linex() > 0) {
00289 cc += sprintf(cp + cc, ":");
00290 cc = Print_Projected_Node_Segment_Stride(cp, cc, pn);
00291 }
00292 return cc;
00293 }
00294
00295
00296
00297
00298
00299
00300 INT CG_BROWSER::Print_Projected_Array(char* cp,
00301 INT cc,
00302 PROJECTED_ARRAY *pa)
00303 {
00304 for (INT i = 0; i <= pa->Lastidx(); i++) {
00305 cc += sprintf(cp + cc, "[");
00306 PROJECTED_NODE* pn = &(*pa)[i];
00307 cc = Print_Projected_Node(cp, cc, pn);
00308 cc += sprintf(cp + cc, "]");
00309 }
00310 return cc;
00311 }
00312
00313
00314
00315
00316
00317
00318 INT CG_BROWSER::Print_Projected_Region(char* cp,
00319 INT cc,
00320 PROJECTED_REGION *pr)
00321 {
00322 if (pr->Is_messy_region()) {
00323 cc += sprintf(cp + cc, "[<MESSY REGION>]");
00324 } else {
00325 cc = Print_Projected_Array(cp, cc, pr->Get_projected_array());
00326 }
00327 return cc;
00328 }
00329
00330
00331
00332
00333
00334
00335
00336 void CG_BROWSER::Tlog_Mod_Ref_Formals()
00337 {
00338 INT cc = 0;
00339 char buffer[CGB_MAX_STRING_LENGTH];
00340 IPA_NODE_SECTION_INFO* ipas = Cnode()->Section_Annot();
00341 IPAA_NODE_INFO* ipaa = Cnode()->Mod_Ref_Info();
00342 INT formal_count = ipas->Get_formal_count();
00343 if (formal_count > 0) {
00344 for (INT i = 0; i < formal_count; i++) {
00345 cc += sprintf(buffer + cc, "F#%d: ", i);
00346 STATE* ipaf = ipas->Get_formal(i);
00347 if (ipaf->Is_scalar()) {
00348 BOOL indent = FALSE;
00349 if (ipaa != NULL) {
00350 if (ipaa->Is_formal_dmod_elmt(i) || ipaa->Is_formal_imod_elmt(i)) {
00351 cc += sprintf(buffer + cc, "MOD ");
00352 cc += sprintf(buffer + cc, "%s", Formal_Name(i));
00353 indent = TRUE;
00354 }
00355 if (ipaa->Is_formal_dref_elmt(i) || ipaa->Is_formal_iref_elmt(i)) {
00356 if (indent)
00357 cc += sprintf(buffer + cc, " ");
00358 cc += sprintf(buffer + cc, "REF ");
00359 cc += sprintf(buffer + cc, "%s", Formal_Name(i));
00360 indent = TRUE;
00361 }
00362 }
00363 if (!indent)
00364 cc += sprintf(buffer + cc, " %s", Formal_Name(i));
00365 if (cc >= CGB_MAX_STRING_LENGTH - 1)
00366 buffer[CGB_MAX_STRING_LENGTH - 1] = '\0';
00367 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00368 buffer);
00369 cc = 0;
00370 } else {
00371 BOOL indent = FALSE;
00372 if (ipaf->Get_projected_mod_region() != NULL) {
00373 cc += sprintf(buffer + cc, "MOD ");
00374 cc += sprintf(buffer + cc, "%s", Formal_Name(i));
00375 cc = Print_Projected_Region(buffer, cc,
00376 ipaf->Get_projected_mod_region());
00377 indent = TRUE;
00378 if (cc >= CGB_MAX_STRING_LENGTH - 1)
00379 buffer[CGB_MAX_STRING_LENGTH - 1] = '\0';
00380 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00381 buffer);
00382 cc = 0;
00383 }
00384 if (ipaf->Get_projected_ref_region() != NULL) {
00385 if (indent)
00386 cc += sprintf(buffer + cc, " ");
00387 cc += sprintf(buffer + cc, "REF ");
00388 cc += sprintf(buffer + cc, "%s", Formal_Name(i));
00389 cc = Print_Projected_Region(buffer, cc,
00390 ipaf->Get_projected_ref_region());
00391 if (cc >= CGB_MAX_STRING_LENGTH - 1)
00392 buffer[CGB_MAX_STRING_LENGTH - 1] = '\0';
00393 indent = TRUE;
00394 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00395 buffer);
00396 cc = 0;
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 if (!indent)
00415 cc += sprintf(buffer + cc, " %s", Formal_Name(i));
00416 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00417 buffer);
00418 cc = 0;
00419 }
00420 }
00421 }
00422 }
00423
00424
00425
00426
00427
00428
00429
00430 void CG_BROWSER::Tlog_Mod_Ref_Commons()
00431 {
00432 INT cc = 0;
00433 char buffer[CGB_MAX_STRING_LENGTH];
00434
00435
00436 IPAA_NODE_INFO* ipaa = Cnode()->Mod_Ref_Info();
00437 ST* st;
00438 INT i;
00439 FOREACH_SYMBOL (GLOBAL_SYMTAB, st, i) {
00440 if (ST_class(st) == CLASS_VAR &&
00441 ST_base_idx(st) == ST_st_idx(st) &&
00442 TY_kind(ST_type(st)) != KIND_ARRAY &&
00443 !ST_is_split_common(st)) {
00444 UINT32 mod_ref_key = ST_IDX_index(ST_st_idx(st));
00445 if (ipaa->Is_def_elmt(mod_ref_key)) {
00446 cc += sprintf(buffer + cc, "MOD /%s/", ST_name(st));
00447 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00448 buffer);
00449 cc = 0;
00450 }
00451 if (ipaa->Is_eref_elmt(mod_ref_key)) {
00452 cc += sprintf(buffer + cc, "REF /%s/", ST_name(st));
00453 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00454 buffer);
00455 cc = 0;
00456 }
00457 }
00458 }
00459
00460
00461 IPA_NODE_SECTION_INFO* ipas = Cnode()->Section_Annot();
00462 GLOBAL_ARRAY_TABLE* cst = ipas->Global_Array_Table();
00463 GLOBAL_ARRAY_TABLE_ITER cst_iter(cst);
00464 GLOBAL_ARRAY_LIST* list = NULL;
00465 ST_IDX base_st_idx;
00466 while (cst_iter.Step(&base_st_idx, &list)) {
00467 if (list->Is_messy()) {
00468 cc += sprintf(buffer + cc, "/%s/ <MESSY>", ST_name(base_st_idx));
00469 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00470 buffer);
00471 cc = 0;
00472 continue;
00473 }
00474 GLOBAL_ARRAY_LIST_ITER iter(list);
00475 for (iter.First(); !iter.Is_Empty(); iter.Next()) {
00476 GLOBAL_ARRAY_INFO* css = iter.Cur();
00477 if (css->Get_projected_mod_region() != NULL) {
00478 cc += sprintf(buffer + cc, "MOD ");
00479 cc += sprintf(buffer + cc, "/%s/ ", ST_name(base_st_idx));
00480 cc += sprintf(buffer + cc, "%s", ST_name(css->St_Idx()));
00481 cc = Print_Projected_Region(buffer, cc,
00482 css->Get_projected_mod_region());
00483 if (cc >= CGB_MAX_STRING_LENGTH - 1)
00484 buffer[CGB_MAX_STRING_LENGTH - 1] = '\0';
00485 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00486 buffer);
00487 cc = 0;
00488 }
00489 if (css->Get_projected_ref_region() != NULL) {
00490 cc += sprintf(buffer + cc, "REF ");
00491 cc += sprintf(buffer + cc, "/%s/ ", ST_name(base_st_idx));
00492 cc += sprintf(buffer + cc, "%s", ST_name(css->St_Idx()));
00493 cc = Print_Projected_Region(buffer, cc,
00494 css->Get_projected_ref_region());
00495 if (cc >= CGB_MAX_STRING_LENGTH - 1)
00496 buffer[CGB_MAX_STRING_LENGTH - 1] = '\0';
00497 Generate_Tlog("IPA", "Array_Section", (SRCPOS) 0, "", "", "",
00498 buffer);
00499 cc = 0;
00500 }
00501 }
00502 }
00503 }
00504
00505
00506
00507
00508
00509
00510 void CG_BROWSER::Print_Summary_Value(FILE* fp,
00511 SUMMARY_VALUE* sv)
00512 {
00513 if (sv->Get_mtype() != MTYPE_UNKNOWN)
00514 fprintf(fp, "%s ", MTYPE_name(sv->Get_mtype()));
00515 if (sv->Is_int_const())
00516 fprintf(fp, "(%lld) ", sv->Get_int_const_value());
00517 else if (sv->Is_two_consts())
00518 fprintf(fp, "(%d,%d) ",
00519 sv->Get_first_of_two_values(), sv->Get_second_of_two_values());
00520 else if (sv->Is_const_st()) {
00521 ST_IDX st_idx = sv->Get_const_st_idx();
00522 ST* st = &St_Table[st_idx];
00523 fprintf(fp, "<ST_IDX(%d) VALUE(%s)> ", sv->Get_const_st_idx(),
00524 Targ_Print(NULL, Tcon_Table[st->u1.tcon]));
00525 } else if (sv->Is_formal())
00526 fprintf(fp, "FORMAL[%d] ", sv->Get_formal_index());
00527 else if (sv->Is_global())
00528 fprintf(fp, "GLOBAL[%d] ", sv->Get_global_index());
00529 else if (sv->Is_symbol())
00530 fprintf(fp, "SYMBOL[%d] ", sv->Get_symbol_index());
00531 else if (sv->Is_expr())
00532 fprintf(fp, "EXPR[%d] ", sv->Get_expr_index());
00533 else if (sv->Is_phi())
00534 fprintf(fp, "PHI[%d] ", sv->Get_phi_index());
00535 else if (sv->Is_chi())
00536 fprintf(fp, "CHI[%d] ", sv->Get_chi_index());
00537 else if (sv->Is_callsite())
00538 fprintf(fp, "CALLSITE[%d] ", sv->Get_callsite_index());
00539 }