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
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 #ifdef USE_PCH
00082 #include "opt_pch.h"
00083 #endif // USE_PCH
00084 #pragma hdrstop
00085
00086
00087 #include "defs.h"
00088 #include "errors.h"
00089 #include "erglob.h"
00090 #include "glob.h"
00091 #include "mempool.h"
00092 #include "tracing.h"
00093 #include "cxx_memory.h"
00094
00095 #include "opt_defs.h"
00096 #include "idx_32_set.h"
00097 #include "opt_cfg.h"
00098 #include "opt_ssa.h"
00099 #include "opt_main.h"
00100 #include "opt_mu_chi.h"
00101 #include "opt_sym.h"
00102 #include "opt_htable.h"
00103 #include "opt_alias_rule.h"
00104
00105
00106 extern void dump_tree(WN *wn);
00107 extern void Rename_CODEMAP(COMP_UNIT *);
00108
00109
00110 class OPT_REVISE_SSA {
00111 private:
00112 OPT_STAB *_opt_stab;
00113 CFG *_cfg;
00114 CODEMAP *_htable;
00115 MEM_POOL *_loc_pool;
00116 BOOL _tracing;
00117
00118 AUX_ID _first_new_aux_id;
00119 BOOL _has_bitfield;
00120
00121 BOOL _has_lda_indirect;
00122
00123 BOOL _default_vsym_used;
00124
00125 IDX_32_SET *_symbols_to_revise;
00126
00127
00128 OCC_TAB_ENTRY *Get_new_occ(CODEREP *cr, BOOL is_store);
00129 void Find_scalars_from_lowering_bitfld_cr(CODEREP *cr);
00130 void Find_scalars_from_lda_iloads(CODEREP *cr);
00131 void Update_phis(BB_NODE *bb);
00132 void Update_chi_list_for_old_var(STMTREP *stmt, AUX_ID i);
00133 void Insert_mu_and_chi_list_for_new_var(STMTREP *stmt, AUX_ID i);
00134 void Update_mu_and_chi_list(STMTREP *stmt);
00135 CODEREP *Create_EXTRACT_BITS(INT bit_offset, INT bit_size,
00136 CODEREP *x, MTYPE rtype);
00137 CODEREP *Create_COMPOSE_BITS(INT bit_offset, INT bit_size,
00138 CODEREP *v, CODEREP *rhs);
00139 CODEREP *Form_extract(CODEREP *cr);
00140 CODEREP *Fold_lda_iloads(CODEREP *cr);
00141 void Delete_chi(AUX_ID aux_id, STMTREP *stmt);
00142
00143 OPT_REVISE_SSA(void);
00144 OPT_REVISE_SSA(const OPT_REVISE_SSA&);
00145 OPT_REVISE_SSA& operator = (const OPT_REVISE_SSA&);
00146
00147 public:
00148 OPT_REVISE_SSA( OPT_STAB *opt_stab, CODEMAP *htable, CFG *cfg, MEM_POOL *lpool, INT trace_flag):
00149 _opt_stab(opt_stab), _htable(htable), _cfg(cfg), _loc_pool(lpool) {
00150 _first_new_aux_id = opt_stab->Lastidx() + 1;
00151 _tracing = Get_Trace(TP_GLOBOPT, trace_flag);
00152 _has_bitfield = FALSE;
00153 _has_lda_indirect = FALSE;
00154 _default_vsym_used = FALSE;
00155 _symbols_to_revise = CXX_NEW(IDX_32_SET(opt_stab->Lastidx(), lpool, OPTS_FALSE), lpool);;
00156 }
00157 ~OPT_REVISE_SSA(void) {}
00158
00159 BOOL Has_bitfield(void) const { return _has_bitfield; }
00160 BOOL Has_lda_indirect(void) const { return _has_lda_indirect; }
00161
00162 void Find_scalars_from_lowering_bitfld(void);
00163 void Find_scalars_from_lda_indirects(void);
00164 void Form_extract_compose(void);
00165 void Fold_lda_indirects(void);
00166 void Rename_new_scalars(COMP_UNIT *cunit);
00167 };
00168
00169
00170
00171
00172
00173
00174
00175
00176 OCC_TAB_ENTRY *
00177 OPT_REVISE_SSA::Get_new_occ(CODEREP *cr, BOOL is_store)
00178 {
00179 WN *wn = WN_Create(cr->Op(), 1);
00180 BZERO(wn, sizeof(WN));
00181 WN_set_operator(wn, OPR_ILOAD);
00182 WN_set_desc(wn, cr->Dsctyp());
00183 WN_set_rtype(wn, cr->Dtyp());
00184 WN_store_offset(wn) = cr->Offset();
00185 WN_set_ty(wn, cr->Ilod_ty());
00186 WN_set_load_addr_ty(wn, cr->Ilod_base_ty());
00187 WN_set_field_id(wn, 0);
00188 if (_tracing)
00189 fdump_wn(TFile, wn);
00190
00191 #if 0 // cannot use Identify_vsym because it requires address expr in wn also
00192 AUX_ID vsym_id = _opt_stab->Identify_vsym(wn);
00193 #endif
00194 AUX_ID vsym_id;
00195
00196 AUX_ID old_vsym_id = cr->Ivar_occ()->Aux_id();
00197 AUX_STAB_ENTRY *old_vsym = _opt_stab->Aux_stab_entry(old_vsym_id);
00198 if (old_vsym->Is_real_var() || old_vsym->Stype() == VT_LDA_VSYM) {
00199 if (old_vsym->Bit_size() == 0) {
00200 vsym_id = old_vsym_id;
00201
00202 if (is_store)
00203 _symbols_to_revise->Union1D(vsym_id);
00204 }
00205 else {
00206 vsym_id = _opt_stab->Find_vsym_with_base_ofst_and_size(old_vsym->Base(),
00207 old_vsym->Base_byte_ofst(), old_vsym->Byte_size(), 0, 0);
00208 if (vsym_id == 0) {
00209 if (_opt_stab->Default_vsym() == 0) {
00210 AUX_ID dft_vsym = _opt_stab->Create_vsym(EXPR_IS_ANY);
00211 _opt_stab->Set_default_vsym(dft_vsym);
00212
00213 _opt_stab->Aux_stab_entry(dft_vsym)->Points_to()->Set_default_vsym();
00214 }
00215 vsym_id = _opt_stab->Default_vsym();
00216 _default_vsym_used = TRUE;
00217 }
00218 _symbols_to_revise->Union1D(vsym_id);
00219 }
00220 }
00221 else {
00222 vsym_id = old_vsym_id;
00223 if (is_store)
00224 _symbols_to_revise->Union1D(vsym_id);
00225 }
00226
00227
00228
00229
00230 OCC_TAB_ENTRY *occ = _opt_stab->Enter_occ_tab(wn, vsym_id);
00231 occ->Points_to()->Copy_fully(_opt_stab->Aux_stab_entry(vsym_id)->Points_to());
00232 return occ;
00233 }
00234
00235
00236
00237
00238
00239
00240 void
00241 OPT_REVISE_SSA::Find_scalars_from_lowering_bitfld_cr(CODEREP *cr)
00242 {
00243 INT i;
00244 AUX_ID idx;
00245 switch (cr->Kind()) {
00246 case CK_CONST:
00247 case CK_RCONST:
00248 case CK_LDA:
00249 return;
00250 case CK_VAR:
00251 if (cr->Bit_field_valid()) {
00252 WN wn;
00253 BZERO (&wn, sizeof(WN));
00254 WN_set_operator(&wn, OPR_LDID);
00255 WN_set_desc(&wn, cr->Dsctyp());
00256 WN_set_rtype(&wn, cr->Dtyp());
00257 WN_store_offset(&wn) = cr->Offset();
00258 WN_st_idx(&wn) = ST_st_idx(_opt_stab->St(cr->Aux_id()));
00259 WN_set_ty(&wn, cr->Lod_ty());
00260 WN_set_field_id(&wn, 0);
00261 WN_set_map_id(&wn, 0);
00262 if (_tracing)
00263 fdump_wn(TFile, &wn);
00264
00265 idx = _opt_stab->Enter_symbol(WN_operator(&wn), WN_st(&wn),
00266 WN_offset(&wn), WN_ty(&wn), FALSE, &wn);
00267 Is_True(idx != 0, ("Find_scalars_from_lowering_bitfld_cr:: index from Enter_symbol is 0"));
00268 _symbols_to_revise->Union1D(idx);
00269 AUX_STAB_ENTRY *aux = _opt_stab->Aux_stab_entry(idx);
00270 aux->Points_to()->Set_expr_kind(EXPR_IS_ADDR);
00271 aux->Points_to()->Set_named();
00272
00273 cr->Set_scalar_aux_id(idx);
00274 _has_bitfield = TRUE;
00275 if (_tracing && idx >= _first_new_aux_id)
00276 _opt_stab->Print_aux_entry(idx, TFile);
00277 }
00278 #ifdef KEY
00279 else if (cr->Dtyp() != MTYPE_M && MTYPE_byte_size(cr->Dsctyp()) < 4 &&
00280 (idx = _opt_stab->Part_of_reg_size_symbol(cr->Aux_id())) != 0) {
00281 cr->Set_promote_to_reg_size();
00282 _symbols_to_revise->Union1D(idx);
00283 cr->Set_scalar_aux_id(idx);
00284 _has_bitfield = TRUE;
00285 if (_tracing)
00286 fprintf(TFile, "replace %d by extract of %d\n", cr->Aux_id(), idx);
00287 }
00288 #endif
00289 return;
00290 case CK_IVAR:
00291 Find_scalars_from_lowering_bitfld_cr(cr->Ilod_base());
00292 if (cr->Opr() == OPR_MLOAD)
00293 Find_scalars_from_lowering_bitfld_cr(cr->Mload_size());
00294 if (cr->Opr() == OPR_ILOADX)
00295 Find_scalars_from_lowering_bitfld_cr(cr->Index());
00296 if (cr->Opr() == OPR_ILDBITS) {
00297 cr->Set_scalar_ivar_occ(Get_new_occ(cr, FALSE));
00298 _has_bitfield = TRUE;
00299 }
00300 return;
00301 case CK_OP:
00302 #ifdef KEY
00303 if (cr->Is_isop_flag_set(ISOP_XLOWER_VISITED))
00304 return;
00305 cr->Set_isop_flag(ISOP_XLOWER_VISITED);
00306 #endif
00307 for (i = 0; i < cr->Kid_count(); i++)
00308 Find_scalars_from_lowering_bitfld_cr(cr->Opnd(i));
00309 return;
00310 }
00311 }
00312
00313
00314
00315
00316
00317
00318 void
00319 OPT_REVISE_SSA::Find_scalars_from_lowering_bitfld(void)
00320 {
00321 CFG_ITER cfg_iter(_cfg);
00322 BB_NODE *bb;
00323 INT32 i;
00324
00325
00326 if (_tracing)
00327 fprintf(TFile, "%sOPT_REVISE_SSA:: Scalars due to lowering bitfields:\n(new scalars start at aux id %d)\n%s",
00328 DBar, _first_new_aux_id, DBar );
00329
00330
00331 FOR_ALL_NODE( bb, cfg_iter, Init() ) {
00332 STMTREP_ITER stmt_iter(bb->Stmtlist());
00333 STMTREP *stmt;
00334 FOR_ALL_NODE(stmt, stmt_iter, Init()) {
00335 OPERATOR opr = stmt->Opr();
00336 CODEREP *rhs = stmt->Rhs();
00337 if (OPERATOR_is_call(opr) || opr == OPR_ASM_STMT) {
00338 for (i = 0; i < rhs->Kid_count(); i++)
00339 Find_scalars_from_lowering_bitfld_cr(rhs->Opnd(i));
00340 continue;
00341 }
00342 if (rhs) {
00343 if (opr == OPR_PREFETCH)
00344 Find_scalars_from_lowering_bitfld_cr(rhs->Ilod_base());
00345 else Find_scalars_from_lowering_bitfld_cr(rhs);
00346 }
00347 if (OPERATOR_is_store(opr)) {
00348 CODEREP *lhs = stmt->Lhs();
00349 switch (opr) {
00350 #ifdef KEY // bug 9179
00351 case OPR_STID: {
00352
00353 AUX_ID idx;
00354 if (lhs->Dsctyp() != MTYPE_M && MTYPE_byte_size(lhs->Dsctyp()) < 4 &&
00355 (idx = _opt_stab->Part_of_reg_size_symbol(lhs->Aux_id())) != 0) {
00356 _symbols_to_revise->Union1D(lhs->Aux_id());
00357
00358 lhs->Set_promote_to_reg_size();
00359 _symbols_to_revise->Union1D(idx);
00360 lhs->Set_scalar_aux_id(idx);
00361 _has_bitfield = TRUE;
00362 if (_tracing)
00363 fprintf(TFile, "replace %d by compose of %d\n", lhs->Aux_id(), idx);
00364 }
00365 break;
00366 }
00367 #endif
00368 case OPR_STBITS: {
00369 _symbols_to_revise->Union1D(lhs->Aux_id());
00370
00371 WN wn;
00372 BZERO(&wn, sizeof(WN));
00373 WN_set_operator(&wn, OPR_STID);
00374 WN_set_desc(&wn, stmt->Desc());
00375 WN_set_rtype(&wn, MTYPE_V);
00376 WN_store_offset(&wn) = lhs->Offset();
00377 WN_st_idx(&wn) = ST_st_idx(_opt_stab->St(lhs->Aux_id()));
00378 WN_set_ty(&wn, lhs->Lod_ty());
00379 WN_set_field_id(&wn, 0);
00380 WN_set_map_id(&wn, 0);
00381 if (_tracing)
00382 fdump_wn(TFile, &wn);
00383
00384 AUX_ID idx = _opt_stab->Enter_symbol(WN_operator(&wn), WN_st(&wn),
00385 WN_offset(&wn), WN_ty(&wn), FALSE, &wn);
00386 Is_True(idx != 0, ("Find_scalars_from_lowering_bitfld:: index from Enter_symbol is 0"));
00387 _symbols_to_revise->Union1D(idx);
00388 AUX_STAB_ENTRY *aux = _opt_stab->Aux_stab_entry(idx);
00389 aux->Points_to()->Set_expr_kind(EXPR_IS_ADDR);
00390 aux->Points_to()->Set_named();
00391
00392 lhs->Set_scalar_aux_id(idx);
00393 _has_bitfield = TRUE;
00394 if (_tracing && idx >= _first_new_aux_id)
00395 _opt_stab->Print_aux_entry(idx, TFile);
00396 break;
00397 }
00398 case OPR_MSTORE:
00399 Find_scalars_from_lowering_bitfld_cr(lhs->Mstore_size());
00400
00401 case OPR_ISTORE:
00402 case OPR_ISTBITS:
00403 Find_scalars_from_lowering_bitfld_cr(lhs->Istr_base());
00404 if (opr == OPR_ISTBITS) {
00405 lhs->Set_scalar_ivar_occ(Get_new_occ(lhs, TRUE));
00406 _has_bitfield = TRUE;
00407 }
00408 break;
00409 default: ;
00410 }
00411 }
00412 }
00413 }
00414 }
00415
00416
00417
00418
00419
00420
00421 void
00422 OPT_REVISE_SSA::Find_scalars_from_lda_iloads(CODEREP *cr)
00423 {
00424 INT i;
00425 switch (cr->Kind()) {
00426 case CK_CONST:
00427 case CK_RCONST:
00428 case CK_LDA:
00429 case CK_VAR:
00430 return;
00431 case CK_IVAR: {
00432 WN wn;
00433 Find_scalars_from_lda_iloads(cr->Ilod_base());
00434 if (cr->Opr() == OPR_MLOAD) {
00435 Find_scalars_from_lda_iloads(cr->Mload_size());
00436 return;
00437 }
00438 else if (cr->Opr() == OPR_ILOADX) {
00439 Find_scalars_from_lda_iloads(cr->Index());
00440 return;
00441 }
00442 if (cr->Ilod_base()->Kind() != CK_LDA ||
00443 cr->Is_ivar_volatile() ||
00444 cr->Opr() == OPR_PARM)
00445 return;
00446 #ifdef KEY // to limit compilation time explosion (bug 2081)
00447 if (_opt_stab->Lastidx() > WOPT_Enable_Folded_Scalar_Limit) {
00448 cr->Set_scalar_aux_id(0);
00449 return;
00450 }
00451 #endif
00452
00453 CODEREP *lda = cr->Ilod_base();
00454 WN_set_operator(&wn, cr->Opr() == OPR_ILOAD ? OPR_LDID : OPR_LDBITS);
00455 WN_set_desc(&wn, cr->Dsctyp());
00456 WN_set_rtype(&wn, cr->Dtyp());
00457 WN_store_offset(&wn) = cr->Offset() + lda->Offset();
00458 #if 1 // bug fix aug-14-02
00459 ST *lda_st;
00460 INT64 ofst;
00461 Expand_ST_into_base_and_ofst(_opt_stab->St(lda->Lda_aux_id()),
00462 _opt_stab->St_ofst(lda->Lda_aux_id()),
00463 &lda_st, &ofst);
00464 if (lda_st == lda->Lda_base_st()) {
00465 if (_opt_stab->St_chain_map()->Lookup(ST_st_idx(lda_st)) != NULL)
00466 WN_st_idx(&wn) = ST_st_idx(lda_st);
00467 else {
00468 WN_store_offset(&wn) -= ofst - _opt_stab->St_ofst(lda->Lda_aux_id());
00469 WN_st_idx(&wn) = ST_st_idx(_opt_stab->St(lda->Lda_aux_id()));
00470 }
00471 } else
00472 #endif
00473 WN_st_idx(&wn) = ST_st_idx(_opt_stab->St(lda->Lda_aux_id()));
00474 WN_set_ty(&wn, cr->Ilod_ty());
00475 WN_set_field_id(&wn, cr->I_field_id());
00476 WN_set_map_id(&wn, 0);
00477 if (_tracing)
00478 fdump_wn(TFile, &wn);
00479
00480 AUX_ID idx = _opt_stab->Enter_symbol(WN_operator(&wn), WN_st(&wn),
00481 WN_offset(&wn), WN_ty(&wn), FALSE, &wn);
00482 Is_True(idx != 0, ("Find_scalars_from_lda_iloads:: index from Enter_symbol is 0"));
00483 _symbols_to_revise->Union1D(idx);
00484 AUX_STAB_ENTRY *aux = _opt_stab->Aux_stab_entry(idx);
00485 aux->Points_to()->Set_expr_kind(EXPR_IS_ADDR);
00486 aux->Points_to()->Set_named();
00487
00488 cr->Set_scalar_aux_id(idx);
00489 _has_lda_indirect = TRUE;
00490 if (_tracing && idx >= _first_new_aux_id)
00491 _opt_stab->Print_aux_entry(idx, TFile);
00492 return;
00493 }
00494 case CK_OP:
00495 #ifdef KEY
00496 if (cr->Is_isop_flag_set(ISOP_LDAFOLD_VISITED))
00497 return;
00498 cr->Set_isop_flag(ISOP_LDAFOLD_VISITED);
00499 #endif
00500 for (i = 0; i < cr->Kid_count(); i++)
00501 Find_scalars_from_lda_iloads(cr->Opnd(i));
00502 return;
00503 }
00504 }
00505
00506
00507
00508
00509
00510
00511 void
00512 OPT_REVISE_SSA::Find_scalars_from_lda_indirects(void)
00513 {
00514 CFG_ITER cfg_iter(_cfg);
00515 BB_NODE *bb;
00516 INT32 i;
00517
00518
00519 if (_tracing)
00520 fprintf(TFile, "%sOPT_REVISE_SSA:: Scalars due to lda indirects:\n(new scalars start at aux id %d)\n%s",
00521 DBar, _first_new_aux_id, DBar );
00522
00523
00524 FOR_ALL_NODE( bb, cfg_iter, Init() ) {
00525 STMTREP_ITER stmt_iter(bb->Stmtlist());
00526 STMTREP *stmt;
00527 FOR_ALL_NODE(stmt, stmt_iter, Init()) {
00528 OPERATOR opr = stmt->Opr();
00529 CODEREP *rhs = stmt->Rhs();
00530 if (OPERATOR_is_call(opr) || opr == OPR_ASM_STMT) {
00531 for (i = 0; i < rhs->Kid_count(); i++)
00532 Find_scalars_from_lda_iloads(rhs->Opnd(i));
00533 continue;
00534 }
00535 if (rhs) {
00536 if (opr == OPR_PREFETCH)
00537 Find_scalars_from_lda_iloads(rhs->Ilod_base());
00538 else Find_scalars_from_lda_iloads(rhs);
00539 }
00540 if (OPERATOR_is_store(opr)) {
00541 CODEREP *lhs = stmt->Lhs();
00542 switch (opr) {
00543 case OPR_MSTORE:
00544 Find_scalars_from_lda_iloads(lhs->Mstore_size());
00545 Find_scalars_from_lda_iloads(lhs->Istr_base());
00546 break;
00547 case OPR_ISTORE:
00548 case OPR_ISTBITS: {
00549 WN wn;
00550 if (lhs->Istr_base()->Kind() != CK_LDA) {
00551 Find_scalars_from_lda_iloads(lhs->Istr_base());
00552 break;
00553 }
00554 if (lhs->Is_ivar_volatile())
00555 break;
00556 #ifdef KEY // to limit compilation time explosion (bug 2081)
00557 if (_opt_stab->Lastidx() > WOPT_Enable_Folded_Scalar_Limit) {
00558 lhs->Set_scalar_aux_id(0);
00559 break;
00560 }
00561 #endif
00562
00563 CODEREP *lda = lhs->Istr_base();
00564 BZERO(&wn, sizeof(WN));
00565 WN_set_operator(&wn, opr == OPR_ISTORE ? OPR_STID : OPR_STBITS);
00566 WN_set_desc(&wn, stmt->Desc());
00567 WN_set_rtype(&wn, MTYPE_V);
00568 WN_store_offset(&wn) = lhs->Offset() + lda->Offset();
00569 #if 1 // bug fix aug-14-02
00570 ST *lda_st;
00571 INT64 ofst;
00572 Expand_ST_into_base_and_ofst(_opt_stab->St(lda->Lda_aux_id()),
00573 _opt_stab->St_ofst(lda->Lda_aux_id()),
00574 &lda_st, &ofst);
00575 if (lda_st == lda->Lda_base_st()){
00576 if (_opt_stab->St_chain_map()->Lookup(ST_st_idx(lda_st)) != NULL)
00577 WN_st_idx(&wn) = ST_st_idx(lda_st);
00578 else {
00579 WN_store_offset(&wn) -= ofst - _opt_stab->St_ofst(lda->Lda_aux_id());
00580 WN_st_idx(&wn) = ST_st_idx(_opt_stab->St(lda->Lda_aux_id()));
00581 }
00582 } else
00583 #endif
00584 WN_st_idx(&wn) = ST_st_idx(_opt_stab->St(lda->Lda_aux_id()));
00585 WN_set_ty(&wn, lhs->Ilod_ty());
00586 WN_set_field_id(&wn, lhs->I_field_id());
00587 WN_set_map_id(&wn, 0);
00588 if (_tracing)
00589 fdump_wn(TFile, &wn);
00590
00591 AUX_ID idx = _opt_stab->Enter_symbol(WN_operator(&wn), WN_st(&wn),
00592 WN_offset(&wn), WN_ty(&wn), FALSE, &wn);
00593 Is_True(idx != 0, ("Find_scalars_from_lda_indirects:: index from Enter_symbol is 0"));
00594 _symbols_to_revise->Union1D(idx);
00595 AUX_STAB_ENTRY *aux = _opt_stab->Aux_stab_entry(idx);
00596 aux->Points_to()->Set_expr_kind(EXPR_IS_ADDR);
00597 aux->Points_to()->Set_named();
00598
00599 lhs->Set_scalar_aux_id(idx);
00600 _has_lda_indirect = TRUE;
00601 if (_tracing && idx >= _first_new_aux_id)
00602 _opt_stab->Print_aux_entry(idx, TFile);
00603 break;
00604 }
00605 default: ;
00606 }
00607 }
00608 }
00609 }
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 void
00621 OPT_REVISE_SSA::Update_phis(BB_NODE *bb)
00622 {
00623 PHI_NODE *phi;
00624 PHI_LIST_ITER phi_iter;
00625 CODEREP *phi_res;
00626
00627
00628 FOR_ALL_ELEM (phi, phi_iter, Init(bb->Phi_list())) {
00629 AUX_ID i = phi->Aux_id();
00630 if (i >= _first_new_aux_id)
00631 continue;
00632 if (! _symbols_to_revise->MemberP(i))
00633 continue;
00634
00635 if (! phi->Live() || phi->RESULT()->Is_flag_set(CF_IS_ZERO_VERSION)) {
00636 phi->Set_live();
00637 phi->Reset_dse_dead();
00638 phi->Reset_dce_dead();
00639 AUX_STAB_ENTRY *sym = _opt_stab->Aux_stab_entry(i);
00640 MTYPE rtype;
00641 TY_IDX ty = TY_IDX_ZERO;
00642 ST *st = _opt_stab->St(i);
00643 if (st != NULL) ty = ST_type(st);
00644 #if defined(TARG_NVISA)
00645
00646
00647
00648 rtype = sym->Mtype();
00649 #else
00650 if (sym->Mtype()==MTYPE_M || MTYPE_is_vector(sym->Mtype()))
00651 rtype = sym->Mtype();
00652 else {
00653 rtype = Mtype_from_mtype_class_and_size(sym->Mclass(),
00654 sym->Byte_size());
00655 #ifdef KEY // bug 8186
00656 if (MTYPE_is_unsigned(sym->Mtype()))
00657 rtype = Mtype_TransferSign(MTYPE_U4, rtype);
00658 #endif
00659 }
00660 #endif //TARG_NVISA
00661 MTYPE desc = rtype;
00662 #ifdef KEY // promote to register type size
00663 if (i != _opt_stab->Default_vsym() &&
00664 desc != MTYPE_UNKNOWN && desc != MTYPE_M)
00665 rtype = OPCODE_rtype(Ldid_from_mtype(desc));
00666 #endif
00667 if (rtype != MTYPE_UNKNOWN && rtype != MTYPE_M) {
00668 ty = MTYPE_To_TY(rtype);
00669 }
00670 phi_res = _htable->Add_def(i, -1, NULL, rtype, desc,
00671 _opt_stab->St_ofst(i), ty, 0, TRUE);
00672 phi_res->Set_flag(CF_DEF_BY_PHI);
00673 phi_res->Set_defphi(phi);
00674 phi->Set_result(phi_res);
00675 if (! phi->Res_is_cr()) {
00676 BB_NODE *pred;
00677 BB_LIST_ITER bb_iter;
00678 FOR_ALL_ELEM(pred, bb_iter, Init(bb->Pred())) {
00679 phi->Set_opnd(bb_iter.Idx(),
00680 _htable->Ssa()->Get_zero_version_CR(i, _opt_stab, 0));
00681 }
00682 }
00683 }
00684 }
00685 }
00686
00687
00688
00689
00690
00691 void
00692 OPT_REVISE_SSA::Update_chi_list_for_old_var(STMTREP *stmt, AUX_ID i)
00693 {
00694
00695 CHI_LIST_ITER chi_iter;
00696 CHI_NODE *cnode;
00697 CODEREP *chi_res;
00698 AUX_STAB_ENTRY *sym;
00699 MTYPE rtype;
00700 FOR_ALL_NODE(cnode, chi_iter, Init(stmt->Chi_list()))
00701 if (cnode->Aux_id() == i) {
00702 if (! cnode->Live() || cnode->RESULT()->Is_flag_set(CF_IS_ZERO_VERSION)) {
00703 BOOL originally_dead = ! cnode->Live();
00704 cnode->Set_live(TRUE);
00705 cnode->Set_dse_dead(FALSE);
00706 sym = _opt_stab->Aux_stab_entry(i);
00707 TY_IDX ty = TY_IDX_ZERO;
00708 ST *st = _opt_stab->St(i);
00709 if (st != NULL) ty = ST_type(st);
00710 #if defined(TARG_NVISA)
00711 rtype = sym->Mtype();
00712 #else
00713 if (sym->Mtype()==MTYPE_M || MTYPE_is_vector(sym->Mtype()))
00714 rtype = sym->Mtype();
00715 else {
00716 rtype = Mtype_from_mtype_class_and_size(sym->Mclass(),
00717 sym->Byte_size());
00718 #ifdef KEY // bug 8186
00719 if (MTYPE_is_unsigned(sym->Mtype()))
00720 rtype = Mtype_TransferSign(MTYPE_U4, rtype);
00721 #endif
00722 }
00723 #endif
00724 MTYPE desc = rtype;
00725 #ifdef KEY // promote to register type size
00726 if (i != _opt_stab->Default_vsym() &&
00727 desc != MTYPE_UNKNOWN && desc != MTYPE_M)
00728 rtype = OPCODE_rtype(Ldid_from_mtype(desc));
00729 #endif
00730
00731 if (rtype != MTYPE_UNKNOWN && rtype != MTYPE_M) {
00732 ty = MTYPE_To_TY(rtype);
00733 }
00734
00735 chi_res = _htable->Add_def(i, -1, stmt, rtype, desc,
00736 _opt_stab->St_ofst(i), ty, 0, TRUE);
00737 chi_res->Set_flag(CF_DEF_BY_CHI);
00738 chi_res->Set_defchi(cnode);
00739 cnode->Set_RESULT(chi_res);
00740 if (originally_dead)
00741 cnode->Set_OPND(_htable->Ssa()->Get_zero_version_CR(i, _opt_stab, 0));
00742 stmt->Recompute_has_zver();
00743 }
00744 else if (cnode->RESULT()->Dtyp() == MTYPE_UNKNOWN) {
00745 chi_res = cnode->RESULT();
00746
00747 sym = _opt_stab->Aux_stab_entry(i);
00748 TY_IDX ty = TY_IDX_ZERO;
00749 ST *st = _opt_stab->St(i);
00750 if (st != NULL) ty = ST_type(st);
00751 #if defined(TARG_NVISA)
00752 rtype = sym->Mtype();
00753 #else
00754 if (sym->Mtype()==MTYPE_M || MTYPE_is_vector(sym->Mtype()))
00755 rtype = sym->Mtype();
00756 else {
00757 rtype = Mtype_from_mtype_class_and_size(sym->Mclass(),
00758 sym->Byte_size());
00759 #ifdef KEY // bug 8186
00760 if (MTYPE_is_unsigned(sym->Mtype()))
00761 rtype = Mtype_TransferSign(MTYPE_U4, rtype);
00762 #endif
00763 }
00764 #endif
00765 MTYPE desc = rtype;
00766 #ifdef KEY // promote to register type size
00767 if (i != _opt_stab->Default_vsym() &&
00768 desc != MTYPE_UNKNOWN && desc != MTYPE_M)
00769 rtype = OPCODE_rtype(Ldid_from_mtype(desc));
00770 #endif
00771
00772 if (rtype != MTYPE_UNKNOWN && rtype != MTYPE_M) {
00773 ty = MTYPE_To_TY(rtype);
00774 }
00775
00776 chi_res->Set_dtyp(rtype);
00777 chi_res->Set_dsctyp(desc);
00778 chi_res->Set_lod_ty(ty);
00779 }
00780 return;
00781 }
00782 }
00783
00784
00785
00786
00787
00788 void
00789 OPT_REVISE_SSA::Insert_mu_and_chi_list_for_new_var(STMTREP *stmt, AUX_ID i)
00790 {
00791 AUX_ID cur;
00792 BOOL need_chi = FALSE;
00793 BOOL need_mu = FALSE;
00794 OPERATOR opr = stmt->Opr();
00795 AUX_STAB_ENTRY *aux = _opt_stab->Aux_stab_entry(i);
00796 if (OPERATOR_is_store(opr)) {
00797 switch(opr) {
00798 case OPR_STID:
00799 case OPR_STBITS:
00800 cur = stmt->Lhs()->Aux_id();
00801 if (cur == i)
00802 break;
00803 if (ST_class(_opt_stab->Aux_stab_entry(cur)->St()) == CLASS_PREG)
00804 break;
00805 if (_opt_stab->Rule()->Aliased_Memop_By_Analysis( aux->Points_to(),
00806 _opt_stab->Aux_stab_entry(cur)->Points_to()))
00807 need_chi = TRUE;
00808 break;
00809 case OPR_ISTORE:
00810 case OPR_MSTORE:
00811 cur = stmt->Lhs()->Ivar_occ()->Aux_id();
00812 if (_opt_stab->Rule()->Aliased_Memop(aux->Points_to(),
00813 stmt->Lhs()->Ivar_occ()->Points_to(),
00814 aux->Points_to()->Ty(),
00815 stmt->Ty()))
00816 need_chi = TRUE;
00817 break;
00818 default: ;
00819 }
00820 }
00821 else if (opr == OPR_RETURN
00822 #ifdef KEY
00823 || opr == OPR_GOTO_OUTER_BLOCK
00824 #endif
00825 ) {
00826 if (! _opt_stab->Aux_stab_entry(i)->Points_to()->Local() ||
00827 _opt_stab->Local_static(i))
00828 need_mu = TRUE;
00829 }
00830 else if (opr == OPR_OPT_CHI && i == _opt_stab->Default_vsym())
00831 need_chi = TRUE;
00832 else if (OPERATOR_is_call(opr) || opr == OPR_ASM_STMT || opr == OPR_REGION ||
00833 opr == OPR_FORWARD_BARRIER || opr == OPR_BACKWARD_BARRIER ||
00834 opr == OPR_DEALLOCA || opr == OPR_OPT_CHI) {
00835 if (! _opt_stab->Aux_stab_entry(i)->Points_to()->Local() ||
00836 _opt_stab->Local_static(i)) {
00837 need_chi = TRUE;
00838 if (opr != OPR_OPT_CHI && opr != OPR_ASM_STMT)
00839 need_mu = TRUE;
00840 }
00841 else {
00842
00843 CHI_LIST_ITER chi_iter;
00844 CHI_NODE *cnode;
00845 FOR_ALL_NODE(cnode, chi_iter, Init(stmt->Chi_list())) {
00846 if (! cnode->Live())
00847 continue;
00848 AUX_STAB_ENTRY *psym = _opt_stab->Aux_stab_entry(cnode->Aux_id());
00849 if (_opt_stab->Rule()->Aliased_Ofst_Rule(aux->Points_to(),
00850 psym->Points_to())) {
00851 need_chi = TRUE;
00852 if (opr != OPR_OPT_CHI)
00853 need_mu = TRUE;
00854 break;
00855 }
00856 }
00857 }
00858 }
00859
00860 if (need_mu) {
00861 if (stmt->Mu_list() == NULL)
00862 stmt->Set_mu_list(CXX_NEW(MU_LIST, _htable->Mem_pool()));
00863 MU_NODE *newmu = stmt->Mu_list()->New_mu_node(i, _htable->Mem_pool());
00864 newmu->Set_OPND(_htable->Ssa()->Get_zero_version_CR(i, _opt_stab, 0));
00865 }
00866 if (need_chi) {
00867 CODEREP *chi_res;
00868 if (stmt->Chi_list() == NULL)
00869 stmt->Set_chi_list(CXX_NEW(CHI_LIST, _htable->Mem_pool()));
00870 CHI_NODE *newchi = stmt->Chi_list()->New_chi_node(i, _htable->Mem_pool());
00871 newchi->Set_live(TRUE);
00872 newchi->Set_dse_dead(FALSE);
00873 AUX_STAB_ENTRY *sym = _opt_stab->Aux_stab_entry(i);
00874
00875 TY_IDX ty = TY_IDX_ZERO;
00876 ST *st = _opt_stab->St(i);
00877 if (st != NULL) ty = ST_type(st);
00878
00879 MTYPE rtype;
00880 #if defined(TARG_NVISA)
00881 rtype = sym->Mtype();
00882 #else
00883 if (sym->Mtype()==MTYPE_M || MTYPE_is_vector(sym->Mtype()))
00884 rtype = sym->Mtype();
00885 else {
00886 rtype = Mtype_from_mtype_class_and_size(sym->Mclass(),
00887 sym->Byte_size());
00888 #ifdef KEY // bug 8186
00889 if (MTYPE_is_unsigned(sym->Mtype()))
00890 rtype = Mtype_TransferSign(MTYPE_U4, rtype);
00891 #endif
00892 }
00893 #endif
00894 MTYPE desc = rtype;
00895 #ifdef KEY // promote to register type size
00896 if (i != _opt_stab->Default_vsym() &&
00897 desc != MTYPE_UNKNOWN && desc != MTYPE_M)
00898 rtype = OPCODE_rtype(Ldid_from_mtype(desc));
00899 #endif
00900
00901 if (rtype != MTYPE_UNKNOWN && rtype != MTYPE_M) {
00902 ty = MTYPE_To_TY(rtype);
00903 }
00904
00905 chi_res = _htable->Add_def(i, -1, stmt, rtype, desc,
00906 _opt_stab->St_ofst(i), ty, 0, TRUE);
00907 chi_res->Set_flag(CF_DEF_BY_CHI);
00908 chi_res->Set_defchi(newchi);
00909 newchi->Set_RESULT(chi_res);
00910 newchi->Set_OPND(_htable->Ssa()->Get_zero_version_CR(i, _opt_stab, 0));
00911 }
00912 }
00913
00914
00915
00916
00917
00918 void
00919 OPT_REVISE_SSA::Update_mu_and_chi_list(STMTREP *stmt)
00920 {
00921 if (! stmt->Has_chi() && ! stmt->Has_mu())
00922 return;
00923 AUX_ID i;
00924
00925
00926 IDX_32_SET_ITER iter;
00927 iter.Init(_symbols_to_revise);
00928 for (i = iter.First_elem(); ! iter.Is_Empty(); i = iter.Next_elem()) {
00929 if (i >= _first_new_aux_id)
00930 break;
00931 if (_opt_stab->Aux_stab_entry(i)->Is_volatile())
00932 continue;
00933 Update_chi_list_for_old_var(stmt, i);
00934 }
00935
00936
00937 for (i = _first_new_aux_id; i <= _opt_stab->Lastidx(); i++) {
00938 if (_opt_stab->Aux_stab_entry(i)->Is_volatile())
00939 continue;
00940 Insert_mu_and_chi_list_for_new_var(stmt, i);
00941 }
00942 }
00943
00944
00945
00946
00947 CODEREP *
00948 OPT_REVISE_SSA::Create_EXTRACT_BITS(INT bit_offset, INT bit_size,
00949 CODEREP *v, MTYPE rtype)
00950 {
00951 CODEREP stack_cr;
00952 stack_cr.Init_expr(OPCODE_make_op(OPR_EXTRACT_BITS, rtype, MTYPE_V), v);
00953 stack_cr.Set_op_bit_offset(bit_offset);
00954 stack_cr.Set_op_bit_size(bit_size);
00955 return _htable->Rehash(&stack_cr);
00956 }
00957
00958
00959
00960
00961 CODEREP *
00962 OPT_REVISE_SSA::Create_COMPOSE_BITS(INT bit_offset, INT bit_size,
00963 CODEREP *v, CODEREP *rhs)
00964 {
00965 CODEREP stack_cr;
00966 #if 0
00967 if (MTYPE_bit_size(v->Dtyp()) != MTYPE_bit_size(rhs->Dtyp())) {
00968 CODEREP cvt_cr;
00969 FOLD ftmp;
00970 OPCODE opc = OPCODE_make_op(OPR_CVT, v->Dtyp(), rhs->Dtyp());
00971 cvt_cr.Init_expr(opc, rhs);
00972 rhs = ftmp.Fold_Expr(&cvt_cr);
00973 if (!rhs)
00974 rhs = _htable->Rehash(&cvt_cr);
00975 }
00976 #endif
00977 stack_cr.Init_expr(OPCODE_make_op(OPR_COMPOSE_BITS, v->Dtyp(), MTYPE_V), v);
00978 stack_cr.Set_kid_count(2);
00979 stack_cr.Set_opnd(1, rhs);
00980 stack_cr.Set_op_bit_offset(bit_offset);
00981 stack_cr.Set_op_bit_size(bit_size);
00982 return _htable->Rehash(&stack_cr);
00983 }
00984
00985
00986
00987
00988 void
00989 OPT_REVISE_SSA::Delete_chi(AUX_ID aux_id, STMTREP *stmt)
00990 {
00991 CHI_NODE *cnode, *prev_cnode;
00992 CHI_LIST_ITER chi_iter;
00993
00994 chi_iter.Init(stmt->Chi_list());
00995 for (prev_cnode = NULL, cnode = chi_iter.First();
00996 ! chi_iter.Is_Empty();
00997 prev_cnode = cnode, cnode = chi_iter.Next()) {
00998 if (cnode->Aux_id() != aux_id)
00999 continue;
01000 stmt->Chi_list()->Remove(prev_cnode, cnode);
01001 stmt->Recompute_has_zver();
01002 return;
01003 }
01004 }
01005
01006
01007
01008
01009
01010
01011 CODEREP *
01012 OPT_REVISE_SSA::Form_extract(CODEREP *cr)
01013 {
01014 CODEREP *x, *x2;
01015 CODEREP *new_cr = Alloc_stack_cr(cr->Extra_ptrs_used());
01016 BOOL need_rehash;
01017 INT32 i;
01018 switch (cr->Kind()) {
01019 case CK_CONST:
01020 case CK_RCONST:
01021 case CK_LDA:
01022 return NULL;
01023 case CK_VAR:
01024 if (cr->Bit_field_valid()) {
01025
01026 x = _htable->Ssa()->Get_zero_version_CR(cr->Scalar_aux_id(), _opt_stab,0);
01027 AUX_STAB_ENTRY *sym = _opt_stab->Aux_stab_entry(cr->Scalar_aux_id());
01028 #ifdef KEY
01029 if (sym->Is_volatile())
01030 x->Set_var_volatile();
01031 #endif
01032 x->Set_dtyp(cr->Dtyp());
01033 x->Set_dsctyp(Mtype_from_mtype_class_and_size(MTYPE_type_class(cr->Dtyp()), sym->Byte_size()));
01034 #ifdef KEY
01035 x->Set_sign_extension_flag();
01036 #endif
01037 #ifndef KEY
01038 return Create_EXTRACT_BITS(cr->Bit_offset(), cr->Bit_size(), x, cr->Dtyp());
01039 #else
01040 INT32 adjust = 0;
01041 if (Target_Byte_Sex == BIG_ENDIAN)
01042 adjust = MTYPE_bit_size(cr->Dtyp()) - MTYPE_bit_size(x->Dsctyp());
01043 return Create_EXTRACT_BITS(cr->Bit_offset()+adjust, cr->Bit_size(), x,
01044 cr->Dtyp());
01045 #endif
01046 }
01047 #ifdef KEY
01048 else if (cr->Promote_to_reg_size()) {
01049
01050 x = _htable->Ssa()->Get_zero_version_CR(cr->Scalar_aux_id(), _opt_stab,0);
01051 AUX_STAB_ENTRY *osym = _opt_stab->Aux_stab_entry(cr->Aux_id());
01052 AUX_STAB_ENTRY *sym = _opt_stab->Aux_stab_entry(cr->Scalar_aux_id());
01053 MTYPE mtyp = Mtype_from_mtype_class_and_size(MTYPE_CLASS_UNSIGNED_INTEGER,
01054 sym->Byte_size());
01055 if (cr->Dtyp() != MTYPE_M)
01056 x->Set_dtyp(Mtype_TransferSize(mtyp, cr->Dtyp()));
01057 else x->Set_dtyp(mtyp);
01058 x->Set_dsctyp(x->Dtyp());
01059 x->Set_sign_extension_flag();
01060 INT32 bofst = (osym->Base_byte_ofst() - sym->Base_byte_ofst()) * 8;
01061 Is_True(bofst >= 0 && (bofst<32 || sym->Byte_size() == 8 && bofst<64),
01062 ("Form_extract:: illegal bit offset in extract"));
01063 x = Create_EXTRACT_BITS(bofst, MTYPE_bit_size(cr->Dsctyp()), x,
01064 x->Dtyp());
01065 if (MTYPE_byte_size(x->Dtyp()) != MTYPE_byte_size(cr->Dtyp()) &&
01066 cr->Dtyp() != MTYPE_M) {
01067 CODEREP stack_cr;
01068 stack_cr.Init_expr(OPCODE_make_op(OPR_CVT, cr->Dtyp(), x->Dtyp()), x);
01069 x = _htable->Rehash(&stack_cr);
01070 }
01071 return x;
01072 }
01073 #endif
01074 return NULL;
01075 case CK_IVAR:
01076 x = Form_extract(cr->Ilod_base());
01077 if (x)
01078 cr->Set_ilod_base(x);
01079 if (cr->Opr() == OPR_MLOAD) {
01080 x2 = Form_extract(cr->Mload_size());
01081 if (x2)
01082 cr->Set_mload_size(x2);
01083 }
01084 else if (cr->Opr() == OPR_ILOADX) {
01085 x2 = Form_extract(cr->Index());
01086 if (x2)
01087 cr->Set_index(x2);
01088 }
01089 else x2 = NULL;
01090 if (cr->Opr() != OPR_ILDBITS) {
01091 if (x || x2) {
01092 new_cr->Copy(*cr);
01093 new_cr->Set_istr_base(NULL);
01094 new_cr->Set_usecnt(0);
01095 if (x)
01096 new_cr->Set_ilod_base(x);
01097 if (x2)
01098 new_cr->Set_mload_size(x2);
01099 new_cr->Set_ivar_occ(cr->Ivar_occ());
01100 cr->DecUsecnt();
01101 return _htable->Rehash(new_cr);
01102 }
01103 return NULL;
01104 }
01105
01106 new_cr->Copy(*cr);
01107 new_cr->Set_opr(OPR_ILOAD);
01108 new_cr->Set_istr_base(NULL);
01109 new_cr->Set_i_field_id(0);
01110 new_cr->Set_usecnt(0);
01111 if (x)
01112 new_cr->Set_ilod_base(x);
01113 new_cr->Set_ivar_occ(cr->Scalar_ivar_occ());
01114
01115 new_cr->Set_ivar_mu_node(CXX_NEW(MU_NODE(*cr->Ivar_mu_node()),
01116 _htable->Mem_pool()));
01117
01118 new_cr->Ivar_mu_node()->Set_OPND(_htable->Ssa()->Get_zero_version_CR(new_cr->Ivar_occ()->Aux_id(), _opt_stab, 0));
01119 cr->DecUsecnt();
01120 x = _htable->Rehash(new_cr);
01121 #ifndef KEY
01122 return Create_EXTRACT_BITS(cr->I_bit_offset(), cr->I_bit_size(), x,
01123 cr->Dtyp());
01124 #else
01125 {
01126 INT32 adjust = 0;
01127 if (Target_Byte_Sex == BIG_ENDIAN)
01128 adjust = MTYPE_bit_size(cr->Dtyp()) - MTYPE_bit_size(x->Dsctyp());
01129 return Create_EXTRACT_BITS(cr->I_bit_offset()+adjust, cr->I_bit_size(), x,
01130 cr->Dtyp());
01131 }
01132 #endif
01133 case CK_OP:
01134 need_rehash = FALSE;
01135 new_cr->Copy(*cr);
01136 new_cr->Set_usecnt(0);
01137 OPERATOR opr = cr->Opr();
01138
01139 for (i = 0; i < cr->Kid_count(); i++) {
01140 x = Form_extract(cr->Opnd(i));
01141 if (x) {
01142 need_rehash = TRUE;
01143 new_cr->Set_opnd(i, x);
01144 }
01145 else new_cr->Set_opnd(i, cr->Opnd(i));
01146 }
01147 if (need_rehash) {
01148 cr->DecUsecnt();
01149 return _htable->Rehash(new_cr);
01150 }
01151 return NULL;
01152 }
01153 }
01154
01155
01156
01157
01158
01159
01160 void
01161 OPT_REVISE_SSA::Form_extract_compose(void)
01162 {
01163 CFG_ITER cfg_iter(_cfg);
01164 BB_NODE *bb;
01165 INT32 i;
01166 CODEREP *x, *v;
01167
01168
01169 FOR_ALL_NODE( bb, cfg_iter, Init() ) {
01170 Update_phis(bb);
01171
01172
01173 STMTREP_ITER stmt_iter(bb->Stmtlist());
01174 STMTREP *stmt;
01175 FOR_ALL_NODE(stmt, stmt_iter, Init()) {
01176 OPERATOR opr = stmt->Opr();
01177 CODEREP *rhs = stmt->Rhs();
01178 if (OPERATOR_is_call(opr) || opr == OPR_ASM_STMT) {
01179 for (i = 0; i < rhs->Kid_count(); i++) {
01180 x = Form_extract(rhs->Opnd(i));
01181 if (x)
01182 rhs->Set_opnd(i, x);
01183 }
01184 }
01185 else {
01186 if (rhs) {
01187 if (opr == OPR_PREFETCH) {
01188 x = Form_extract(rhs->Ilod_base());
01189 if (x)
01190 rhs->Set_ilod_base(x);
01191 }
01192 else {
01193 x = Form_extract(rhs);
01194 if (x) {
01195 stmt->Set_rhs(x);
01196 rhs = x;
01197 }
01198 }
01199 }
01200 }
01201
01202 if (OPERATOR_is_store(opr)) {
01203 CODEREP *lhs = stmt->Lhs();
01204 switch (opr) {
01205 case OPR_MSTORE:
01206 x = Form_extract(lhs->Mstore_size());
01207 if (x)
01208 lhs->Set_mstore_size(x);
01209
01210 case OPR_ISTORE:
01211 case OPR_ISTBITS:
01212 x = Form_extract(lhs->Istr_base());
01213 if (x)
01214 lhs->Set_istr_base(x);
01215 break;
01216 default: ;
01217 }
01218
01219
01220 if (opr == OPR_STBITS
01221 #ifdef KEY
01222 || (opr == OPR_STID && lhs->Promote_to_reg_size())
01223 #endif
01224 ) {
01225
01226 TY_IDX stbits_tyidx = Void_Type;
01227 #if !defined(TARG_NVISA)
01228 if (opr == OPR_STBITS) {
01229 stbits_tyidx = MTYPE_To_TY(lhs->Dsctyp());
01230 }
01231 #endif
01232
01233 if (stmt->Chi_list() == NULL)
01234 stmt->Set_chi_list(CXX_NEW(CHI_LIST, _htable->Mem_pool()));
01235 CHI_NODE *newchi
01236 = stmt->Chi_list()->New_chi_node(lhs->Aux_id(),
01237 _htable->Mem_pool());
01238 newchi->Set_live(TRUE);
01239 newchi->Set_dse_dead(FALSE);
01240 lhs->Set_flag(CF_DEF_BY_CHI);
01241 lhs->Set_defchi(newchi);
01242 newchi->Set_RESULT(lhs);
01243 newchi->Set_OPND(_htable->Ssa()->Get_zero_version_CR(lhs->Aux_id(),
01244 _opt_stab, 0));
01245
01246
01247 v = _htable->Ssa()->Get_zero_version_CR(lhs->Scalar_aux_id(),
01248 _opt_stab, 0);
01249 AUX_STAB_ENTRY *sym = _opt_stab->Aux_stab_entry(lhs->Scalar_aux_id());
01250 #ifdef KEY
01251 if (sym->Is_volatile())
01252 v->Set_var_volatile();
01253 #endif
01254 v->Set_dsctyp(Mtype_from_mtype_class_and_size(MTYPE_type_class(lhs->Dtyp()), sym->Byte_size()));
01255 v->Set_dtyp(OPCODE_rtype(Ldid_from_mtype(v->Dsctyp())));
01256 #ifdef KEY
01257 v->Set_sign_extension_flag();
01258 #endif
01259 INT32 adjust = 0;
01260 if (Target_Byte_Sex == BIG_ENDIAN)
01261 adjust = MTYPE_bit_size(v->Dtyp()) - MTYPE_bit_size(v->Dsctyp());
01262 #ifdef KEY // bug 9179
01263 if (opr == OPR_STID) {
01264 AUX_STAB_ENTRY *osym = _opt_stab->Aux_stab_entry(lhs->Aux_id());
01265 INT32 bofst = (osym->Base_byte_ofst() - sym->Base_byte_ofst()) * 8;
01266 Is_True(bofst >= 0 && (bofst<32 || sym->Byte_size() == 8 && bofst<64),
01267 ("Form_extract_compose:: illegal bit offset in compose"));
01268 stmt->Set_rhs(Create_COMPOSE_BITS(bofst+adjust, MTYPE_bit_size(lhs->Dsctyp()), v, rhs));
01269 }
01270 else
01271 #endif
01272 stmt->Set_rhs(Create_COMPOSE_BITS(lhs->Bit_offset()+adjust, lhs->Bit_size(), v, rhs));
01273
01274 #ifdef KEY // bug 9179
01275 if (opr == OPR_STID)
01276 stmt->Set_lhs(_htable->Add_def(v->Aux_id(), -1, stmt,
01277 v->Dtyp(), v->Dsctyp(), v->Offset(), stbits_tyidx, 0, TRUE));
01278 else
01279 #endif
01280 stmt->Set_lhs(_htable->Add_def(lhs->Scalar_aux_id(), -1, stmt,
01281 lhs->Dtyp(), lhs->Dsctyp(), lhs->Offset(), stbits_tyidx, 0, TRUE));
01282
01283 stmt->Set_opr(OPR_STID);
01284 if (v->Aux_id() < _first_new_aux_id)
01285 Delete_chi(v->Aux_id(), stmt);
01286 }
01287 else if (opr == OPR_ISTBITS) {
01288
01289 CODEREP *new_cr = Alloc_stack_cr(lhs->Extra_ptrs_used());
01290 new_cr->Copy(*lhs);
01291 new_cr->Set_opr(OPR_ILOAD);
01292 new_cr->Set_ilod_base(lhs->Istr_base());
01293 new_cr->Set_istr_base(NULL);
01294 new_cr->Set_ivar_defstmt(NULL);
01295 new_cr->Set_i_field_id(0);
01296 new_cr->Set_usecnt(1);
01297 new_cr->Set_ivar_occ(lhs->Scalar_ivar_occ());
01298
01299 MU_NODE *mu = CXX_NEW(MU_NODE, _htable->Mem_pool());
01300 mu->Set_aux_id(lhs->Scalar_ivar_occ()->Aux_id());
01301
01302 mu->Set_OPND(_htable->Ssa()->Get_zero_version_CR(new_cr->Ivar_occ()->Aux_id(), _opt_stab, 0));
01303 new_cr->Set_ivar_mu_node(mu);
01304 v = _htable->Rehash(new_cr);
01305 #ifndef KEY
01306 stmt->Set_rhs(Create_COMPOSE_BITS(lhs->I_bit_offset(), lhs->I_bit_size(), v, rhs));
01307 #else
01308 INT32 adjust = 0;
01309 if (Target_Byte_Sex == BIG_ENDIAN)
01310 adjust = MTYPE_bit_size(v->Dtyp()) - MTYPE_bit_size(v->Dsctyp());
01311 stmt->Set_rhs(Create_COMPOSE_BITS(lhs->I_bit_offset()+adjust, lhs->I_bit_size(), v, rhs));
01312 #endif
01313
01314
01315 stmt->Set_lhs(_htable->Add_idef(
01316 OPCODE_make_op(OPR_ILOAD, lhs->Dtyp(), lhs->Dsctyp()),
01317 lhs->Scalar_ivar_occ(), stmt, NULL,
01318 lhs->Dtyp(), lhs->Dsctyp(), lhs->Ilod_ty(), 0,
01319 lhs->Offset(), (CODEREP *)Make_Pointer_Type(MTYPE_To_TY(lhs->Dsctyp())),
01320 NULL, lhs->Istr_base(), _opt_stab));
01321 stmt->Set_opr(OPR_ISTORE);
01322 }
01323 }
01324
01325
01326 Update_mu_and_chi_list(stmt);
01327 }
01328 }
01329 }
01330
01331
01332
01333
01334
01335
01336 CODEREP *
01337 OPT_REVISE_SSA::Fold_lda_iloads(CODEREP *cr)
01338 {
01339 CODEREP *x, *x2;
01340 CODEREP *new_cr = Alloc_stack_cr(cr->Extra_ptrs_used());
01341 BOOL need_rehash;
01342 INT32 i;
01343 switch (cr->Kind()) {
01344 case CK_CONST:
01345 case CK_RCONST:
01346 case CK_LDA:
01347 case CK_VAR:
01348 return NULL;
01349 case CK_IVAR:
01350 x = Fold_lda_iloads(cr->Ilod_base());
01351 if (x)
01352 cr->Set_ilod_base(x);
01353 if (cr->Opr() == OPR_MLOAD) {
01354 x2 = Fold_lda_iloads(cr->Mload_size());
01355 if (x2)
01356 cr->Set_mload_size(x2);
01357 }
01358 else if (cr->Opr() == OPR_ILOADX) {
01359 x2 = Fold_lda_iloads(cr->Index());
01360 if (x2)
01361 cr->Set_index(x2);
01362 }
01363 else x2 = NULL;
01364 if (x || x2) {
01365 new_cr->Copy(*cr);
01366 new_cr->Set_istr_base(NULL);
01367 new_cr->Set_usecnt(0);
01368 if (x)
01369 new_cr->Set_ilod_base(x);
01370 if (x2)
01371 new_cr->Set_mload_size(x2);
01372 new_cr->Set_ivar_occ(cr->Ivar_occ());
01373 cr->DecUsecnt();
01374 return _htable->Rehash(new_cr);
01375 }
01376 if (cr->Ilod_base()->Kind() != CK_LDA ||
01377 cr->Is_ivar_volatile() ||
01378 cr->Opr() == OPR_PARM ||
01379 cr->Opr() == OPR_ILOADX ||
01380 cr->Opr() == OPR_MLOAD)
01381 return NULL;
01382 #ifdef KEY
01383 if (cr->Scalar_aux_id() == 0)
01384 return NULL;
01385 #endif
01386
01387
01388 x = _htable->Ssa()->Get_zero_version_CR(cr->Scalar_aux_id(), _opt_stab, 0);
01389 #ifdef KEY // bug 8933
01390 if (_opt_stab->Is_volatile(cr->Scalar_aux_id()))
01391 x->Set_var_volatile();
01392 #endif
01393 #if 1 // bug fix aug-26-02
01394
01395 if (x->Is_var_volatile())
01396 return NULL;
01397 #endif
01398 x->Set_dsctyp(cr->Dsctyp());
01399 x->Set_lod_ty(TY_pointed(cr->Ilod_base_ty()));
01400 x->Set_field_id(cr->I_field_id());
01401 #if 1 // bug fix sep-4-02
01402 if (x->Field_id() == 0 && x->Dsctyp() != MTYPE_M &&
01403 TY_size(x->Lod_ty()) != MTYPE_byte_size(x->Dsctyp()))
01404 x->Set_lod_ty(MTYPE_To_TY(x->Dsctyp()));
01405 #endif
01406 if (cr->Dsctyp() == MTYPE_BS)
01407 x->Set_offset(cr->Offset()+cr->Ilod_base()->Offset());
01408 if (cr->Opr() == OPR_ILDBITS)
01409 x->Set_bit_field_valid();
01410
01411 if (MTYPE_is_integral(x->Dtyp())
01412 && MTYPE_byte_size(cr->Dtyp()) != MTYPE_byte_size(x->Dtyp()))
01413 {
01414 DevWarn("insert cvt above zero-version");
01415 CODEREP cvt_cr;
01416 cvt_cr.Init_expr(OPCODE_make_op(OPR_CVT, cr->Dtyp(), x->Dtyp()), x);
01417 x = _htable->Rehash(&cvt_cr);
01418 }
01419 else
01420 x->Set_dtyp(cr->Dtyp());
01421 cr->DecUsecnt();
01422 return x;
01423 case CK_OP:
01424 #ifdef KEY // bug 3064
01425 if (cr->Is_isop_flag_set(ISOP_LDAFOLD2_VISITED))
01426 return NULL;
01427 #endif
01428 need_rehash = FALSE;
01429 new_cr->Copy(*cr);
01430 new_cr->Set_usecnt(0);
01431 OPERATOR opr = cr->Opr();
01432
01433 for (i = 0; i < cr->Kid_count(); i++) {
01434 x = Fold_lda_iloads(cr->Opnd(i));
01435 if (x) {
01436 need_rehash = TRUE;
01437 new_cr->Set_opnd(i, x);
01438 }
01439 else new_cr->Set_opnd(i, cr->Opnd(i));
01440 }
01441 if (need_rehash) {
01442 cr->DecUsecnt();
01443 return _htable->Rehash(new_cr);
01444 }
01445 #ifdef KEY // bug 3064
01446 cr->Set_isop_flag(ISOP_LDAFOLD2_VISITED);
01447 #endif
01448 return NULL;
01449 }
01450 }
01451
01452
01453
01454
01455
01456
01457 void
01458 OPT_REVISE_SSA::Fold_lda_indirects(void)
01459 {
01460 CFG_ITER cfg_iter(_cfg);
01461 BB_NODE *bb;
01462 INT32 i;
01463 CODEREP *x, *v;
01464
01465
01466 FOR_ALL_NODE( bb, cfg_iter, Init() ) {
01467 Update_phis(bb);
01468
01469
01470 STMTREP_ITER stmt_iter(bb->Stmtlist());
01471 STMTREP *stmt;
01472 FOR_ALL_NODE(stmt, stmt_iter, Init()) {
01473 OPERATOR opr = stmt->Opr();
01474 CODEREP *rhs = stmt->Rhs();
01475 if (OPERATOR_is_call(opr) || opr == OPR_ASM_STMT) {
01476 for (i = 0; i < rhs->Kid_count(); i++) {
01477 x = Fold_lda_iloads(rhs->Opnd(i));
01478 if (x)
01479 rhs->Set_opnd(i, x);
01480 }
01481 }
01482 else {
01483 if (rhs) {
01484 if (opr == OPR_PREFETCH) {
01485 x = Fold_lda_iloads(rhs->Ilod_base());
01486 if (x)
01487 rhs->Set_ilod_base(x);
01488 }
01489 else {
01490 x = Fold_lda_iloads(rhs);
01491 if (x) {
01492 stmt->Set_rhs(x);
01493 rhs = x;
01494 }
01495 }
01496 }
01497 }
01498
01499 if (OPERATOR_is_store(opr)) {
01500 CODEREP *lhs = stmt->Lhs();
01501 AUX_ID vaux;
01502 switch (opr) {
01503 case OPR_MSTORE:
01504 x = Fold_lda_iloads(lhs->Mstore_size());
01505 if (x)
01506 lhs->Set_mstore_size(x);
01507 x = Fold_lda_iloads(lhs->Istr_base());
01508 if (x)
01509 lhs->Set_istr_base(x);
01510 break;
01511 case OPR_ISTORE:
01512 case OPR_ISTBITS:
01513 if (lhs->Istr_base()->Kind() != CK_LDA) {
01514 x = Fold_lda_iloads(lhs->Istr_base());
01515 if (x)
01516 lhs->Set_istr_base(x);
01517 break;
01518 }
01519 if (lhs->Is_ivar_volatile())
01520 break;
01521 vaux = lhs->Scalar_aux_id();
01522 #ifdef KEY
01523 if (vaux == 0)
01524 break;
01525 #endif
01526 #if 1 // bug fix aug-26-02
01527
01528 if (_opt_stab->Is_volatile(vaux))
01529 break;
01530 #endif
01531
01532
01533 stmt->Set_lhs(_htable->Add_def(vaux, -1, stmt,
01534 lhs->Dtyp(), lhs->Dsctyp(),
01535 _opt_stab->St_ofst(vaux),
01536 TY_pointed(lhs->Ilod_base_ty()), lhs->I_field_id(),
01537 TRUE));
01538 #if 1 // bug fix sep-4-02
01539 if (stmt->Lhs()->Field_id() == 0 && stmt->Lhs()->Dsctyp() != MTYPE_M &&
01540 TY_size(stmt->Lhs()->Lod_ty()) != MTYPE_byte_size(stmt->Lhs()->Dsctyp()))
01541 stmt->Lhs()->Set_lod_ty(MTYPE_To_TY(stmt->Lhs()->Dsctyp()));
01542 #endif
01543 if (lhs->Dsctyp() == MTYPE_BS)
01544 stmt->Lhs()->Set_offset(lhs->Offset()+lhs->Istr_base()->Offset());
01545 if (stmt->Opr() == OPR_ISTORE)
01546 stmt->Set_opr(OPR_STID);
01547 else {
01548 stmt->Set_opr(OPR_STBITS);
01549 stmt->Lhs()->Set_bit_field_valid();
01550 }
01551 if (vaux < _first_new_aux_id)
01552 Delete_chi(vaux, stmt);
01553 break;
01554 default: ;
01555 }
01556 }
01557
01558
01559 Update_mu_and_chi_list(stmt);
01560 }
01561 }
01562 }
01563
01564
01565
01566
01567
01568
01569
01570
01571 void
01572 OPT_REVISE_SSA::Rename_new_scalars(COMP_UNIT *cunit)
01573 {
01574 Rename_CODEMAP(cunit);
01575 }
01576
01577
01578
01579
01580
01581
01582
01583
01584 void
01585 COMP_UNIT::Lower_to_extract_compose(void)
01586 {
01587 MEM_POOL revise_ssa_pool;
01588
01589 OPT_POOL_Initialize(&revise_ssa_pool, "revise ssa pool", FALSE, OPT_LOWER_FLAG);
01590 OPT_POOL_Push(&revise_ssa_pool, OPT_LOWER_FLAG);
01591
01592 {
01593 OPT_REVISE_SSA opt_revise_ssa(Opt_stab(), Htable(), Cfg(),
01594 &revise_ssa_pool, OPT_LOWER_FLAG);
01595 opt_revise_ssa.Find_scalars_from_lowering_bitfld();
01596 if (opt_revise_ssa.Has_bitfield()) {
01597 opt_revise_ssa.Form_extract_compose();
01598 opt_revise_ssa.Rename_new_scalars(this);
01599 }
01600 }
01601
01602 OPT_POOL_Pop(&revise_ssa_pool, OPT_LOWER_FLAG);
01603 OPT_POOL_Delete(&revise_ssa_pool, OPT_LOWER_FLAG);
01604
01605 if ( Get_Trace(TP_GLOBOPT, OPT_LOWER_FLAG)) {
01606 fprintf( TFile, "%sAfter COMP_UNIT::Lower_to_extract_compose\n%s",
01607 DBar, DBar );
01608 Cfg()->Print(TFile);
01609 }
01610 }
01611
01612
01613
01614
01615 void
01616 COMP_UNIT::Fold_lda_iload_istore(void)
01617 {
01618 MEM_POOL revise_ssa_pool;
01619
01620 OPT_POOL_Initialize(&revise_ssa_pool, "revise ssa pool", FALSE, FOLD_DUMP_FLAG);
01621 OPT_POOL_Push(&revise_ssa_pool, FOLD_DUMP_FLAG);
01622
01623 {
01624 OPT_REVISE_SSA opt_revise_ssa(Opt_stab(), Htable(), Cfg(),
01625 &revise_ssa_pool, FOLD_DUMP_FLAG);
01626 opt_revise_ssa.Find_scalars_from_lda_indirects();
01627 if (opt_revise_ssa.Has_lda_indirect()) {
01628 opt_revise_ssa.Fold_lda_indirects();
01629 opt_revise_ssa.Rename_new_scalars(this);
01630 }
01631 }
01632
01633 OPT_POOL_Pop(&revise_ssa_pool, FOLD_DUMP_FLAG);
01634 OPT_POOL_Delete(&revise_ssa_pool, FOLD_DUMP_FLAG);
01635
01636 if ( Get_Trace(TP_GLOBOPT, FOLD_DUMP_FLAG)) {
01637 fprintf( TFile, "%sAfter COMP_UNIT::Fold_lda_iload_istore\n%s",
01638 DBar, DBar );
01639 Cfg()->Print(TFile);
01640 }
01641 }