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 #ifndef opt_emit_template_INCLUDED
00064 #define opt_emit_template_INCLUDED "opt_emit_template.h"
00065
00066 #ifndef opt_combine_INCLUDED
00067 #include "opt_combine.h"
00068 #endif // opt_combine_INCLUDED
00069
00070 #ifndef opt_fold_INCLUDED
00071 #include "opt_fold.h"
00072 #endif // opt_fold_INCLUDED
00073
00074 #include "opt_project.h"
00075
00076 #include "be_symtab.h"
00077
00078 #include "opt_cvtl_rule.h"
00079 #include "wn_util.h"
00080
00081
00082 template < class EMITTER >WN*
00083 Gen_exp_wn(CODEREP *exp, EMITTER *emitter)
00084 {
00085 WN *wn;
00086 OPCODE op;
00087 OPERATOR opr;
00088 BOOL connect_cr_to_wn = TRUE;
00089 MTYPE actual_type;
00090 MTYPE actual_opnd_type;
00091
00092 switch (exp->Kind()) {
00093 case CK_OP:
00094 opr = exp->Opr();
00095 switch (opr) {
00096
00097 case OPR_CVT:
00098 {
00099 if (WOPT_Enable_Cvt_Folding && !emitter->For_preopt()) {
00100 INT cvt_kind;
00101 OPCODE opc;
00102 cvt_kind =
00103 Need_type_conversion(exp->Dsctyp(), exp->Dtyp(), &opc);
00104
00105 CODEREP *kid = exp->Get_opnd(0);
00106 if (cvt_kind == NEED_CVT) {
00107
00108 if (MTYPE_is_integral(exp->Dsctyp())
00109 #ifdef TARG_X8664
00110 && ! MTYPE_is_vector(exp->Dsctyp())
00111 #endif
00112 && MTYPE_is_integral(exp->Dtyp())
00113 #ifdef TARG_X8664
00114 && ! MTYPE_is_vector(exp->Dtyp())
00115 #endif
00116 && ! (Only_Unsigned_64_Bit_Ops && MTYPE_signed(exp->Dtyp()))
00117 && MTYPE_size_min(kid->Dsctyp()) >= MTYPE_size_min(MTYPE_I4)
00118 && ((kid->Kind() == CK_VAR && !kid->Is_var_volatile() &&
00119 ST_class(emitter->Opt_stab()->
00120 Aux_stab_entry(kid->Aux_id())->St()) != CLASS_PREG)
00121
00122 ||
00123 (kid->Kind() == CK_IVAR &&
00124 OPERATOR_is_scalar_iload (kid->Opr()) &&
00125 !kid->Is_ivar_volatile())
00126 )
00127 ) {
00128
00129 MTYPE mtype_d = kid->Dtyp();
00130 MTYPE mtype_dsc = kid->Dsctyp();
00131 kid->Set_dtyp(exp->Dtyp());
00132 if (exp->Dsctyp() == MTYPE_U4 && exp->Dtyp() == MTYPE_I8) {
00133 kid->Set_dtyp(MTYPE_U8);
00134 }
00135 kid->Set_dsctyp(Mtype_TransferSign(kid->Dtyp(), kid->Dsctyp()));
00136 wn = Gen_exp_wn(kid, emitter);
00137 kid->Set_dtyp(mtype_d);
00138 kid->Set_dsctyp(mtype_dsc);
00139 connect_cr_to_wn = FALSE;
00140 #ifdef TARG_X8664 // bug 9680: avoid add/sub in V16F4
00141 } else if (Roundoff_Level >= ROUNDOFF_ASSOC &&
00142 exp->Dsctyp() == MTYPE_V8F4 &&
00143 exp->Dtyp() == MTYPE_V16F8 &&
00144 kid->Kind() == CK_OP &&
00145 (kid->Opr() == OPR_ADD || kid->Opr() == OPR_SUB)) {
00146 wn = Gen_exp_wn(kid, emitter);
00147 WN_kid0(wn) = WN_CreateExp1(exp->Op(), WN_kid0(wn));
00148 WN_kid1(wn) = WN_CreateExp1(exp->Op(), WN_kid1(wn));
00149 WN_set_rtype(wn, MTYPE_V16F8);
00150 connect_cr_to_wn = FALSE;
00151 #endif
00152 } else {
00153 WN* wn_kid = Gen_exp_wn(kid, emitter);
00154 BOOL enabled = WN_Simplifier_Enable(TRUE);
00155 wn = WN_CreateExp1(exp->Op(), wn_kid);
00156 WN_Simplifier_Enable(enabled);
00157 if (WN_opcode(wn) != exp->Op()) {
00158 connect_cr_to_wn = FALSE;
00159 }
00160 }
00161
00162 } else if (cvt_kind == NOT_AT_ALL) {
00163 wn = Gen_exp_wn(kid, emitter);
00164 connect_cr_to_wn = FALSE;
00165 } else
00166 Is_True(FALSE, ("Gen_exp_wn: Bad type sequence"));
00167 break;
00168 } else {
00169 WN *opnd = Gen_exp_wn(exp->Get_opnd(0), emitter);
00170 INT cvt_kind;
00171 OPCODE opc;
00172
00173 cvt_kind =
00174 Need_type_conversion(exp->Dsctyp(), exp->Dtyp(), &opc);
00175 if (cvt_kind == NEED_CVT)
00176 wn = WN_CreateExp1(exp->Op(), opnd);
00177 else if (cvt_kind == NOT_AT_ALL) {
00178 wn = opnd;
00179 connect_cr_to_wn = FALSE;
00180 }
00181 else
00182 Is_True(FALSE, ("Gen_exp_wn: Bad type sequence"));
00183 break;
00184 }
00185 }
00186 case OPR_CVTL:
00187 {
00188 if (WOPT_Enable_Cvt_Folding && ! emitter->For_preopt()) {
00189 CODEREP *kid = exp->Get_opnd(0);
00190 WN *opnd;
00191 actual_type = Actual_cvtl_type(exp->Op(), exp->Offset());
00192
00193 if ((kid->Kind() == CK_VAR && !kid->Is_var_volatile() &&
00194 ST_class(emitter->Opt_stab()->Aux_stab_entry(kid->Aux_id())
00195 ->St()) != CLASS_PREG)
00196 ||
00197 (kid->Kind() == CK_IVAR &&
00198 OPERATOR_is_scalar_iload (kid->Opr()) &&
00199 !kid->Is_ivar_volatile())) {
00200 actual_opnd_type = kid->Dsctyp();
00201 if (MTYPE_is_integral(actual_opnd_type) &&
00202 MTYPE_is_integral(exp->Dtyp()) &&
00203 ! (Only_Unsigned_64_Bit_Ops && MTYPE_signed(exp->Dtyp()))) {
00204 if (MTYPE_size_min(actual_opnd_type)<MTYPE_size_min(MTYPE_I4) &&
00205 MTYPE_size_min(actual_type)==MTYPE_size_min(actual_opnd_type)) {
00206 MTYPE mtype_d = kid->Dtyp();
00207 MTYPE mtype_dsc = kid->Dsctyp();
00208 kid->Set_dtyp(exp->Dtyp());
00209 kid->Set_dsctyp(Mtype_TransferSign(exp->Dtyp(), kid->Dsctyp()));
00210 wn = Gen_exp_wn(kid, emitter);
00211 kid->Set_dtyp(mtype_d);
00212 kid->Set_dsctyp(mtype_dsc);
00213 connect_cr_to_wn = FALSE;
00214 break;
00215 } else if (MTYPE_size_min(actual_opnd_type) >= MTYPE_size_min(actual_type) &&
00216 MTYPE_size_min(actual_type) < MTYPE_size_min(MTYPE_I4)) {
00217 INT64 offset1 = MTYPE_size_min(actual_opnd_type) >> 3;
00218 INT64 offset2 = MTYPE_size_min(actual_type) >> 3;
00219 INT32 offset_old = kid->Offset();
00220 INT32 offset_new = offset_old;
00221
00222 if (Target_Byte_Sex == BIG_ENDIAN)
00223 offset_new = offset1 - offset2 + offset_old;
00224 if ( offset_new <= 0x8fffffff ) {
00225 kid->Set_offset( offset_new );
00226 MTYPE mtype_d = kid->Dtyp();
00227 MTYPE mtype_dsc = kid->Dsctyp();
00228 kid->Set_dtyp(exp->Dtyp());
00229 kid->Set_dsctyp(actual_type);
00230 wn = Gen_exp_wn(kid, emitter);
00231 kid->Set_offset( offset_old );
00232 kid->Set_dtyp(mtype_d);
00233 kid->Set_dsctyp(mtype_dsc);
00234 connect_cr_to_wn = FALSE;
00235 break;
00236 }
00237 }
00238 }
00239 opnd = Gen_exp_wn(kid, emitter);
00240 }
00241 else {
00242 opnd = Gen_exp_wn(kid, emitter);
00243 actual_opnd_type = Actual_result_type(opnd);
00244 }
00245
00246 if (WN_operator(opnd) == OPR_INTCONST) {
00247 MTYPE new_type =
00248 Adjust_signed_type(OPCODE_rtype(exp->Op()), exp->Offset(), opnd);
00249 if (new_type) actual_type = new_type;
00250 }
00251
00252 #if 0 // the analysis in No_truncation_by_value_size assumes state
00253
00254 if (actual_type == actual_opnd_type ||
00255 (WOPT_Enable_Min_Type &&
00256 kid->Kind() == CK_VAR &&
00257 MTYPE_is_integral( actual_opnd_type ) &&
00258 No_truncation_by_value_size(actual_type,
00259 MTYPE_is_signed(actual_type),
00260 kid, emitter->Opt_stab() )
00261 )
00262 ) {
00263 wn = opnd;
00264 connect_cr_to_wn = FALSE;
00265 } else
00266 #endif
00267 {
00268 BOOL enabled = WN_Simplifier_Enable(TRUE);
00269 wn = WN_CreateCvtl(exp->Op(), (INT16)exp->Offset(), opnd);
00270 WN_Simplifier_Enable(enabled);
00271 if (WN_opcode(wn) != exp->Op() ||
00272 WN_cvtl_bits(wn) != exp->Offset()) {
00273 connect_cr_to_wn = FALSE;
00274 }
00275 }
00276
00277 break;
00278
00279 } else {
00280 WN *opnd = Gen_exp_wn(exp->Get_opnd(0), emitter);
00281 actual_type = Actual_cvtl_type(exp->Op(), exp->Offset());
00282 actual_opnd_type = Actual_result_type(opnd);
00283
00284 if (exp->Get_opnd(0)->Kind() == CK_VAR ||
00285 (exp->Get_opnd(0)->Kind() == CK_IVAR &&
00286 OPERATOR_is_scalar_iload (exp->Get_opnd(0)->Opr())))
00287 actual_opnd_type = exp->Get_opnd(0)->Dsctyp();
00288
00289 if (WN_operator(opnd) == OPR_INTCONST) {
00290 MTYPE new_type =
00291 Adjust_signed_type(OPCODE_rtype(exp->Op()),exp->Offset(),opnd);
00292 if (new_type) actual_type = new_type;
00293 }
00294
00295 if (actual_type != actual_opnd_type)
00296 wn = WN_CreateCvtl(exp->Op(), (INT16)exp->Offset(), opnd);
00297 else {
00298 wn = opnd;
00299 connect_cr_to_wn = FALSE;
00300 }
00301 break;
00302 }
00303 }
00304
00305 case OPR_EXTRACT_BITS:
00306 case OPR_COMPOSE_BITS:
00307 {
00308 wn = WN_Create(exp->Op(), exp->Kid_count());
00309 WN_set_bit_offset_size(wn,exp->Op_bit_offset(),exp->Op_bit_size());
00310 for (INT i = 0; i < exp->Kid_count(); i++) {
00311 CODEREP *opnd = exp->Get_opnd(i);
00312 WN_kid(wn, i) = Gen_exp_wn(opnd, emitter);
00313 }
00314 }
00315 break;
00316
00317 case OPR_ARRAY:
00318 case OPR_CALL:
00319 case OPR_ICALL:
00320 case OPR_INTRINSIC_CALL:
00321 case OPR_INTRINSIC_OP:
00322 case OPR_FORWARD_BARRIER:
00323 case OPR_BACKWARD_BARRIER:
00324 case OPR_DEALLOCA:
00325 #ifdef KEY
00326 case OPR_PURE_CALL_OP:
00327 #endif
00328 {
00329 wn = WN_Create(exp->Op(), exp->Kid_count());
00330 if (opr == OPR_ARRAY) {
00331 WN_element_size(wn) = exp->Elm_siz();
00332 }
00333 else if ( opr == OPR_INTRINSIC_CALL || opr == OPR_INTRINSIC_OP ) {
00334 WN_intrinsic(wn) = exp->Intrinsic();
00335 }
00336 #ifdef KEY
00337 else if ( opr == OPR_PURE_CALL_OP ) {
00338 WN_st_idx (wn) = exp->Call_op_aux_id();
00339 }
00340 #endif
00341
00342 for (INT i = 0; i < exp->Kid_count(); i++) {
00343 CODEREP *opnd = exp->Get_opnd(i);
00344 WN_kid(wn, i) = Gen_exp_wn(opnd, emitter);
00345 }
00346 }
00347 break;
00348
00349 case OPR_ASM_STMT:
00350 {
00351 wn = WN_Create(exp->Op(), exp->Kid_count() + 2);
00352 for (INT i = 0; i < exp->Kid_count(); ++i) {
00353 CODEREP *opnd = exp->Get_opnd(i);
00354 WN_kid(wn, i + 2) = Gen_exp_wn(opnd, emitter);
00355 }
00356 }
00357 break;
00358
00359 case OPR_ASM_INPUT:
00360 {
00361 wn = WN_Create(exp->Op(), exp->Kid_count());
00362 WN_asm_opnd_num(wn) = exp->Asm_opnd_num();
00363 WN_st_idx(wn) = exp->Asm_constraint();
00364 for (INT i = 0; i < exp->Kid_count(); ++i) {
00365 CODEREP *opnd = exp->Get_opnd(i);
00366 WN_kid(wn, i) = Gen_exp_wn(opnd, emitter);
00367 #ifdef KEY
00368 if (opnd->Kind() == CK_OP){
00369 if (opnd->Opr() == OPR_CVT){
00370 TYPE_ID ty = exp->Asm_input_dsctype();
00371
00372 if (ty == MTYPE_I1 || ty == MTYPE_I2 || ty == MTYPE_U1 || ty == MTYPE_U2)
00373 WN_kid(wn, i) = WN_Int_Type_Conversion( WN_kid(WN_kid(wn, i),0), ty );
00374 else if (
00375 #if 1
00376 ! MTYPE_is_float(exp->Asm_input_rtype()) &&
00377 #endif
00378 exp->Asm_input_rtype() != exp->Asm_input_dsctype()) {
00379 WN_set_rtype(WN_kid(wn, i), exp->Asm_input_rtype());
00380 WN_set_desc(WN_kid(wn, i), exp->Asm_input_dsctype());
00381 }
00382 }
00383 else{
00384 WN_set_rtype(WN_kid(wn, i), exp->Asm_input_rtype());
00385 if (WN_desc(WN_kid(wn, i)) != MTYPE_V &&
00386 exp->Asm_input_rtype() != exp->Asm_input_dsctype())
00387 WN_set_desc(WN_kid(wn, i), exp->Asm_input_dsctype());
00388 }
00389 }
00390 else{
00391 #ifdef TARG_NVISA
00392
00393
00394
00395
00396 if (Mtype_TransferSign(WN_rtype(WN_kid(wn,i)),
00397 exp->Asm_input_rtype())
00398 == WN_rtype(WN_kid(wn,i)))
00399 {
00400 continue;
00401 }
00402 #endif //TARG_NVISA
00403 WN_set_rtype(WN_kid(wn, i), exp->Asm_input_rtype());
00404
00405 if (! MTYPE_is_float(exp->Asm_input_rtype()) &&
00406 (opnd->Kind() == CK_VAR || opnd->Kind() == CK_IVAR))
00407
00408 WN_set_desc(WN_kid(wn, i), Mtype_TransferSign(exp->Asm_input_rtype(), exp->Asm_input_dsctype()));
00409 }
00410 #endif
00411 }
00412 }
00413 break;
00414
00415 case OPR_TAS:
00416 wn = WN_Tas(exp->Dtyp(),
00417 exp->Ty_index(),
00418 Gen_exp_wn(exp->Get_opnd(0), emitter));
00419 #ifdef TARG_X8664 // bug 11752: make sure operand type has same size
00420 if (MTYPE_byte_size(WN_rtype(wn)) > MTYPE_byte_size(WN_rtype(WN_kid0(wn))) &&
00421 WN_operator(WN_kid0(wn)) == OPR_INTCONST)
00422 WN_set_rtype(WN_kid0(wn), Mtype_TransferSize(MTYPE_I8, WN_rtype(WN_kid0(wn))));
00423 #endif
00424
00425
00426 if ( WOPT_Enable_Combine_Operations ) {
00427 WN *combined_operation;
00428 if ( Uncombine_Operations( wn, &combined_operation ) ) {
00429 wn = combined_operation;
00430 }
00431 }
00432 break;
00433
00434 default:
00435 {
00436 STMTREP *proj_defstmt;
00437 if (Projection_operation(exp->Op()) &&
00438 exp->Opnd(0)->Kind() == CK_VAR) {
00439 proj_defstmt = Proj_defstmt(exp->Opnd(0),
00440 emitter->Opt_stab());
00441 }
00442 else {
00443 proj_defstmt = NULL;
00444 }
00445 if (proj_defstmt != NULL &&
00446 Stores_proj_op_to_temp(proj_defstmt,
00447 emitter->Opt_stab()) &&
00448 proj_defstmt->Proj_op_uses() == 1) {
00449
00450
00451
00452
00453 wn = WN_CreateExp1(exp->Op(),
00454 Gen_exp_wn(exp->Opnd(0)->Defstmt()->Rhs(),
00455 emitter));
00456 }
00457 else if (exp->Kid_count() == 0) {
00458 wn = WN_CreateExp0(exp->Op());
00459 } else if (exp->Kid_count() == 1) {
00460 wn = WN_CreateExp1(exp->Op(),
00461 Gen_exp_wn(exp->Get_opnd(0), emitter));
00462 } else if (exp->Kid_count() == 2) {
00463 WN *opnd0 = Gen_exp_wn(exp->Get_opnd(0), emitter);
00464 WN *opnd1 = Gen_exp_wn(exp->Get_opnd(1), emitter);
00465 #ifdef KEY // make the desc type of the comparison smaller if possible
00466 if (MTYPE_byte_size(WN_rtype(opnd0))==MTYPE_byte_size(WN_rtype(opnd1))
00467 && MTYPE_byte_size(WN_rtype(opnd0))< MTYPE_byte_size(exp->Dsctyp())
00468 && OPERATOR_is_compare(exp->Opr()))
00469 exp->Set_dsctyp(WN_rtype(opnd0));
00470 #endif
00471 #ifdef KEY // bug 13230: fix INTCONSTs kids of compare unnecessarily made 64-bit
00472 else if (OPERATOR_is_compare(exp->Opr()) &&
00473 MTYPE_byte_size(exp->Dsctyp()) == 4) {
00474 if (WN_operator(opnd0) == OPR_INTCONST &&
00475 MTYPE_byte_size(WN_rtype(opnd0)) == 8)
00476 WN_set_rtype(opnd0, Mtype_TransferSize(exp->Dsctyp(), WN_rtype(opnd0)));
00477 if (WN_operator(opnd1) == OPR_INTCONST &&
00478 MTYPE_byte_size(WN_rtype(opnd1)) == 8)
00479 WN_set_rtype(opnd1, Mtype_TransferSize(exp->Dsctyp(), WN_rtype(opnd1)));
00480 }
00481 #endif
00482 #ifdef KEY // bug 3347: fix INTCONSTs unnecessarily made 64-bit
00483 else if (! OPERATOR_is_compare(exp->Opr()) &&
00484 MTYPE_byte_size(exp->Dtyp()) == 4) {
00485 if (WN_operator(opnd0) == OPR_INTCONST &&
00486 MTYPE_byte_size(WN_rtype(opnd0)) == 8) {
00487 #if 0
00488 Is_True(( WN_const_val(opnd0) << 32 >> 32) == WN_const_val(opnd0),
00489 ("Inconsistent INTCONST type"));
00490 #else
00491 if ((WN_const_val(opnd0) << 32 >> 32) == WN_const_val(opnd0))
00492 WN_set_rtype(opnd0, Mtype_TransferSize(exp->Dtyp(), WN_rtype(opnd0)));
00493 #endif
00494 }
00495 if (WN_operator(opnd1) == OPR_INTCONST &&
00496 MTYPE_byte_size(WN_rtype(opnd1)) == 8) {
00497 #if 0 // umlau6.f of sixtrack hits this assertion
00498 Is_True((WN_const_val(opnd1) << 32 >> 32) == WN_const_val(opnd1),
00499 ("Inconsistent INTCONST type"));
00500 #else
00501 if ((WN_const_val(opnd1) << 32 >> 32) == WN_const_val(opnd1))
00502 WN_set_rtype(opnd1, Mtype_TransferSize(exp->Dtyp(), WN_rtype(opnd1)));
00503 #endif
00504 }
00505 if (OPCODE_is_load(WN_opcode(opnd0)) &&
00506 MTYPE_byte_size(WN_rtype(opnd0)) == 8 &&
00507 MTYPE_byte_size(WN_desc(opnd0)) == 4) {
00508 WN_set_rtype(opnd0, Mtype_TransferSize(exp->Dtyp(), WN_rtype(opnd0)));
00509 }
00510 if (OPCODE_is_load(WN_opcode(opnd1)) &&
00511 MTYPE_byte_size(WN_rtype(opnd1)) == 8 &&
00512 MTYPE_byte_size(WN_desc(opnd1)) == 4) {
00513 WN_set_rtype(opnd1, Mtype_TransferSize(exp->Dtyp(), WN_rtype(opnd1)));
00514 }
00515 }
00516 else if ((exp->Opr() == OPR_MPY ||
00517 MTYPE_signed(exp->Dtyp()) &&
00518 (exp->Opr() == OPR_SUB || exp->Opr() == OPR_ADD)) &&
00519 MTYPE_byte_size(exp->Dtyp()) == 8 &&
00520 (MTYPE_byte_size(exp->Dtyp()) != MTYPE_byte_size(WN_rtype(opnd0)) ||
00521 MTYPE_byte_size(exp->Dtyp()) != MTYPE_byte_size(WN_rtype(opnd1))))
00522 {
00523 if (WN_operator(opnd0) != OPR_INTCONST)
00524 if (MTYPE_byte_size(WN_rtype(opnd0)) != 8) {
00525 #ifdef TARG_X8664 // bug 11599
00526 if (WN_operator(opnd0) == OPR_SUB)
00527 opnd0 = WN_Cvt(MTYPE_I4, exp->Dtyp(), opnd0);
00528 else
00529 #endif
00530 opnd0 = WN_Cvt(WN_rtype(opnd0), exp->Dtyp(), opnd0);
00531 }
00532 if (WN_operator(opnd1) != OPR_INTCONST)
00533 if (MTYPE_byte_size(WN_rtype(opnd1)) != 8) {
00534 #ifdef TARG_X8664 // bug 11599
00535 if (WN_operator(opnd1) == OPR_SUB)
00536 opnd1 = WN_Cvt(MTYPE_I4, exp->Dtyp(), opnd1);
00537 else
00538 #endif
00539 opnd1 = WN_Cvt(WN_rtype(opnd1), exp->Dtyp(), opnd1);
00540 }
00541 }
00542 #endif
00543 wn = WN_CreateExp2(exp->Op(), opnd0, opnd1);
00544 } else if (exp->Kid_count() == 3) {
00545 WN *opnd0 = Gen_exp_wn(exp->Get_opnd(0), emitter);
00546 WN *opnd1 = Gen_exp_wn(exp->Get_opnd(1), emitter);
00547 WN *opnd2 = Gen_exp_wn(exp->Get_opnd(2), emitter);
00548 wn = WN_CreateExp3(exp->Op(), opnd0, opnd1, opnd2);
00549 } else {
00550 Is_True(FALSE, ("Kid count > 3."));
00551 }
00552
00553
00554 if ( WOPT_Enable_Combine_Operations ) {
00555 WN *combined_operation;
00556 if ( Uncombine_Operations( wn, &combined_operation ) ) {
00557 wn = combined_operation;
00558 }
00559 }
00560
00561 }
00562 break;
00563 }
00564 break;
00565 case CK_IVAR:
00566 if (exp->Opr() == OPR_MLOAD) {
00567 CODEREP *num_byte = exp->Mload_size();
00568 WN *kid0 = Gen_exp_wn(exp->Ilod_base(), emitter);
00569 WN *kid1 = Gen_exp_wn(num_byte, emitter);
00570 wn = WN_CreateMload(exp->Offset(), exp->Ilod_ty(), kid0, kid1);
00571 emitter->Alias_Mgr()->Gen_alias_id(wn, exp->Points_to(emitter->Opt_stab()));
00572 WN_set_field_id (wn, exp->I_field_id());
00573 }
00574 else if ( exp->Opr() == OPR_PARM ) {
00575 wn = Gen_exp_wn(exp->Ilod_base(), emitter);
00576 #ifdef KEY // bug 12161: fix INTCONSTs unnecessarily made 64-bit
00577 if (WN_operator(wn) == OPR_INTCONST && MTYPE_byte_size(WN_rtype(wn)) == 8
00578 && MTYPE_byte_size(exp->Dtyp()) == 4) {
00579 if ((WN_const_val(wn) << 32 >> 32) == WN_const_val(wn))
00580 WN_set_rtype(wn, Mtype_TransferSize(exp->Dtyp(), WN_rtype(wn)));
00581 }
00582 #endif
00583 wn = WN_CreateParm(exp->Dtyp(), wn, exp->Ilod_ty(), exp->Offset());
00584 #if defined(TARG_SL)
00585
00586 if (WN_Parm_By_Reference(wn) || WN_Parm_Dereference(wn)) {
00587 #else
00588 if (WN_Parm_By_Reference(wn)) {
00589 #endif
00590 POINTS_TO *pt = exp->Points_to(emitter->Opt_stab());
00591 Is_True(pt != NULL, ("Reference parameter has NULL POINTS_TO."));
00592 emitter->Alias_Mgr()->Gen_alias_id(wn, pt);
00593 }
00594 #ifdef KEY // bug 7766
00595 else if (IS_FORTRAN && exp->Ilod_base()->Kind() == CK_LDA &&
00596 ! exp->Ilod_base()->Is_flag_set(CF_LDA_LABEL) &&
00597 ! WN_Parm_By_Reference(wn)) {
00598 WN_Set_Parm_By_Reference(wn);
00599 Set_ST_addr_passed(exp->Ilod_base()->Lda_base_st());
00600 AUX_ID vp_idx = exp->Ilod_base()->Lda_aux_id();
00601 emitter->Alias_Mgr()->Gen_alias_id(wn, emitter->Opt_stab()->Points_to(vp_idx));
00602 MU_NODE *mnode = CXX_NEW(MU_NODE, emitter->Mem_pool());
00603 mnode->Init(vp_idx);
00604 mnode->Set_OPND(emitter->Htable()->Ssa()->Get_zero_version_CR(vp_idx, emitter->Opt_stab(), 0));
00605 exp->Set_ivar_mu_node(mnode);
00606 }
00607 #endif
00608 }
00609 else if ( exp->Opr() == OPR_ILOADX ) {
00610 WN *kid0 = Gen_exp_wn(exp->Ilod_base(), emitter);
00611 WN *kid1 = Gen_exp_wn(exp->Index(), emitter);
00612 wn = WN_CreateIloadx(exp->Op(), exp->Ilod_ty(), exp->Ilod_base_ty(), kid0, kid1);
00613 emitter->Alias_Mgr()->Gen_alias_id(wn, exp->Points_to(emitter->Opt_stab()));
00614 if (emitter->Gen_lno_info())
00615 WN_add_lno_info(wn, exp);
00616 }
00617 else {
00618 WN *kid0 = Gen_exp_wn(exp->Ilod_base(), emitter);
00619
00620 wn = WN_CreateIload (exp->Opr(), exp->Dtyp(), exp->Dsctyp(),
00621 exp->Offset(), exp->Ilod_ty(),
00622 exp->Ilod_base_ty(), kid0, exp->I_field_id());
00623 if (exp->Opr() == OPR_ILDBITS)
00624 WN_set_bit_offset_size (wn, exp->I_bit_offset(), exp->I_bit_size());
00625 emitter->Alias_Mgr()->Gen_alias_id(wn, exp->Points_to(emitter->Opt_stab()));
00626 if (emitter->Gen_lno_info())
00627 WN_add_lno_info(wn, exp);
00628 }
00629 break;
00630 case CK_LDA:
00631 if (exp->Is_flag_set(CF_LDA_LABEL)) {
00632 wn = WN_LdaLabel(exp->Dtyp(), exp->Offset());
00633 }
00634 else {
00635 wn = WN_CreateLda(OPR_LDA, exp->Dtyp(), MTYPE_V, exp->Offset(), exp->Lda_ty(), exp->Lda_base_st(), exp->Afield_id());
00636
00637
00638
00639
00640
00641
00642
00643 IDTYPE ip_alias_class = exp->Points_to(emitter->Opt_stab())->Ip_alias_class();
00644 if (ip_alias_class != OPTIMISTIC_AC_ID &&
00645 ip_alias_class != PESSIMISTIC_AC_ID) {
00646 WN_MAP32_Set(WN_MAP_ALIAS_CLASS, wn, ip_alias_class);
00647 }
00648 }
00649 break;
00650 case CK_VAR:
00651 {
00652 AUX_STAB_ENTRY *aux_entry =
00653 emitter->Opt_stab()->Aux_stab_entry(exp->Aux_id());
00654 #ifdef TARG_SL
00655 if (exp->Dtyp() == MTYPE_I2 && exp->Dsctyp() == MTYPE_I2) {
00656 wn = WN_Create((aux_entry->Bit_size() > 0 && aux_entry->Field_id() == 0)
00657 ? OPR_LDBITS : OPR_LDID,
00658 MTYPE_I4, exp->Dsctyp(), 0);
00659 } else
00660 #endif
00661 wn = WN_Create((aux_entry->Bit_size() > 0 && aux_entry->Field_id() == 0)
00662 ? OPR_LDBITS : OPR_LDID,
00663 exp->Dtyp(), exp->Dsctyp(), 0);
00664 TY_IDX ty_idx = exp->Lod_ty();
00665 Is_True(ty_idx, ("Gen_exp_wn: NULL Lod_ty() for CK_VAR node"));
00666 UINT16 field_id = exp->Field_id();
00667 ST* st = aux_entry->St();
00668
00669
00670 if (ST_class (st) == CLASS_PREG &&
00671 exp->Dsctyp() != MTYPE_M &&
00672 TY_size (ty_idx) != MTYPE_byte_size (exp->Dsctyp())) {
00673 BOOL reset_type = TRUE;
00674 if (field_id != 0 && TY_kind(ty_idx) == KIND_STRUCT) {
00675
00676 UINT cur_field_id = 0;
00677 FLD_HANDLE fld = FLD_get_to_field (ty_idx, field_id, cur_field_id);
00678 Is_True (! fld.Is_Null(), ("Invalid field id %d for type 0x%x",
00679 field_id, ty_idx));
00680 if (TY_size(FLD_type(fld)) == MTYPE_byte_size(exp->Dsctyp()))
00681 reset_type = FALSE;
00682 }
00683 if (reset_type) {
00684 DevWarn("PREG (%s) has mismatching MTYPE-size and TY-size; refer to bug #567932",
00685 ST_name(st));
00686 Set_TY_IDX_index (ty_idx,
00687 TY_IDX_index(MTYPE_To_TY (exp->Dsctyp())));
00688 field_id = 0;
00689 }
00690 }
00691 WN_set_ty(wn, ty_idx);
00692 WN_st_idx(wn) = ST_st_idx(st);
00693 if (aux_entry->Bit_size() > 0 && aux_entry->Field_id() == 0)
00694 WN_set_bit_offset_size (wn, exp->Bit_offset(), exp->Bit_size());
00695 else
00696 WN_set_field_id (wn, field_id);
00697
00698 if (aux_entry->Is_non_dedicated_preg() &&
00699 exp->Safe_to_renumber_preg()) {
00700 IDTYPE new_preg_num =
00701 emitter->Preg_renumbering_map().Lookup(exp->Coderep_id());
00702 if (new_preg_num == 0) {
00703 if (!aux_entry->Some_version_renumbered()) {
00704
00705
00706 aux_entry->Set_some_version_renumbered();
00707 new_preg_num = exp->Offset();
00708 }
00709 else {
00710
00711 new_preg_num =
00712 emitter->Opt_stab()->Alloc_preg(exp->Dtyp(),
00713 "renumbered PREG",
00714 NULL);
00715 }
00716 emitter->Preg_renumbering_map().Insert(exp->Coderep_id(),
00717 new_preg_num);
00718 }
00719 WN_load_offset(wn) = new_preg_num;
00720 }
00721 else {
00722 WN_load_offset(wn) = exp->Offset();
00723 }
00724 emitter->Alias_Mgr()->Gen_alias_id(wn, exp->Points_to(emitter->Opt_stab()));
00725
00726 if (ST_class(aux_entry->St()) != CLASS_PREG && aux_entry->Home_sym() != 0)
00727 {
00728 AUX_STAB_ENTRY *preg_entry =
00729 emitter->Opt_stab()->Aux_stab_entry(aux_entry->Home_sym());
00730 Is_True(ST_class(preg_entry->St()) == CLASS_PREG,
00731 ("Gen_exp_wn: home preg is not a preg"));
00732 WN *preg_home = Preg_Home(preg_entry->St_ofst());
00733 if (preg_home) {
00734 Copy_alias_info(emitter->Alias_Mgr(), wn, preg_home);
00735 }
00736 }
00737 }
00738 break;
00739 case CK_CONST:
00740 op = OPCODE_make_op(OPR_INTCONST, exp->Dtyp(), MTYPE_V);
00741 wn = WN_Create(op, 0);
00742 WN_const_val(wn) = exp->Const_val();
00743 break;
00744 case CK_RCONST:
00745 op = OPCODE_make_op(OPR_CONST, exp->Dtyp(), MTYPE_V);
00746 wn = WN_Create(op, 0);
00747 WN_st_idx(wn) = ST_st_idx(exp->Const_id());
00748 break;
00749 default:
00750 Warn_todo("Gen_exp_wn: CODEKIND is not implemented yet");
00751 break;
00752 }
00753
00754 #if defined(TARG_SL)
00755
00756 if (exp->Is_flag_set(CF_INTERNAL_MEM_OFFSET)) {
00757 WN_Set_is_internal_mem_ofst(wn);
00758 }
00759
00760 extern INT Need_type_conversion(TYPE_ID from_ty, TYPE_ID to_ty, OPCODE *opc);
00761
00762 OPERATOR opr_t = WN_operator(wn);
00763 TYPE_ID from_ty = WN_desc(wn);
00764 TYPE_ID to_ty = WN_rtype(wn);
00765 OPCODE opc = WN_opcode(wn);
00766
00767 if ((opr_t == OPR_CVT) && (Need_type_conversion(from_ty, to_ty, &opc) == NOT_AT_ALL) && WN_kid0(wn))
00768 wn = WN_kid0(wn);
00769 #endif
00770
00771
00772 if ( emitter->Wn_to_cr_map() && connect_cr_to_wn )
00773 Connect_cr_wn( emitter->Wn_to_cr_map(), exp, wn );
00774
00775
00776
00777 if ( emitter->Do_rvi() ) {
00778 if ( exp->Kind() == CK_VAR && ST_class(WN_st(wn)) != CLASS_PREG ) {
00779 Warn_todo( "CODEREP::Gen_wn: do not adjust bitpos by 1" );
00780 emitter->Rvi()->Map_bitpos( wn, exp->Bitpos()+1 );
00781 }
00782 if ( exp->Kind() == CK_IVAR && exp->Ivar_mu_node() != NULL )
00783 emitter->Rvi()->Map_mu_node( wn, exp->Ivar_mu_node() );
00784 }
00785
00786 return wn;
00787 }
00788
00789
00790 template < class EMITTER >WN *
00791 Gen_stmt_wn(STMTREP *srep, STMT_CONTAINER *stmt_container, EMITTER *emitter)
00792 {
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804 WN *rwn = NULL;
00805 WN *rhs_wn = NULL;
00806 WN *base_wn = NULL;
00807 WN *index_wn = NULL;
00808 OPCODE opcode, opc;
00809
00810 switch (srep->Opr()) {
00811 case OPR_GOTO:
00812 rwn = WN_CreateGoto( srep->St(), srep->Label_number() );
00813 break;
00814
00815 case OPR_REGION_EXIT:
00816 rwn = WN_CreateRegionExit( srep->St(), srep->Label_number() );
00817
00818
00819
00820
00821
00822
00823
00824 break;
00825
00826 case OPR_AGOTO:
00827
00828
00829 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
00830 rwn = WN_CreateAgoto(rhs_wn);
00831 break;
00832 case OPR_FALSEBR:
00833 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
00834 rwn = WN_CreateFalsebr(srep->Label_number(), rhs_wn);
00835 break;
00836 case OPR_TRUEBR:
00837 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
00838 rwn = WN_CreateTruebr(srep->Label_number(), rhs_wn);
00839 break;
00840 case OPR_COMPGOTO:
00841 Is_True( srep->Bb()->Switchinfo() != NULL,
00842 ("BB:%d has COMPGOTO, but no switchinfo", srep->Bb()->Id()) );
00843 {
00844 WN *default_wn = NULL;
00845 INT32 num_entries = srep->Bb()->Switchentries();
00846 WN *block_wn = WN_CreateBlock();
00847
00848
00849 for (INT32 num_entry = num_entries-1; num_entry >= 0; num_entry--) {
00850 WN_INSERT_BlockAfter( block_wn, NULL,
00851 WN_CreateGoto((ST_IDX) NULL,
00852 srep->Bb()->Switchcase(num_entry)->Labnam() ) );
00853 }
00854
00855
00856 if ( srep->Bb()->Switchdefault() != NULL ) {
00857 default_wn =
00858 WN_CreateGoto((ST_IDX) NULL, srep->Bb()->Switchdefault()->Labnam());
00859 }
00860 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
00861 rwn = WN_CreateCompgoto(num_entries, rhs_wn, block_wn, default_wn, 0);
00862 }
00863 #ifdef TARG_SL //fork_joint
00864 if (srep->Fork_stmt_flags())
00865 WN_Set_is_compgoto_para(rwn);
00866 else if(srep->Minor_fork_stmt_flags())
00867 WN_Set_is_compgoto_for_minor(rwn);
00868 #endif
00869 break;
00870
00871 case OPR_ASM_STMT:
00872 {
00873
00874
00875
00876 rwn = Gen_exp_wn(srep->Rhs(), emitter);
00877 WN_st_idx(rwn) = srep->Asm_string_idx();
00878 WN_asm_flag(rwn) = srep->Asm_stmt_flags();
00879
00880 WN *clobber_block = WN_CreateBlock();
00881
00882 vector<CLOBBER_PRAGMA_INFO,
00883 mempool_allocator<CLOBBER_PRAGMA_INFO> >::const_iterator p;
00884 for (p = srep->Asm_pragma()->clobber_info.begin();
00885 p != srep->Asm_pragma()->clobber_info.end();
00886 ++p) {
00887 WN *prag;
00888 if (p->preg_st_idx == (ST_IDX) 0) {
00889 prag = WN_CreatePragma(WN_PRAGMA_ASM_CLOBBER,
00890 (ST_IDX) 0,
00891 p->clobber_string_idx,
00892 0);
00893 }
00894 else {
00895
00896 prag = WN_CreateXpragma(WN_PRAGMA_ASM_CLOBBER,
00897 (ST_IDX) p->clobber_string_idx,
00898 1);
00899 WN_kid0(prag) = WN_CreateIdname(p->preg_number,
00900 p->preg_st_idx);
00901 if(WN_kid0(prag) == 0)
00902 WN_pragma_arg2(prag) = p->clobber_string_idx;
00903 }
00904 WN_INSERT_BlockAfter(clobber_block,
00905 WN_last (clobber_block),
00906 prag);
00907 }
00908 WN_asm_clobbers(rwn) = clobber_block;
00909
00910 WN *output_constraint_block = WN_CreateBlock();
00911
00912 vector<CONSTRAINT_PRAGMA_INFO,
00913 mempool_allocator<CONSTRAINT_PRAGMA_INFO> >::const_iterator q;
00914 for (q = srep->Asm_pragma()->constraint_info.begin();
00915 q != srep->Asm_pragma()->constraint_info.end();
00916 ++q) {
00917 WN *prag = WN_CreatePragma(WN_PRAGMA_ASM_CONSTRAINT,
00918 emitter->Opt_stab()->St(q->preg_st_idx),
00919 (INT32) q->constraint_st_idx,
00920 q->asm_neg_preg,
00921 q->asm_opnd_num);
00922 WN_INSERT_BlockAfter(output_constraint_block,
00923 WN_last(output_constraint_block),
00924 prag);
00925 }
00926 WN_asm_constraints(rwn) = output_constraint_block;
00927 }
00928 break;
00929
00930 case OPR_CALL:
00931 case OPR_ICALL:
00932 case OPR_INTRINSIC_CALL:
00933 case OPR_FORWARD_BARRIER:
00934 case OPR_BACKWARD_BARRIER:
00935 case OPR_ALLOCA:
00936 case OPR_DEALLOCA:
00937
00938 {
00939 OPCODE opc = srep->Op();
00940 OPERATOR opr = OPCODE_operator(opc);
00941 rwn = Gen_exp_wn( srep->Rhs(), emitter );
00942 #ifdef KEY
00943
00944 if (WN_operator (rwn) == OPR_ICALL)
00945 {
00946 mINT16 kidcount = WN_kid_count (rwn);
00947 WN * kid = WN_kid (rwn, kidcount - 1 );
00948 if (WN_operator (kid) == OPR_LDA &&
00949 ST_class (WN_st (kid)) == CLASS_FUNC)
00950 {
00951 WN_set_operator (rwn, OPR_CALL);
00952 WN_st_idx (rwn) = ST_st_idx (WN_st (kid));
00953 WN_call_flag (rwn) = srep->Call_flags();
00954 WN_set_kid_count (rwn, kidcount - 1);
00955 WN_Delete (kid);
00956 break;
00957 }
00958 }
00959 #endif
00960 if (opr == OPR_ICALL)
00961 WN_set_ty(rwn, srep->Ty());
00962 if (OPCODE_is_call(opc))
00963 WN_call_flag(rwn) = srep->Call_flags();
00964 if (OPCODE_has_sym(opc))
00965 WN_st_idx(rwn) = ST_st_idx(srep->St());
00966 if (opr == OPR_FORWARD_BARRIER ||
00967 opr == OPR_BACKWARD_BARRIER ||
00968 opr == OPR_DEALLOCA)
00969 emitter->Alias_Mgr()->Gen_alias_id_list(rwn, srep->Pt_list());
00970 }
00971 break;
00972
00973 case OPR_STID:
00974 case OPR_STBITS:
00975 {
00976 if (Stores_proj_op_to_temp(srep, emitter->Opt_stab()) &&
00977 srep->Proj_op_uses() == 1) {
00978
00979
00980
00981 return NULL;
00982 }
00983 else {
00984
00985 CODEREP *rhs_cr = srep->Rhs();
00986 CODEREP *lhs = srep->Lhs();
00987
00988 if ( !emitter->For_preopt() &&
00989 WOPT_Enable_Cvt_Folding &&
00990 rhs_cr->Kind() == CK_OP &&
00991 ( rhs_cr->Opr() == OPR_CVT &&
00992 MTYPE_is_integral( rhs_cr->Dsctyp() )
00993 || rhs_cr->Opr() == OPR_CVTL ) &&
00994 MTYPE_is_integral( rhs_cr->Dtyp() ) &&
00995 MTYPE_is_integral( lhs->Dsctyp() )
00996 #ifdef TARG_X8664
00997 && ! MTYPE_is_vector(lhs->Dsctyp())
00998 #endif
00999 ) {
01000
01001 MTYPE actual_type;
01002 if (rhs_cr->Opr() == OPR_CVTL)
01003 actual_type = Actual_cvtl_type(rhs_cr->Op(),rhs_cr->Offset());
01004 else if (MTYPE_size_min(rhs_cr->Dsctyp()) <= MTYPE_size_min(rhs_cr->Dtyp()))
01005 actual_type = rhs_cr->Dsctyp();
01006 else
01007 actual_type = rhs_cr->Dtyp();
01008 if ( ST_class(emitter->Opt_stab()->St(lhs->Aux_id())) != CLASS_PREG
01009 && MTYPE_size_min(lhs->Dsctyp())<=MTYPE_size_min(actual_type) ) {
01010 rhs_cr = rhs_cr->Get_opnd(0);
01011 } else {
01012 FOLD ftmp;
01013 CODEREP *cr;
01014 cr = ftmp.Fold_Expr(rhs_cr);
01015 if (cr) rhs_cr = cr;
01016 }
01017 }
01018
01019
01020 rhs_wn = Gen_exp_wn( rhs_cr, emitter );
01021 opcode = OPCODE_make_op(srep->Opr(), MTYPE_V, lhs->Dsctyp());
01022 AUX_STAB_ENTRY *aux_entry =
01023 emitter->Opt_stab()->Aux_stab_entry(lhs->Aux_id());
01024 INT64 lhs_offset;
01025 if (aux_entry->Is_non_dedicated_preg() &&
01026 lhs->Safe_to_renumber_preg()) {
01027 lhs_offset =
01028 emitter->Preg_renumbering_map().Lookup(lhs->Coderep_id());
01029 if (lhs_offset == 0) {
01030 if (!aux_entry->Some_version_renumbered()) {
01031 aux_entry->Set_some_version_renumbered();
01032 lhs_offset = lhs->Offset();
01033 }
01034 else {
01035 lhs_offset =
01036 emitter->Opt_stab()->Alloc_preg(lhs->Dsctyp(),
01037 "renumbered PREG",
01038 NULL);
01039 }
01040 emitter->Preg_renumbering_map().Insert(lhs->Coderep_id(),
01041 (IDTYPE) lhs_offset);
01042 }
01043 }
01044 else {
01045 lhs_offset = lhs->Offset();
01046 }
01047 ST* st = emitter->Opt_stab()->St(lhs->Aux_id());
01048 TY_IDX ty_idx = lhs->Lod_ty();
01049 UINT16 field_id = lhs->Field_id();
01050
01051
01052 if (ST_class (st) == CLASS_PREG &&
01053 lhs->Dsctyp() != MTYPE_M &&
01054 TY_size(ty_idx) != MTYPE_byte_size (lhs->Dsctyp())) {
01055 Set_TY_IDX_index (ty_idx,
01056 TY_IDX_index(MTYPE_To_TY (lhs->Dsctyp())));
01057 field_id = 0;
01058 }
01059
01060 if (lhs->Dsctyp() == MTYPE_B && WN_rtype(rhs_wn) != MTYPE_B) {
01061 Is_True(WN_operator(rhs_wn) == OPR_INTCONST,
01062 ("Gen_stmt_wn: non-boolean value stored to boolean variable"));
01063 WN_set_rtype(rhs_wn, MTYPE_B);
01064 }
01065 #ifdef KEY
01066 if (OPERATOR_is_load(WN_operator(rhs_wn)) &&
01067 lhs->Dsctyp() != MTYPE_BS ) {
01068 if (MTYPE_byte_size(WN_rtype(rhs_wn)) <
01069 MTYPE_byte_size(lhs->Dsctyp())) {
01070 Is_True(MTYPE_is_integral(WN_rtype(rhs_wn)),
01071 ("Gen_stmt_wn: inconsistent sizes in float type assignment"));
01072 WN_set_rtype(rhs_wn, Mtype_TransferSize(lhs->Dsctyp(), WN_rtype(rhs_wn)));
01073 }
01074 else if (MTYPE_byte_size(WN_rtype(rhs_wn)) >
01075 MTYPE_byte_size(lhs->Dsctyp()) &&
01076 MTYPE_byte_size(WN_rtype(rhs_wn)) >
01077 MTYPE_byte_size(WN_desc(rhs_wn))) {
01078
01079 WN_set_rtype(rhs_wn, Mtype_TransferSize(MTYPE_I4, WN_rtype(rhs_wn)));
01080 }
01081 }
01082 #endif
01083 rwn = WN_CreateStid(opcode, lhs_offset, st, ty_idx, rhs_wn, field_id);
01084 if ( emitter->Do_rvi() ) {
01085 Warn_todo( "Gen_stmt_wn: do not adjust bitpos by 1" );
01086 emitter->Rvi()->Map_bitpos( rwn, lhs->Bitpos()+1 );
01087 }
01088 emitter->Alias_Mgr()->Gen_alias_id(rwn,
01089 lhs->Points_to(emitter->Opt_stab()));
01090 }
01091 }
01092 break;
01093 case OPR_PREFETCH:
01094 {
01095 WN *addr_wn = Gen_exp_wn( srep->Rhs()->Ilod_base(), emitter );
01096
01097
01098 rwn = srep->Prefetch_wn();
01099 WN_kid0(rwn) = addr_wn;
01100 WN_offset(rwn) = srep->Rhs()->Offset();
01101 break;
01102 }
01103
01104 case OPR_ISTORE:
01105 case OPR_ISTBITS:
01106 {
01107 if (!emitter->For_preopt() &&
01108 srep->Rhs()->Kind() == CK_IVAR &&
01109 srep->Rhs()->Ilod_base() == srep->Lhs()->Istr_base() &&
01110 srep->Rhs()->Offset() == srep->Lhs()->Offset() &&
01111 MTYPE_size_min(srep->Rhs()->Dsctyp()) == MTYPE_size_min(srep->Lhs()->Dsctyp()) &&
01112 !srep->Rhs()->Is_ivar_volatile() &&
01113 !srep->Lhs()->Is_ivar_volatile())
01114 return FALSE;
01115
01116 CODEREP *rhs_cr = srep->Rhs();
01117 CODEREP *lhs = srep->Lhs();
01118
01119 if (
01120 #ifndef KEY
01121 !emitter->For_preopt() &&
01122 #endif
01123 WOPT_Enable_Cvt_Folding &&
01124 rhs_cr->Kind() == CK_OP &&
01125 ( rhs_cr->Opr() == OPR_CVT &&
01126 MTYPE_is_integral( rhs_cr->Dsctyp() )
01127 #ifdef KEY
01128 && !MTYPE_is_vector( rhs_cr->Dsctyp() )
01129 && !MTYPE_is_vector( rhs_cr->Dtyp() )
01130 #endif
01131 || rhs_cr->Opr() == OPR_CVTL ) &&
01132 MTYPE_is_integral( rhs_cr->Dtyp() ) &&
01133 MTYPE_is_integral( lhs->Dsctyp() ) &&
01134 lhs->Dsctyp() != MTYPE_BS
01135 ) {
01136 MTYPE actual_type;
01137 if (rhs_cr->Opr() == OPR_CVTL)
01138 actual_type = Actual_cvtl_type(rhs_cr->Op(),rhs_cr->Offset());
01139 else if (MTYPE_size_min(rhs_cr->Dsctyp()) <= MTYPE_size_min(rhs_cr->Dtyp()))
01140 actual_type = rhs_cr->Dsctyp();
01141 else
01142 actual_type = rhs_cr->Dtyp();
01143 if ( MTYPE_size_min(lhs->Dsctyp()) <= MTYPE_size_min(actual_type) ) {
01144 rhs_cr = rhs_cr->Get_opnd(0);
01145 } else {
01146 FOLD ftmp;
01147 CODEREP *cr;
01148 cr = ftmp.Fold_Expr(rhs_cr);
01149 if (cr) rhs_cr = cr;
01150 }
01151 }
01152
01153
01154 rhs_wn = Gen_exp_wn( rhs_cr, emitter );
01155
01156 Is_True(lhs->Istr_base() != NULL,
01157 ("Gen_stmt_wn: istr_base has NULL lhs"));
01158 base_wn = Gen_exp_wn( lhs->Istr_base(), emitter );
01159 opcode = OPCODE_make_op(srep->Opr(), MTYPE_V, lhs->Dsctyp());
01160 rwn = WN_Create(opcode, 2);
01161 WN_kid0(rwn) = rhs_wn;
01162 WN_kid1(rwn) = base_wn;
01163 WN_store_offset(rwn) = lhs->Offset();
01164 WN_set_ty(rwn, lhs->Ilod_base_ty());
01165 WN_set_field_id(rwn, lhs->I_field_id());
01166 #if defined(TARG_SL)
01167
01168 if(srep->SL2_internal_mem_ofst())
01169 WN_Set_is_internal_mem_ofst(rwn);
01170 #endif
01171 #ifdef TARG_X8664 // bug 6910
01172 if (emitter->Htable()->Phase() != MAINOPT_PHASE &&
01173 WN_operator(rhs_wn) == OPR_INTCONST &&
01174 MTYPE_byte_size(WN_rtype(rhs_wn)) < MTYPE_byte_size(lhs->Dsctyp()) &&
01175 lhs->Dsctyp() != MTYPE_BS )
01176 WN_set_rtype(rhs_wn, Mtype_TransferSize(lhs->Dsctyp(), WN_rtype(rhs_wn)));
01177 #endif
01178 #ifdef TARG_X8664
01179 if (Is_Target_32bit() && MTYPE_byte_size(WN_rtype(rhs_wn)) == 8 &&
01180 WN_operator(rhs_wn) == OPR_INTCONST &&
01181 MTYPE_byte_size(lhs->Dsctyp()) < 8 &&
01182 lhs->Dsctyp() != MTYPE_BS )
01183 WN_set_rtype(rhs_wn, Mtype_TransferSize(MTYPE_I4, WN_rtype(rhs_wn)));
01184 #endif
01185 emitter->Alias_Mgr()->
01186 Gen_alias_id(rwn, lhs->Points_to(emitter->Opt_stab()));
01187 if (emitter->Gen_lno_info())
01188 WN_add_lno_info(rwn, lhs);
01189 break;
01190 }
01191
01192 case OPR_ISTOREX:
01193 {
01194 CODEREP *rhs_cr = srep->Rhs();
01195 CODEREP *lhs = srep->Lhs();
01196
01197 if ( !emitter->For_preopt() &&
01198 WOPT_Enable_Cvt_Folding &&
01199 rhs_cr->Kind() == CK_OP &&
01200 ( rhs_cr->Opr() == OPR_CVT &&
01201 MTYPE_is_integral( rhs_cr->Dsctyp() )
01202 || rhs_cr->Opr() == OPR_CVTL ) &&
01203 MTYPE_is_integral( rhs_cr->Dtyp() ) &&
01204 MTYPE_is_integral( lhs->Dsctyp() )
01205 ) {
01206 MTYPE actual_type = (rhs_cr->Opr() == OPR_CVT) ?
01207 rhs_cr->Dsctyp() : Actual_cvtl_type(rhs_cr->Op(),rhs_cr->Offset());
01208 if ( MTYPE_size_min(lhs->Dsctyp()) <= MTYPE_size_min(actual_type) ) {
01209 rhs_cr = rhs_cr->Get_opnd(0);
01210 } else {
01211 FOLD ftmp;
01212 CODEREP *cr;
01213 cr = ftmp.Fold_Expr(rhs_cr);
01214 if (cr) rhs_cr = cr;
01215 }
01216 }
01217
01218
01219 rhs_wn = Gen_exp_wn( rhs_cr, emitter );
01220
01221 base_wn = Gen_exp_wn( lhs->Istr_base(), emitter );
01222 index_wn = Gen_exp_wn( lhs->Index(), emitter );
01223 opcode = OPCODE_make_op(OPR_ISTOREX, MTYPE_V, lhs->Dsctyp());
01224 rwn = WN_Create(opcode, 3);
01225 WN_kid0(rwn) = rhs_wn;
01226 WN_kid1(rwn) = base_wn;
01227 WN_kid(rwn, 2) = index_wn;
01228 WN_set_ty(rwn, lhs->Ilod_base_ty());
01229 emitter->Alias_Mgr()->
01230 Gen_alias_id(rwn, lhs->Points_to(emitter->Opt_stab()));
01231 if (emitter->Gen_lno_info())
01232 WN_add_lno_info(rwn, lhs);
01233 break;
01234 }
01235
01236 case OPR_MSTORE:
01237 {
01238 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
01239 CODEREP *num_bytes = srep->Lhs()->Mstore_size();
01240 WN *num_bytes_wn = Gen_exp_wn(num_bytes, emitter );
01241 base_wn = Gen_exp_wn( srep->Lhs()->Istr_base(), emitter );
01242 rwn = WN_CreateMstore(srep->Lhs()->Offset(),
01243 srep->Lhs()->Ilod_ty(), rhs_wn,
01244 base_wn, num_bytes_wn);
01245 WN_set_field_id (rwn, srep->Lhs()->I_field_id ());
01246 emitter->Alias_Mgr()->Gen_alias_id(rwn,
01247 srep->Lhs()->Points_to(emitter->Opt_stab()));
01248 }
01249 break;
01250
01251 case OPR_LABEL:
01252 {
01253 WN *loop_info = NULL;
01254 if ( srep->Bb()->Label_loop_info() != NULL ) {
01255 if (emitter->For_preopt()) {
01256
01257
01258
01259 WN *old_info = srep->Bb()->Label_loop_info();
01260 loop_info = WN_CreateLoopInfo( NULL, NULL,
01261 WN_loop_trip_est(old_info),
01262 WN_loop_depth(old_info),
01263 WN_loop_flag(old_info) );
01264 }
01265 else {
01266 loop_info = emitter->Build_loop_info( srep->Bb() );
01267 }
01268 }
01269 Is_True(srep->Label_number() != 0, ("No label number."));
01270 rwn = WN_CreateLabel(srep->Label_number(),
01271 srep->Label_flags(),
01272 loop_info);
01273 }
01274 break;
01275
01276 case OPR_ASSERT:
01277 case OPR_RETURN_VAL:
01278 rwn = WN_COPY_Tree_With_Map(srep->Orig_wn());
01279 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
01280 #ifdef KEY // bug 5224
01281 if (srep->Opr() == OPR_RETURN_VAL &&
01282 OPERATOR_is_load(WN_operator(rhs_wn)) &&
01283 MTYPE_byte_size(WN_rtype(rhs_wn)) < MTYPE_byte_size(WN_rtype(rwn))){
01284 WN_set_rtype(rhs_wn, Mtype_TransferSize(WN_rtype(rwn), WN_rtype(rhs_wn)));
01285 }
01286 #endif
01287 WN_kid0(rwn) = rhs_wn;
01288 break;
01289
01290 case OPR_RETURN:
01291 case OPR_PRAGMA:
01292 #ifdef KEY
01293 case OPR_GOTO_OUTER_BLOCK:
01294 #endif
01295 rwn = WN_COPY_Tree_With_Map(srep->Orig_wn());
01296 if (OPCODE_has_aux(srep->Op()))
01297 WN_st_idx(rwn) = ST_st_idx(emitter->Opt_stab()->St(WN_aux(rwn)));
01298 break;
01299
01300 case OPR_XPRAGMA:
01301 #ifdef KEY
01302 if (emitter->Htable()->Phase() == MAINOPT_PHASE &&
01303 WN_pragma(srep->Orig_wn()) == WN_PRAGMA_COPYIN_BOUND)
01304 return NULL;
01305 #endif
01306 rwn = WN_COPY_Tree_With_Map(srep->Orig_wn());
01307 if (OPCODE_has_aux(srep->Op()))
01308 WN_st_idx(rwn) = ST_st_idx(emitter->Opt_stab()->St(WN_aux(rwn)));
01309 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
01310 WN_kid0(rwn) = rhs_wn;
01311 break;
01312
01313 case OPR_EVAL:
01314 rhs_wn = Gen_exp_wn( srep->Rhs(), emitter );
01315 if (srep->Bb()->Kind() == BB_DOHEAD && srep->Bb()->Loop()->Trip_count_stmt() == srep) {
01316 IDTYPE preg = emitter->Opt_stab()->Alloc_preg(srep->Rhs()->Dtyp());
01317 ST *preg_st = MTYPE_To_PREG(srep->Rhs()->Dtyp());
01318 OPCODE opcode = OPCODE_make_op(OPR_STID, MTYPE_V, srep->Rhs()->Dtyp());
01319 rwn = WN_CreateStid(opcode,preg,preg_st,ST_type(preg_st),rhs_wn);
01320 emitter->Alias_Mgr()->Gen_alias_id(rwn, NULL);
01321 opcode = OPCODE_make_op(OPR_LDID, srep->Rhs()->Dtyp(), srep->Rhs()->Dtyp());
01322 WN *lwn = WN_CreateLdid(opcode,preg,preg_st,ST_type(preg_st));
01323 emitter->Alias_Mgr()->Gen_alias_id(lwn, NULL);
01324 srep->Bb()->Loop()->Set_wn_trip_count(lwn);
01325 } else
01326 rwn = WN_CreateEval(rhs_wn);
01327 break;
01328
01329 case OPR_REGION:
01330 rwn = srep->Black_box_wn();
01331 break;
01332
01333 case OPR_OPT_CHI:
01334 {
01335 BB_NODE *entry_bb = srep->Bb();
01336 Is_True(entry_bb->Kind() == BB_ENTRY ||
01337 entry_bb->Kind() == BB_REGIONSTART,
01338 ("Gen_stmt_wn: cannot find entry bb (%s) for OPR_OPT_CHI node",
01339 srep->Bb()->Kind_name()));
01340 if (entry_bb->Kind() == BB_ENTRY)
01341 emitter->Connect_sr_wn( srep, entry_bb->Entrywn() );
01342 else {
01343
01344
01345 emitter->Set_region_entry_stmt(srep);
01346 }
01347 return NULL;
01348 }
01349 case OPR_IO:
01350 rwn = WN_COPY_Tree_With_Map(srep->Black_box_wn());
01351 emitter->Alias_Mgr()->Gen_black_box_alias(rwn);
01352 break;
01353 #ifdef KEY
01354 case OPR_COMMENT:
01355 return NULL;
01356 #endif
01357 default:
01358 FmtAssert(FALSE, ("Gen_stmt_wn: opcode %s is not implemented yet",
01359 OPCODE_name(srep->Op())));
01360 }
01361
01362 WN_Set_Linenum(rwn, srep->Linenum());
01363
01364 if (emitter->Cfg()->Feedback())
01365 emitter->Cfg()->Feedback()->Emit_feedback( rwn, srep->Bb() );
01366
01367 stmt_container->Append(rwn);
01368
01369 if (emitter->Do_rvi()) {
01370 if ( WN_has_mu(rwn, emitter->Cfg()->Rgn_level()) && srep->Mu_list() != NULL ) {
01371 emitter->Rvi()->Map_mu_list( rwn, srep->Mu_list() );
01372 }
01373 if ( WN_has_chi(rwn, emitter->Cfg()->Rgn_level()) && srep->Chi_list() != NULL ) {
01374 emitter->Rvi()->Map_chi_list( rwn, srep->Chi_list() );
01375 }
01376 }
01377
01378
01379 emitter->Connect_sr_wn( srep, rwn );
01380 return rwn;
01381 }
01382
01383
01384 template < class EMITTER > void
01385 Gen_stmt_list_wn(STMT_LIST *stmt_list,
01386 STMT_CONTAINER *stmt_container,
01387 EMITTER *emitter)
01388 {
01389 STMTREP_ITER stmt_iter(stmt_list);
01390 STMTREP *tmp;
01391 FOR_ALL_NODE(tmp, stmt_iter, Init()) {
01392 WN *twn = Gen_stmt_wn(tmp, stmt_container, emitter);
01393 }
01394 }
01395
01396
01397 template < class EMITTER >void
01398 Gen_bb_wn(BB_NODE *bb, EMITTER *emitter)
01399 {
01400
01401 STMT_CONTAINER stmt_cont(bb->Firststmt(), bb->Laststmt());
01402 Gen_stmt_list_wn(bb->Stmtlist(), &stmt_cont, emitter);
01403 bb->Set_firststmt(stmt_cont.Head());
01404 bb->Set_laststmt(stmt_cont.Tail());
01405 bb->Set_wngend();
01406 }
01407
01408 #endif // opt_emit_template_INCLUDED