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 #include "opt_cvtl_rule.h"
00056 #include "wn.h"
00057
00058 #define nop {NOT_AT_ALL,OPCODE_LAST+1}
00059 #define I8I4 {NEED_CVT, OPC_I8I4CVT}
00060 #define U8I4 {NEED_CVT, OPC_U8I4CVT}
00061 #define I4I8 {NEED_CVT, OPC_I4I8CVT}
00062 #define U4I8 {NEED_CVT, OPC_U4I8CVT}
00063 #define I8U4 {NEED_CVT, OPC_I8U4CVT}
00064 #define U8U4 {NEED_CVT, OPC_U8U4CVT}
00065 #define I4U8 {NEED_CVT, OPC_I4U8CVT}
00066 #define U4U8 {NEED_CVT, OPC_U4U8CVT}
00067
00068 #define I4I2 {NEED_CVTL, OPC_I4CVTL}
00069 #define I4I1 {NEED_CVTL, OPC_I4CVTL}
00070 #define U4U2 {NEED_CVTL, OPC_U4CVTL}
00071 #define U4U1 {NEED_CVTL, OPC_U4CVTL}
00072 #define I4U4 {NEED_CVTL, OPC_U4CVTL}
00073 #define U4I4 {NEED_CVTL, OPC_I4CVTL}
00074 #define I8I2 {NEED_CVTL, OPC_I8CVTL}
00075 #define I8I1 {NEED_CVTL, OPC_I8CVTL}
00076 #define U8U2 {NEED_CVTL, OPC_U8CVTL}
00077 #define U8U1 {NEED_CVTL, OPC_U8CVTL}
00078 #define I8U2 {NEED_CVTL, OPC_I8CVTL}
00079 #define I8U1 {NEED_CVTL, OPC_I8CVTL}
00080 #define U8I2 {NEED_CVTL, OPC_U8CVTL}
00081 #define U8I1 {NEED_CVTL, OPC_U8CVTL}
00082
00083 #define I1I4 {NEED_CVTL, OPC_I4CVTL}
00084 #define I2I4 {NEED_CVTL, OPC_I4CVTL}
00085 #define I1I8 {NEED_CVTL, OPC_I8CVTL}
00086 #define I2I8 {NEED_CVTL, OPC_I8CVTL}
00087 #define U1U4 {NEED_CVTL, OPC_U4CVTL}
00088 #define U2U4 {NEED_CVTL, OPC_U4CVTL}
00089 #define U1U8 {NEED_CVTL, OPC_U8CVTL}
00090 #define U2U8 {NEED_CVTL, OPC_U8CVTL}
00091
00092 #define I4B {NEED_CVT, OPC_I4BCVT}
00093 #define I8B {NEED_CVT, OPC_I8BCVT}
00094 #define U4B {NEED_CVT, OPC_U4BCVT}
00095 #define U8B {NEED_CVT, OPC_U8BCVT}
00096
00097
00098
00099
00100
00101 static struct cvt_rule {
00102 char _cvt_kind;
00103 mINT32 _cvt_opcode;
00104 } cvt_rule[MTYPE_U8+1][MTYPE_U8+1] = {
00105
00106 { nop, nop, nop, nop, nop, nop, nop, nop, nop, nop},
00107 { nop, nop, nop, nop, nop, nop, nop, nop, nop, nop},
00108 { nop, nop, nop, nop,I1I4,I1I8, nop, nop,I1I4,I1I8},
00109 { nop, nop, nop, nop,I2I4,I2I8, nop, nop,I2I4,I1I8},
00110 { nop, I4B,I4I1,I4I2, nop,I4I8, nop, nop, nop,U4U8},
00111 #ifdef TARG_SL
00112 { nop, I8B,I8I1,I8I2,I8I4, nop, I8U1,I8U2,I8U4, nop},
00113 #elif defined(TARG_MIPS)
00114 { nop, nop,I8I1,I8I2, nop, nop, nop, nop,I8U4, nop},
00115 #elif defined(TARG_IA32)
00116 { nop, nop,I8I1,I8I2,I8I4, nop, nop, nop,I8U4, nop},
00117 #elif defined(TARG_NVISA)
00118 { nop, I8B,I8I1,I8I2,I8I4, nop, I8U1,I8U2,I8U4, nop},
00119 #else
00120 { nop, I8B,I8I1,I8I2,I8I4, nop, nop, nop, nop, nop},
00121 #endif
00122 { nop, nop, nop, nop,U1U4,U1U8, nop, nop,U1U4,U1U8},
00123 { nop, nop, nop, nop,U2U4,U2U8, nop, nop,U2U4,U2U8},
00124 { nop, U4B, nop, nop, nop,U4I8,U4U1,U4U2, nop,U4U8},
00125 #ifdef TARG_SL
00126 { nop, U8B,U8I1,U8I2,U8I4, nop,U8U1,U8U2,U8U4, nop}
00127 #elif defined(TARG_MIPS)
00128 { nop, nop, nop, nop, nop, nop,U8U1,U8U2,U8U4, nop}
00129 #elif defined(TARG_IA32)
00130 { nop, nop, nop, nop,U8I4, nop,U8U1,U8U2,U8U4, nop}
00131 #elif defined(TARG_NVISA)
00132 { nop, U8B,U8I1,U8I2,U8I4, nop,U8U1,U8U2,U8U4, nop}
00133 #elif defined(TARG_IA64)
00134 { nop, U8B, nop, nop,U8U4, nop,U8U1,U8U2,U8U4, nop}
00135 #else // TARG_X8664
00136 { nop, U8B, nop, nop,U8U4, nop,U8U1,U8U2, nop, nop}
00137 #endif
00138 };
00139
00140
00141
00142
00143 INT Need_type_conversion(TYPE_ID from_ty, TYPE_ID to_ty, OPCODE *opc)
00144 {
00145 #ifdef TARG_X8664 // bug 2879
00146 if (Is_Target_32bit() && from_ty == MTYPE_U4 &&
00147 MTYPE_is_integral(to_ty) && MTYPE_byte_size(to_ty) == 8) {
00148 if (opc != NULL)
00149 *opc = MTYPE_signed(to_ty) ? OPC_I8I4CVT : OPC_U8U4CVT;
00150 return NEED_CVT;
00151 }
00152 if ((from_ty == MTYPE_V16C8 && to_ty == MTYPE_V16F8) ||
00153 (from_ty == MTYPE_V16F8 && to_ty == MTYPE_V16C8)) return NOT_AT_ALL;
00154 #endif
00155 if (!(MTYPE_is_integral(from_ty) && MTYPE_is_integral(to_ty))) {
00156 if (from_ty == to_ty) return NOT_AT_ALL;
00157 if (opc != NULL)
00158 *opc = OPCODE_make_op(OPR_CVT, to_ty, from_ty);
00159 return NEED_CVT;
00160 }
00161 #ifdef TARG_X8664 // bug 7733
00162 if (MTYPE_is_vector(from_ty) || MTYPE_is_vector(to_ty)) {
00163 if (from_ty == to_ty) return NOT_AT_ALL;
00164 if (opc != NULL)
00165 *opc = OPCODE_make_op(OPR_CVT, to_ty, from_ty);
00166 return NEED_CVT;
00167 }
00168 #endif
00169 #ifdef KEY // bug 3742
00170 if (from_ty > MTYPE_U8 || to_ty > MTYPE_U8)
00171 {
00172 if (from_ty == to_ty) return NOT_AT_ALL;
00173 Fail_FmtAssertion ("Need_type_conversion: Don't know how to convert");
00174 }
00175 #endif
00176
00177 if (opc != NULL)
00178 *opc = (OPCODE)cvt_rule[to_ty][from_ty]._cvt_opcode;
00179 return (INT)cvt_rule[to_ty][from_ty]._cvt_kind;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 INT Need_load_type_conversion(BOOL source_sign_extd, BOOL target_sign_extd,
00226 TYPE_ID to_ty, TYPE_ID dsc_ty, OPCODE *opc)
00227 {
00228
00229 Is_True(MTYPE_is_integral(to_ty),("Need_load_type_conversion: non integral type"));
00230 Is_True(to_ty != MTYPE_BS,("Need_load_type_conversion: illegal MTYPE_BS"));
00231 Is_True(MTYPE_size_min(to_ty)>=MTYPE_size_min(MTYPE_I4),
00232 ("Need_load_type_conversion: data type size less than I4"));
00233
00234 if (source_sign_extd == target_sign_extd ||
00235 MTYPE_size_min(dsc_ty) > MTYPE_size_min(MTYPE_I4) && dsc_ty != MTYPE_BS)
00236 return NOT_AT_ALL;
00237
00238 if (MTYPE_size_min(dsc_ty) == MTYPE_size_min(MTYPE_I4) &&
00239 dsc_ty != MTYPE_BS) {
00240 if (source_sign_extd) {
00241 *opc = (OPCODE) OPC_U8U4CVT;
00242 } else {
00243 #ifndef KEY
00244 *opc = (OPCODE) OPC_U4U8CVT;
00245 #else
00246 #ifdef TARG_MIPS
00247 *opc = (OPCODE) OPC_I4U8CVT;
00248 #else
00249 *opc = (OPCODE) OPC_I8I4CVT;
00250 #endif // TARG_MIPS
00251 #endif
00252 }
00253 return NEED_CVT;
00254 }
00255 else {
00256 if (source_sign_extd) {
00257 *opc = (OPCODE) (MTYPE_size_min(to_ty) == MTYPE_size_min(MTYPE_I4)) ?
00258 OPC_U4CVTL : OPC_U8CVTL;
00259 } else {
00260 *opc = (OPCODE) (MTYPE_size_min(to_ty) == MTYPE_size_min(MTYPE_I4)) ?
00261 OPC_I4CVTL : OPC_I8CVTL;
00262 }
00263 return NEED_CVTL;
00264 }
00265
00266 }
00267
00268
00269 BOOL
00270 Types_are_compatible(TYPE_ID lhs_type, TYPE_ID rhs_type)
00271 {
00272 BOOL compatible;
00273 OPCODE opc;
00274
00275 if ((MTYPE_type_class(rhs_type)&MTYPE_CLASS_UNSIGNED_INTEGER) == 0 ||
00276 (MTYPE_type_class(lhs_type)&MTYPE_CLASS_UNSIGNED_INTEGER) == 0) {
00277 if (rhs_type == lhs_type) return FALSE;
00278 else
00279 return TRUE;
00280 }
00281 compatible = Need_type_conversion(rhs_type, lhs_type, &opc) != NEED_CVT;
00282 return compatible;
00283 }
00284
00285
00286 BOOL
00287 Types_are_compatible(TYPE_ID lhs_type, WN *rhs_wn)
00288 {
00289 TYPE_ID rhs_type = Actual_result_type(rhs_wn);
00290
00291 return Types_are_compatible(lhs_type, rhs_type);
00292 }
00293
00294
00295
00296 TYPE_ID Rebuild_rtype(TYPE_ID rtype, INT bits)
00297 {
00298 if ( rtype == MTYPE_I4 || rtype == MTYPE_I8 ) {
00299 if ( bits <= 8 )
00300 rtype = MTYPE_I1;
00301 else if ( bits <= 16 )
00302 rtype = MTYPE_I2;
00303 else if ( bits <= 32 )
00304 rtype = MTYPE_I4;
00305 else
00306 rtype = MTYPE_I8;
00307 }
00308 else {
00309 if ( bits <= 8 )
00310 rtype = MTYPE_U1;
00311 else if ( bits <= 16 )
00312 rtype = MTYPE_U2;
00313 else if ( bits <= 32 )
00314 rtype = MTYPE_U4;
00315 else
00316 rtype = MTYPE_U8;
00317 }
00318 return rtype;
00319 }
00320
00321
00322
00323
00324 INT Actual_data_size(WN *wn)
00325 {
00326 OPERATOR opr = WN_operator(wn);
00327 TYPE_ID rtype = WN_rtype(wn);
00328 INT actual_size;
00329
00330 if ((MTYPE_type_class(rtype) & MTYPE_CLASS_INTEGER) == 0)
00331 return MTYPE_size_min(rtype);
00332
00333 switch ( opr ) {
00334 case OPR_INTCONST:
00335 {
00336 INT64 val;
00337 for (val = WN_const_val(wn), actual_size = 0;
00338 actual_size < 64 && val != 0; actual_size++)
00339 val = val >> 1;
00340 if (MTYPE_is_integral(rtype) && !MTYPE_is_unsigned(rtype) && MTYPE_size_min(rtype) == actual_size) {
00341
00342 actual_size = MTYPE_size_min(Pointer_type);
00343 }
00344 return actual_size;
00345 }
00346
00347 case OPR_CVTL:
00348 if (MTYPE_is_signed(rtype)) {
00349 actual_size = Actual_data_size(WN_kid0(wn));
00350 if (MTYPE_size_min(rtype) == actual_size)
00351 return actual_size;
00352 else
00353 return WN_cvtl_bits(wn);
00354 }
00355 else
00356 return WN_cvtl_bits(wn);
00357
00358 case OPR_LDBITS:
00359 case OPR_ILDBITS:
00360 if (MTYPE_is_signed(rtype))
00361 return MTYPE_size_min(rtype);
00362 else
00363 return WN_bit_size (wn);
00364
00365 case OPR_LDID:
00366 case OPR_ILOAD:
00367 if (MTYPE_is_signed(rtype))
00368 return MTYPE_size_min(rtype);
00369 else
00370 return MTYPE_size_min(WN_desc(wn));
00371
00372 case OPR_BAND:
00373 case OPR_BIOR:
00374 {
00375 INT kid0_size = Actual_data_size(WN_kid0(wn));
00376 INT kid1_size = Actual_data_size(WN_kid1(wn));
00377 if (MTYPE_is_unsigned(rtype)) {
00378 if (opr == OPR_BIOR)
00379 return (kid0_size > kid1_size)? kid0_size : kid1_size;
00380 else return (kid0_size > kid1_size)? kid1_size : kid0_size;
00381 }
00382 else return MTYPE_size_min(rtype);
00383 }
00384
00385 case OPR_SHL:
00386 case OPR_ASHR:
00387 case OPR_LSHR:
00388 {
00389
00390 WN *bits = WN_kid1(wn);
00391
00392
00393 if ( WN_operator(bits) == OPR_INTCONST ) {
00394 UINT bit_cnt = WN_const_val(bits);
00395 if (MTYPE_size_min(rtype) == 32)
00396 bit_cnt &= 0x1F;
00397 else
00398 bit_cnt &= 0x3F;
00399
00400 actual_size = Actual_data_size(WN_kid0(wn));
00401 if (opr == OPR_SHL) {
00402 if (MTYPE_is_unsigned(rtype)) {
00403 actual_size += bit_cnt;
00404 if (actual_size > MTYPE_size_min(rtype))
00405 actual_size = MTYPE_size_min(rtype);
00406 }
00407 else actual_size = MTYPE_size_min(rtype);
00408 }
00409 else if (MTYPE_is_unsigned(rtype)) {
00410 actual_size -= bit_cnt;
00411 if (actual_size < 0) actual_size = 0;
00412 }
00413 else actual_size = MTYPE_size_min(rtype);
00414 return actual_size;
00415 }
00416 }
00417 break;
00418 default:
00419 ;
00420 }
00421 return MTYPE_size_min(rtype);
00422 }
00423
00424
00425
00426
00427 TYPE_ID Actual_cvtl_type(OPCODE opc, INT bits)
00428 {
00429 return Rebuild_rtype(OPCODE_rtype(opc), bits);
00430 }
00431
00432
00433
00434
00435
00436 TYPE_ID Actual_result_type(WN *wn)
00437 {
00438 OPCODE opc = WN_opcode(wn);
00439 TYPE_ID rtype = OPCODE_rtype(opc);
00440 INT bits;
00441
00442
00443 if ((MTYPE_type_class(rtype) & MTYPE_CLASS_INTEGER) == 0)
00444 return rtype;
00445
00446 switch ( OPCODE_operator(opc) ) {
00447 case OPR_CVTL:
00448 case OPR_LDID:
00449 case OPR_LDBITS:
00450 case OPR_ILOAD:
00451 case OPR_ILDBITS:
00452 case OPR_BIOR:
00453 case OPR_BAND:
00454 case OPR_SHL:
00455 case OPR_ASHR:
00456 case OPR_LSHR:
00457 case OPR_INTCONST:
00458 bits = Actual_data_size(wn);
00459 rtype = Rebuild_rtype(rtype, bits);
00460 }
00461
00462 return rtype;
00463 }
00464
00465 TYPE_ID Adjust_signed_type(TYPE_ID rtype, INT size, WN *wn)
00466 {
00467 INT bits = Actual_data_size(wn);
00468
00469 if (MTYPE_is_integral(rtype) && !MTYPE_is_unsigned(rtype) && size == bits) {
00470
00471
00472 return Rebuild_rtype(rtype, 32);
00473 }
00474 return MTYPE_UNKNOWN;
00475 }