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 #include "defs.h"
00054 #include "errors.h"
00055 #include "util.h"
00056 #include "tracing.h"
00057 #include "topcode.h"
00058 #include "wn.h"
00059 #include "opcode.h"
00060 #include "config_targ.h"
00061 #include "targ_isa_lits.h"
00062 #include "betarget.h"
00063 #include "w2op.h"
00064
00065 BOOL Targ_Lower_Float_To_Unsigned = TRUE;
00066 BOOL Targ_Lower_Unsigned_To_Float = TRUE;
00067
00068
00069 INT Max_Small_Frame_Offset = 0x7fff;
00070
00071
00072
00073 TOP
00074 OPCODE_To_TOP (OPCODE opcode)
00075 {
00076 OPERATOR opr = OPCODE_operator (opcode);
00077 TYPE_ID rtype = OPCODE_rtype (opcode);
00078 TYPE_ID desc = OPCODE_desc (opcode);
00079
00080 switch (opr) {
00081
00082 case OPR_GOTO:
00083 return TOP_j;
00084
00085 #ifdef TARG_SL2 //fork_joint_region
00086 case OPR_SL2_FORK_MAJOR:
00087 return TOP_c2_fork_m;
00088 case OPR_SL2_FORK_MINOR:
00089 return TOP_c2_fork_n;
00090 #endif
00091
00092 case OPR_FORWARD_BARRIER:
00093 return TOP_fwd_bar;
00094
00095 case OPR_BACKWARD_BARRIER:
00096 return TOP_bwd_bar;
00097
00098 case OPR_INTRINSIC_CALL:
00099 if (rtype == MTYPE_V) return TOP_intrncall;
00100 else return TOP_UNDEFINED;
00101
00102 case OPR_NEG:
00103 if (rtype == MTYPE_F4)
00104 return TOP_neg_s;
00105 if (rtype == MTYPE_F8)
00106 return TOP_neg_d;
00107 return TOP_UNDEFINED;
00108
00109 case OPR_ABS:
00110 if (rtype == MTYPE_F4)
00111 return TOP_abs_s;
00112 if (rtype == MTYPE_F8)
00113 return TOP_abs_d;
00114 return TOP_UNDEFINED;
00115
00116 case OPR_PAREN:
00117 if (rtype == MTYPE_F4) return TOP_noop;
00118 else if (rtype == MTYPE_F8) return TOP_noop;
00119 else return TOP_UNDEFINED;
00120
00121 case OPR_PARM:
00122 return TOP_noop;
00123
00124 case OPR_TRAP:
00125 return TOP_break;
00126
00127 default:
00128 return TOP_UNDEFINED;
00129 }
00130 }
00131
00132
00133
00134 TOP
00135 TAS_To_TOP (WN *tas_wn)
00136 {
00137 TYPE_ID kid_mtype = WN_rtype(WN_kid0(tas_wn));
00138
00139 switch (WN_opcode(tas_wn)) {
00140 case OPC_I4TAS:
00141 case OPC_U4TAS:
00142 return MTYPE_float(kid_mtype) ? TOP_mfc1 : TOP_noop;
00143 case OPC_I8TAS:
00144 case OPC_U8TAS:
00145 return MTYPE_float(kid_mtype) ? TOP_dmfc1 : TOP_noop;
00146 case OPC_F4TAS:
00147 case OPC_F8TAS:
00148 if (MTYPE_float(kid_mtype))
00149 return TOP_noop;
00150 else return MTYPE_is_size_double(kid_mtype) ? TOP_dmtc1 : TOP_mtc1;
00151 default:
00152 return TOP_UNDEFINED;
00153 }
00154 }
00155
00156
00157
00158 #define IS_POWER_OF_2(val) ((val != 0) && ((val & (val-1)) == 0))
00159
00160 static BOOL Is_Power_Of_2(INT64 val, TYPE_ID mtype)
00161 {
00162 if (MTYPE_is_signed(mtype) && val < 0)
00163 val= -val;
00164
00165 if (mtype == MTYPE_U4)
00166 val &= 0xffffffffull;
00167
00168 return IS_POWER_OF_2(val);
00169 }
00170
00171 static BOOL Is_Power_Of_2_Diff1(INT64 val, TYPE_ID mtype)
00172 {
00173 return (Is_Power_Of_2(val-1, mtype)||Is_Power_Of_2(val+1, mtype));
00174 }
00175
00176 static BOOL Is_Power_Of_2_Diff2(INT64 val, TYPE_ID mtype)
00177 {
00178 return (Is_Power_Of_2(val-2, mtype)||Is_Power_Of_2(val+2, mtype));
00179 }
00180
00181
00182
00183 BOOL
00184 Can_Do_Fast_Multiply (TYPE_ID mtype, INT64 val)
00185 {
00186 #if defined(TARG_SL)
00187 if(Is_Power_Of_2(val, mtype)||Is_Power_Of_2_Diff1(val, mtype)||Is_Power_Of_2_Diff2(val, mtype)){
00188 return TRUE;
00189 }
00190 return FALSE;
00191 #else
00192 return TRUE;
00193 #endif
00194 }
00195
00196
00197 BOOL
00198 Can_Do_Fast_Divide (TYPE_ID mtype, INT64 dividend)
00199 {
00200 return Is_Power_Of_2(dividend, mtype);
00201 }
00202
00203
00204 BOOL
00205 Can_Do_Fast_Remainder (TYPE_ID mtype, INT64 dividend)
00206 {
00207 return Is_Power_Of_2(dividend, mtype);
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 INT
00224 Multiply_Limit (WN * tree)
00225 {
00226 Is_True( WN_operator( tree ) == OPR_MPY, ("Expecting a multiply operator") );
00227 if (MTYPE_byte_size(WN_rtype(tree)) == 8)
00228 return 4;
00229 else return 3;
00230 }
00231
00232 INT
00233 Divide_Limit (WN * tree)
00234 {
00235 Is_True( WN_operator( tree ) == OPR_DIV, ("Expecting a divide operator") );
00236 if (MTYPE_byte_size(WN_rtype(tree)) == 8)
00237 return 68;
00238 else return 36;
00239 }
00240
00241
00242 INT
00243 Copy_Quantum_Ratio(void)
00244 {
00245 INT32 ratio;
00246
00247
00248
00249 switch(Target) {
00250 case TARGET_R10K:
00251 case TARGET_sb1: ratio= 4; break;
00252 default: ratio= 4; break;
00253 }
00254
00255 return ratio;
00256 }
00257
00258
00259
00260
00261 inline BOOL Is_Signed_Bits(INT64 val, INT bits)
00262 {
00263 INT64 hibit = 1LL << (bits - 1);
00264 return val >= -hibit && val <= (hibit - 1);
00265 }
00266
00267
00268
00269
00270 inline BOOL Is_Unsigned_Bits(UINT64 val, INT bits)
00271 {
00272 return val < (1ULL << bits);
00273 }
00274
00275
00276
00277
00278 BOOL Can_Be_Immediate(OPERATOR opr,
00279 INT64 val,
00280 TYPE_ID dtype,
00281 INT whichkid,
00282 ST *stid_st)
00283 {
00284 TOP top;
00285
00286 switch (opr)
00287 {
00288 case OPR_AGOTO:
00289 case OPR_LOOP_INFO:
00290 return TRUE;
00291
00292 case OPR_EQ:
00293 case OPR_NE:
00294 return FALSE;
00295
00296 case OPR_GE:
00297 return whichkid == 0 && Is_Signed_Bits(val+1, 16);
00298
00299 case OPR_GT:
00300 return whichkid == 0 && Is_Signed_Bits(val, 16);
00301
00302 case OPR_LE:
00303 return whichkid == 1 && Is_Signed_Bits(val+1, 16);
00304
00305 case OPR_LT:
00306 return whichkid == 1 && Is_Signed_Bits(val, 16);
00307
00308 case OPR_MAX:
00309 case OPR_MIN:
00310 return Is_Signed_Bits(val, 16);
00311
00312 case OPR_ASHR:
00313 case OPR_LSHR:
00314 return (whichkid == 1);
00315
00316 case OPR_SHL:
00317 return (whichkid == 1);
00318
00319 case OPR_MLOAD:
00320 return whichkid == 1;
00321
00322 case OPR_MSTORE:
00323 return whichkid == 2;
00324
00325 case OPR_BAND:
00326 if ((val > 0) && (val < 65536))
00327 return TRUE;
00328 break;
00329
00330 case OPR_SUB:
00331
00332 if (whichkid != 1)
00333 return FALSE;
00334 val = -val;
00335
00336
00337 case OPR_ADD:
00338 return ISA_LC_Value_In_Class(val, LC_simm16);
00339
00340 case OPR_DIV:
00341
00342 return whichkid == 1 && Can_Do_Fast_Divide(dtype, val);
00343
00344 case OPR_REM:
00345 case OPR_MOD:
00346
00347 return whichkid == 1 && Can_Do_Fast_Remainder(dtype, val);
00348
00349 case OPR_DIVREM:
00350
00351 return whichkid == 1
00352 && Can_Do_Fast_Remainder(dtype, val)
00353 && Can_Do_Fast_Divide(dtype, val);
00354
00355 case OPR_MPY:
00356
00357 return Can_Do_Fast_Multiply(dtype, val);
00358
00359 case OPR_SELECT:
00360
00361
00362
00363 return whichkid > 0 && Is_Signed_Bits(val, 16);
00364
00365 case OPR_CALL:
00366 case OPR_ICALL:
00367 case OPR_INTRINSIC_CALL:
00368 case OPR_PARM:
00369
00370
00371
00372 return TRUE;
00373
00374 case OPR_STID:
00375
00376
00377
00378 return ST_class(stid_st) == CLASS_PREG;
00379 }
00380
00381 return FALSE;
00382 }