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
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 #ifdef KEY
00094 #define EBO_REG(regs, cl, op_num) \
00095 (regs[((op_num) * (ISA_REGISTER_CLASS_MAX+1)) + (cl)])
00096 #endif
00097
00098 inline
00099 BOOL
00100 EBO_tn_available(BB *bb,
00101 EBO_TN_INFO *tninfo)
00102 {
00103 TN *tn;
00104 BB *tn_bb;
00105
00106
00107 if ((tninfo == NULL) ||
00108 (tninfo->local_tn == NULL)) return FALSE;
00109 tn = tninfo->local_tn;
00110 tn_bb = tninfo->in_bb;
00111
00112 if (TN_Is_Constant(tn)) return TRUE;
00113
00114 if (get_tn_info(tn) != tninfo) return FALSE;
00115
00116 if ((Opt_Level < 2) && (bb != tn_bb)) return FALSE;
00117
00118
00119
00120
00121 if (!EBO_in_peep &&
00122 ((bb != tn_bb) &&
00123 has_assigned_reg(tn))) return FALSE;
00124
00125 #ifdef KEY
00126
00127
00128
00129
00130 if (Opt_Level >= 2 &&
00131 TN_is_global_reg(tn) &&
00132 TN_is_gra_homeable(tn) &&
00133 !GRA_LIVE_TN_Live_Into_BB(tn, bb)) {
00134 return FALSE;
00135 }
00136 #endif
00137
00138 return TRUE;
00139 }
00140
00141
00142 inline
00143 BOOL
00144 OP_effectively_copy(OP *op)
00145 {
00146 if (OP_copy(op)) return TRUE;
00147 if (CGTARG_Is_Copy(op)) return TRUE;
00148 if (EBO_Copy_Operand(op) >= 0) return TRUE;
00149 return FALSE;
00150 }
00151
00152
00153
00154 inline
00155 INT
00156 EBO_hash_op (OP *op,
00157 EBO_TN_INFO **based_on_tninfo)
00158 {
00159 INT hash_value = 0;
00160 if (OP_memory(op)
00161 #ifdef TARG_X8664
00162 || OP_load_exe(op)
00163 #endif
00164 ) {
00165 TN * spill_tn = NULL;
00166 hash_value = EBO_DEFAULT_MEM_HASH;
00167 if (OP_no_alias(op)) hash_value = EBO_NO_ALIAS_MEM_HASH;
00168 if (OP_load(op)) {
00169 spill_tn = OP_result(op,0);
00170 } else if (OP_store(op)) {
00171 spill_tn = OP_opnd(op,TOP_Find_Operand_Use(OP_code(op), OU_storeval));
00172 }
00173 #ifdef TARG_X8664
00174 if( OP_load_exe(op) && !OP_no_alias(op) ){
00175 const INT n = TOP_Find_Operand_Use(OP_code(op), OU_offset);
00176 TN* tn = OP_opnd( op, n );
00177 if( CGSPILL_Is_Spill_Location( TN_var(tn) ) ){
00178 hash_value = EBO_SPILL_MEM_HASH;
00179 }
00180 }
00181 #endif
00182 #ifdef KEY
00183 if (spill_tn && TN_has_spill(spill_tn)) {
00184 INT n = TOP_Find_Operand_Use(OP_code(op), OU_offset);
00185 if (n >= 0) {
00186 TN *ctn = OP_opnd(op, n);
00187 if (TN_is_constant(ctn) && TN_is_symbol(ctn) &&
00188 TN_var(ctn) == TN_spill(spill_tn))
00189 hash_value = EBO_SPILL_MEM_HASH;
00190 }
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 if (hash_value != EBO_SPILL_MEM_HASH) {
00204 const INT n = TOP_Find_Operand_Use(OP_code(op), OU_offset);
00205 if (n >= 0) {
00206 TN *tn = OP_opnd(op, n);
00207 if (TN_is_symbol(tn) &&
00208 CGSPILL_Is_Spill_Location(TN_var(tn))) {
00209 hash_value = EBO_SPILL_MEM_HASH;
00210 }
00211 }
00212 }
00213 #else
00214 if (spill_tn && TN_has_spill(spill_tn)) hash_value = EBO_SPILL_MEM_HASH;
00215 #endif
00216 } else if (OP_effectively_copy(op)) {
00217 hash_value = EBO_COPY_OP_HASH;
00218 } else {
00219 INT opcount = OP_opnds(op);
00220 INT opndnum;
00221 hash_value =
00222 #ifdef TARG_IA64
00223 ((OP_results(op) == 2) &&
00224 ((OP_result(op,0) != NULL) &&
00225 ((OP_result(op,0) == True_TN) ||
00226 (TN_register_class(OP_result(op,0)) == ISA_REGISTER_CLASS_predicate)))) ? 0 :
00227 #endif
00228 (INT)OP_code(op);
00229 for (opndnum = OP_has_predicate(op)?1:0; opndnum < opcount; opndnum++) {
00230 hash_value+=(INT)(INTPS)based_on_tninfo[opndnum];
00231 }
00232 hash_value = EBO_RESERVED_OP_HASH + EBO_EXP_OP_HASH(hash_value);
00233 }
00234 return hash_value;
00235 }
00236
00237
00238
00239 inline
00240 void
00241 add_to_hash_table ( BOOL in_delay_slot,
00242 OP *op,
00243 EBO_TN_INFO **actual_tninfo,
00244 EBO_TN_INFO **optimal_tninfo)
00245 {
00246 INT hash_value = EBO_hash_op(op, optimal_tninfo);
00247 INT idx;
00248 EBO_OP_INFO *opinfo;
00249 BB *bb = OP_bb(op);
00250 TN *op_predicate_tn;
00251 EBO_TN_INFO *op_predicate_tninfo;
00252
00253
00254 opinfo = get_new_opinfo(op);
00255 opinfo->in_bb = OP_bb(op);
00256 opinfo->in_op = op;
00257 opinfo->in_delay_slot = in_delay_slot;
00258 opinfo->hash_index = hash_value;
00259 opinfo->same = EBO_opinfo_table[hash_value];
00260
00261
00262 if (OP_has_predicate(op)) {
00263 op_predicate_tn = OP_opnd(op,OP_PREDICATE_OPND);
00264 op_predicate_tninfo = actual_tninfo[OP_PREDICATE_OPND];
00265 } else {
00266 op_predicate_tn = NULL;
00267 op_predicate_tninfo = NULL;
00268 }
00269
00270 for (idx = 0; idx < OP_results(op); idx++) {
00271 EBO_TN_INFO *tninfo = NULL;
00272 TN *tnr = OP_result(op, idx);
00273 #ifdef KEY
00274 if (OP_cond_def(op)) {
00275 EBO_TN_INFO *prev_tninfo = get_tn_info(tnr);
00276 if (prev_tninfo != NULL)
00277 inc_ref_count(prev_tninfo);
00278 }
00279 #endif
00280 if ((tnr != NULL) && (tnr != True_TN) && (tnr != Zero_TN)) {
00281 #ifdef TARG_X8664
00282 TN* tmp_tn = CGTARG_Gen_Dedicated_Subclass_TN( op, idx, TRUE );
00283 if( tmp_tn == NULL )
00284 tmp_tn = tnr;
00285 tninfo = tn_info_def(bb, op, tmp_tn, op_predicate_tn,
00286 op_predicate_tninfo);
00287 if (tmp_tn != tnr)
00288 tninfo = tn_info_def(bb, op, tnr, op_predicate_tn,
00289 op_predicate_tninfo);
00290 #else
00291 tninfo = tn_info_def (bb, op, tnr, op_predicate_tn, op_predicate_tninfo);
00292 #endif
00293 tninfo->in_opinfo = opinfo;
00294 }
00295 opinfo->actual_rslt[idx] = tninfo;
00296 }
00297
00298
00299 for (idx = 0; idx < OP_opnds(op); idx++) {
00300 opinfo->actual_opnd[idx] = actual_tninfo[idx];
00301 opinfo->optimal_opnd[idx] = optimal_tninfo[idx];
00302 }
00303
00304 EBO_opinfo_table[hash_value] = opinfo;
00305
00306 if (EBO_Trace_Data_Flow) {
00307 #pragma mips_frequency_hint NEVER
00308 fprintf(TFile,"%sCreate new opinfo entry at %d for:\n\t",EBO_trace_pfx,hash_value);
00309 Print_OP_No_SrcLine(op);
00310 }
00311 }
00312
00313 #if !defined(TARG_SL)
00314 inline
00315 BOOL
00316 tn_registers_identical (TN *tn1, TN *tn2)
00317 {
00318 return ((tn1 == tn2) ||
00319 ((TN_is_register(tn1) && TN_is_register(tn2) &&
00320 (TN_is_dedicated(tn1) || (TN_register(tn1) != REGISTER_UNDEFINED)) &&
00321 (TN_is_dedicated(tn2) || (TN_register(tn2) != REGISTER_UNDEFINED)) &&
00322 (TN_register_and_class(tn1) == TN_register_and_class(tn2)))));
00323 }
00324 #endif
00325
00326 inline
00327 EBO_OP_INFO *
00328 find_opinfo_entry (OP *op)
00329 {
00330 EBO_OP_INFO *opinfo;
00331 INT limit_search = 50;
00332
00333 for (opinfo = EBO_last_opinfo;
00334 ((opinfo != NULL) && (limit_search != 0));
00335 opinfo = opinfo->prior, limit_search--) {
00336 if (opinfo->in_op == op) return opinfo;
00337 }
00338
00339 return NULL;
00340 }
00341
00342
00343
00344
00345 inline
00346 EBO_OP_INFO *
00347 locate_opinfo_entry (EBO_TN_INFO *tninfo)
00348 {
00349
00350 if ((tninfo != NULL) && (tninfo->in_op != NULL)) {
00351 return (tninfo->in_opinfo != NULL) ? tninfo->in_opinfo : find_opinfo_entry(tninfo->in_op);
00352 }
00353
00354 return NULL;
00355 }
00356
00357
00358
00359
00360 inline
00361 void
00362 EBO_OPS_predicate(TN *predicate_tn, OPS *ops)
00363 {
00364 OP *next_op = OPS_first(ops);
00365 while (next_op != NULL) {
00366 if (OP_has_predicate(next_op)) {
00367 Set_OP_opnd(next_op, OP_PREDICATE_OPND, predicate_tn);
00368 }
00369 next_op = OP_next(next_op);
00370 }
00371 }
00372
00373
00374
00375
00376 inline
00377 void
00378 EBO_Exp_COPY(TN *predicate_tn, TN *tgt_tn, TN *src_tn, OPS *ops)
00379 {
00380 Exp_COPY(tgt_tn, src_tn, ops);
00381 if (predicate_tn != NULL) {
00382 EBO_OPS_predicate (predicate_tn, ops);
00383 }
00384 }
00385
00386
00387
00388
00389 inline
00390 void
00391 mark_tn_live_into_BB (TN *tn, BB *into_bb, BB *outof_bb)
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 {
00402 if (into_bb != outof_bb) {
00403 BB *in_bb;
00404 BOOL already_global = TRUE;
00405
00406 if (!TN_is_global_reg(tn)) {
00407 GTN_UNIVERSE_Add_TN(tn);
00408 already_global = FALSE;
00409 }
00410
00411 if (EBO_in_peep) {
00412 if (!REG_LIVE_Into_BB( TN_register_class(tn), TN_register(tn), into_bb)) {
00413 ISA_REGISTER_CLASS tn_class = TN_register_class(tn);
00414 REGISTER tn_reg = TN_register(tn);
00415 FmtAssert((has_assigned_reg(tn)),
00416 ("No assigned register in ebo utility mark_tn_live_into_BB"));
00417
00418
00419 in_bb = into_bb;
00420 while ((in_bb != NULL) && (in_bb != outof_bb)) {
00421 REG_LIVE_Update( tn_class, tn_reg, in_bb);
00422 in_bb = BB_First_Pred(in_bb);
00423 }
00424
00425 }
00426 } else {
00427
00428
00429
00430 GRA_LIVE_Add_Live_Use_GTN(into_bb, tn);
00431
00432
00433 if (!GRA_LIVE_TN_Live_Into_BB(tn, into_bb)) {
00434 GRA_LIVE_Add_Live_In_GTN(into_bb, tn);
00435 GRA_LIVE_Add_Defreach_In_GTN(into_bb, tn);
00436
00437 if (!already_global) {
00438
00439
00440
00441 GRA_LIVE_Add_Live_Def_GTN(outof_bb, tn);
00442 #ifdef KEY
00443
00444
00445
00446 if( TN_is_gra_homeable(tn) ){
00447 Reset_TN_is_gra_homeable( tn );
00448 Set_TN_home( tn, NULL );
00449 }
00450 #endif
00451 }
00452 GRA_LIVE_Add_Live_Out_GTN(outof_bb, tn);
00453 GRA_LIVE_Add_Defreach_Out_GTN(outof_bb, tn);
00454
00455
00456 in_bb = BB_First_Pred(into_bb);
00457 while ((in_bb != NULL) && (in_bb != outof_bb)) {
00458 GRA_LIVE_Add_Live_In_GTN(in_bb, tn);
00459 GRA_LIVE_Add_Defreach_In_GTN(in_bb, tn);
00460 GRA_LIVE_Add_Live_Out_GTN(in_bb, tn);
00461 GRA_LIVE_Add_Defreach_Out_GTN(in_bb, tn);
00462 in_bb = BB_First_Pred(in_bb);
00463 }
00464
00465 }
00466 }
00467 }
00468 }
00469
00470
00471 inline
00472 BOOL
00473 tn_has_live_def_into_BB (TN *tn, BB *into_bb)
00474
00475
00476
00477
00478
00479
00480
00481 {
00482 if (EBO_in_peep) {
00483 return TRUE;
00484 } else {
00485 return (TN_is_dedicated(tn) ||
00486 GTN_SET_MemberP(BB_defreach_in(into_bb), tn));
00487 }
00488 }