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 #include <map>
00092 #include "defs.h"
00093 #include "tracing.h"
00094 #include "errors.h"
00095 #include "wn.h"
00096 #include "bb.h"
00097 #include "op.h"
00098 #include "tn.h"
00099 #include "cg.h"
00100 #include "cgtarget.h"
00101
00102 static std::map<TOP, TOP> InstructionMap;
00103
00104
00105
00106
00107
00108
00109
00110
00111 static TN_MAP tn_16bit_map;
00112 #define DEF_IS_16BIT 0x1
00113 #define USE_IS_16BIT 0x2
00114 #define DEF_IS_NOT16BIT 0x4
00115 #define USE_IS_NOT16BIT 0x8
00116 #define DEF_IS_MAYBE16BIT 0x10
00117 #define USE_IS_MAYBE16BIT 0x20
00118 #define TN_16bit_flags(tn) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn))
00119 #define TN_def_is_16bit(tn) (TN_16bit_flags(tn) & DEF_IS_16BIT)
00120 #define TN_use_is_16bit(tn) (TN_16bit_flags(tn) & USE_IS_16BIT)
00121 #define TN_def_is_not16bit(tn) (TN_16bit_flags(tn) & DEF_IS_NOT16BIT)
00122 #define TN_use_is_not16bit(tn) (TN_16bit_flags(tn) & USE_IS_NOT16BIT)
00123 #define TN_def_is_maybe16bit(tn) (TN_16bit_flags(tn) & DEF_IS_MAYBE16BIT)
00124 #define TN_use_is_maybe16bit(tn) (TN_16bit_flags(tn) & USE_IS_MAYBE16BIT)
00125 #define Set_TN_def_is_16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00126 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) | DEF_IS_16BIT))
00127 #define Set_TN_use_is_16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00128 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) | USE_IS_16BIT))
00129 #define Set_TN_def_is_not16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00130 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) | DEF_IS_NOT16BIT))
00131 #define Set_TN_use_is_not16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00132 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) | USE_IS_NOT16BIT))
00133 #define Set_TN_def_is_maybe16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00134 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) | DEF_IS_MAYBE16BIT))
00135 #define Set_TN_use_is_maybe16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00136 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) | USE_IS_MAYBE16BIT))
00137 #define Reset_TN_def_is_16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00138 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) & ~DEF_IS_16BIT))
00139 #define Reset_TN_use_is_16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00140 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) & ~USE_IS_16BIT))
00141 #define Reset_TN_def_is_maybe16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00142 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) & ~DEF_IS_MAYBE16BIT))
00143 #define Reset_TN_use_is_maybe16bit(tn) TN_MAP_Set(tn_16bit_map, tn, \
00144 (void*) ((INTPTR)TN_MAP_Get(tn_16bit_map,tn) & ~USE_IS_MAYBE16BIT))
00145
00146 static BOOL tracing = FALSE;
00147
00148 static
00149 void Create_Instruction_Map(void)
00150 {
00151
00152 InstructionMap[TOP_cvt_s8_s32] = TOP_mov_s16;
00153 InstructionMap[TOP_cvt_s8_u32] = TOP_mov_s16;
00154 InstructionMap[TOP_cvt_u8_s32] = TOP_mov_u16;
00155 InstructionMap[TOP_cvt_u8_u32] = TOP_mov_u16;
00156 InstructionMap[TOP_cvt_s32_s8] = TOP_mov_s16;
00157 InstructionMap[TOP_cvt_u32_u8] = TOP_mov_u16;
00158 InstructionMap[TOP_cvt_s8_s32_b32] = TOP_mov_s16;
00159 InstructionMap[TOP_cvt_s8_u32_b32] = TOP_mov_s16;
00160 InstructionMap[TOP_cvt_u8_s32_b32] = TOP_mov_u16;
00161 InstructionMap[TOP_cvt_u8_u32_b32] = TOP_mov_u16;
00162 InstructionMap[TOP_cvt_s16_s32] = TOP_mov_s16;
00163 InstructionMap[TOP_cvt_s16_u32] = TOP_mov_s16;
00164 InstructionMap[TOP_cvt_u16_s32] = TOP_mov_u16;
00165 InstructionMap[TOP_cvt_u16_u32] = TOP_mov_u16;
00166 InstructionMap[TOP_cvt_s32_s16] = TOP_mov_s16;
00167 InstructionMap[TOP_cvt_u32_u16] = TOP_mov_u16;
00168 InstructionMap[TOP_cvt_s16_s32_b32] = TOP_mov_s16;
00169 InstructionMap[TOP_cvt_s16_u32_b32] = TOP_mov_s16;
00170 InstructionMap[TOP_cvt_u16_s32_b32] = TOP_mov_u16;
00171 InstructionMap[TOP_cvt_u16_u32_b32] = TOP_mov_u16;
00172
00173 InstructionMap[TOP_mov_s32] = TOP_mov_s16;
00174 InstructionMap[TOP_mov_s32_lit] = TOP_mov_s16_lit;
00175 InstructionMap[TOP_mov_u32] = TOP_mov_u16;
00176 InstructionMap[TOP_mov_u32_lit] = TOP_mov_u16_lit;
00177
00178 InstructionMap[TOP_min_s32] = TOP_min_s16;
00179 InstructionMap[TOP_max_s32] = TOP_max_s16;
00180 InstructionMap[TOP_min_u32] = TOP_min_u16;
00181 InstructionMap[TOP_max_u32] = TOP_max_u16;
00182 InstructionMap[TOP_and_b32] = TOP_and_b16;
00183 InstructionMap[TOP_and_b32_lit] = TOP_and_b16_lit;
00184 InstructionMap[TOP_or_b32] = TOP_or_b16;
00185 InstructionMap[TOP_or_b32_lit] = TOP_or_b16_lit;
00186 InstructionMap[TOP_xor_b32] = TOP_xor_b16;
00187 InstructionMap[TOP_xor_b32_lit] = TOP_xor_b16_lit;
00188 InstructionMap[TOP_shl_b32] = TOP_shl_b16;
00189 InstructionMap[TOP_shr_u32] = TOP_shr_u16;
00190 InstructionMap[TOP_shl_b32_lit] = TOP_shl_b16_lit;
00191 InstructionMap[TOP_shr_u32_lit] = TOP_shr_u16_lit;
00192 InstructionMap[TOP_div_u32] = TOP_div_u16;
00193 InstructionMap[TOP_rem_u32] = TOP_rem_u16;
00194 InstructionMap[TOP_div_u32_lit] = TOP_div_u16_lit;
00195 InstructionMap[TOP_rem_u32_lit] = TOP_rem_u16_lit;
00196 InstructionMap[TOP_not_b32] = TOP_not_b16;
00197 InstructionMap[TOP_abs_s32] = TOP_abs_s16;
00198 InstructionMap[TOP_abs_u32] = TOP_abs_u16;
00199 InstructionMap[TOP_neg_s32] = TOP_neg_s16;
00200 InstructionMap[TOP_neg_u32] = TOP_neg_u16;
00201
00202 InstructionMap[TOP_add_s32] = TOP_add_s16;
00203 InstructionMap[TOP_add_s32_lit] = TOP_add_s16_lit;
00204 InstructionMap[TOP_add_u32] = TOP_add_u16;
00205 InstructionMap[TOP_add_u32_lit] = TOP_add_u16_lit;
00206 InstructionMap[TOP_sub_s32] = TOP_sub_s16;
00207 InstructionMap[TOP_sub_s32_lit] = TOP_sub_s16_lit;
00208 InstructionMap[TOP_sub_u32] = TOP_sub_u16;
00209 InstructionMap[TOP_sub_u32_lit] = TOP_sub_u16_lit;
00210 InstructionMap[TOP_mul_lo_s32] = TOP_mul_lo_s16;
00211 InstructionMap[TOP_mul_lo_s32_lit] = TOP_mul_lo_s16_lit;
00212 InstructionMap[TOP_mul_lo_u32] = TOP_mul_lo_u16;
00213 InstructionMap[TOP_mul_lo_u32_lit] = TOP_mul_lo_u16_lit;
00214
00215 InstructionMap[TOP_ld_qualifier_space_u8_b32] = TOP_ld_qualifier_space_u8;
00216 InstructionMap[TOP_ld_qualifier_space_s8_b32] = TOP_ld_qualifier_space_s8;
00217 InstructionMap[TOP_ld_qualifier_space_u8_b32_o] = TOP_ld_qualifier_space_u8_o;
00218 InstructionMap[TOP_ld_qualifier_space_s8_b32_o] = TOP_ld_qualifier_space_s8_o;
00219 InstructionMap[TOP_ld_qualifier_space_u8_b32_r] = TOP_ld_qualifier_space_u8_r;
00220 InstructionMap[TOP_ld_qualifier_space_s8_b32_r] = TOP_ld_qualifier_space_s8_r;
00221 InstructionMap[TOP_st_qualifier_space_u8_b32] = TOP_st_qualifier_space_u8;
00222 InstructionMap[TOP_st_qualifier_space_s8_b32] = TOP_st_qualifier_space_s8;
00223 InstructionMap[TOP_st_qualifier_space_u8_b32_o] = TOP_st_qualifier_space_u8_o;
00224 InstructionMap[TOP_st_qualifier_space_s8_b32_o] = TOP_st_qualifier_space_s8_o;
00225 InstructionMap[TOP_st_qualifier_space_u8_b32_r] = TOP_st_qualifier_space_u8_r;
00226 InstructionMap[TOP_st_qualifier_space_s8_b32_r] = TOP_st_qualifier_space_s8_r;
00227 InstructionMap[TOP_ld_qualifier_space_u16_b32] = TOP_ld_qualifier_space_u16;
00228 InstructionMap[TOP_ld_qualifier_space_s16_b32] = TOP_ld_qualifier_space_s16;
00229 InstructionMap[TOP_ld_qualifier_space_u16_b32_o] = TOP_ld_qualifier_space_u16_o;
00230 InstructionMap[TOP_ld_qualifier_space_s16_b32_o] = TOP_ld_qualifier_space_s16_o;
00231 InstructionMap[TOP_ld_qualifier_space_u16_b32_r] = TOP_ld_qualifier_space_u16_r;
00232 InstructionMap[TOP_ld_qualifier_space_s16_b32_r] = TOP_ld_qualifier_space_s16_r;
00233 InstructionMap[TOP_st_qualifier_space_u16_b32] = TOP_st_qualifier_space_u16;
00234 InstructionMap[TOP_st_qualifier_space_s16_b32] = TOP_st_qualifier_space_s16;
00235 InstructionMap[TOP_st_qualifier_space_u16_b32_o] = TOP_st_qualifier_space_u16_o;
00236 InstructionMap[TOP_st_qualifier_space_s16_b32_o] = TOP_st_qualifier_space_s16_o;
00237 InstructionMap[TOP_st_qualifier_space_u16_b32_r] = TOP_st_qualifier_space_u16_r;
00238 InstructionMap[TOP_st_qualifier_space_s16_b32_r] = TOP_st_qualifier_space_s16_r;
00239
00240 InstructionMap[TOP_ld_qualifier_space_u8_b32_a64] = TOP_ld_qualifier_space_u8_a64;
00241 InstructionMap[TOP_ld_qualifier_space_s8_b32_a64] = TOP_ld_qualifier_space_s8_a64;
00242 InstructionMap[TOP_ld_qualifier_space_u8_b32_a64_o] = TOP_ld_qualifier_space_u8_a64_o;
00243 InstructionMap[TOP_ld_qualifier_space_s8_b32_a64_o] = TOP_ld_qualifier_space_s8_a64_o;
00244 InstructionMap[TOP_ld_qualifier_space_u8_b32_a64_r] = TOP_ld_qualifier_space_u8_a64_r;
00245 InstructionMap[TOP_ld_qualifier_space_s8_b32_a64_r] = TOP_ld_qualifier_space_s8_a64_r;
00246 InstructionMap[TOP_st_qualifier_space_u8_b32_a64] = TOP_st_qualifier_space_u8_a64;
00247 InstructionMap[TOP_st_qualifier_space_s8_b32_a64] = TOP_st_qualifier_space_s8_a64;
00248 InstructionMap[TOP_st_qualifier_space_u8_b32_a64_o] = TOP_st_qualifier_space_u8_a64_o;
00249 InstructionMap[TOP_st_qualifier_space_s8_b32_a64_o] = TOP_st_qualifier_space_s8_a64_o;
00250 InstructionMap[TOP_st_qualifier_space_u8_b32_a64_r] = TOP_st_qualifier_space_u8_a64_r;
00251 InstructionMap[TOP_st_qualifier_space_s8_b32_a64_r] = TOP_st_qualifier_space_s8_a64_r;
00252 InstructionMap[TOP_ld_qualifier_space_u16_b32_a64] = TOP_ld_qualifier_space_u16_a64;
00253 InstructionMap[TOP_ld_qualifier_space_s16_b32_a64] = TOP_ld_qualifier_space_s16_a64;
00254 InstructionMap[TOP_ld_qualifier_space_u16_b32_a64_o] = TOP_ld_qualifier_space_u16_a64_o;
00255 InstructionMap[TOP_ld_qualifier_space_s16_b32_a64_o] = TOP_ld_qualifier_space_s16_a64_o;
00256 InstructionMap[TOP_ld_qualifier_space_u16_b32_a64_r] = TOP_ld_qualifier_space_u16_a64_r;
00257 InstructionMap[TOP_ld_qualifier_space_s16_b32_a64_r] = TOP_ld_qualifier_space_s16_a64_r;
00258 InstructionMap[TOP_st_qualifier_space_u16_b32_a64] = TOP_st_qualifier_space_u16_a64;
00259 InstructionMap[TOP_st_qualifier_space_s16_b32_a64] = TOP_st_qualifier_space_s16_a64;
00260 InstructionMap[TOP_st_qualifier_space_u16_b32_a64_o] = TOP_st_qualifier_space_u16_a64_o;
00261 InstructionMap[TOP_st_qualifier_space_s16_b32_a64_o] = TOP_st_qualifier_space_s16_a64_o;
00262 InstructionMap[TOP_st_qualifier_space_u16_b32_a64_r] = TOP_st_qualifier_space_u16_a64_r;
00263 InstructionMap[TOP_st_qualifier_space_s16_b32_a64_r] = TOP_st_qualifier_space_s16_a64_r;
00264
00265 InstructionMap[TOP_setp_eq_s32] = TOP_setp_eq_s16;
00266 InstructionMap[TOP_setp_ne_s32] = TOP_setp_ne_s16;
00267 InstructionMap[TOP_setp_lt_s32] = TOP_setp_lt_s16;
00268 InstructionMap[TOP_setp_le_s32] = TOP_setp_le_s16;
00269 InstructionMap[TOP_setp_gt_s32] = TOP_setp_gt_s16;
00270 InstructionMap[TOP_setp_ge_s32] = TOP_setp_ge_s16;
00271 InstructionMap[TOP_setp_eq_u32] = TOP_setp_eq_u16;
00272 InstructionMap[TOP_setp_ne_u32] = TOP_setp_ne_u16;
00273 InstructionMap[TOP_setp_lt_u32] = TOP_setp_lt_u16;
00274 InstructionMap[TOP_setp_le_u32] = TOP_setp_le_u16;
00275 InstructionMap[TOP_setp_gt_u32] = TOP_setp_gt_u16;
00276 InstructionMap[TOP_setp_ge_u32] = TOP_setp_ge_u16;
00277 }
00278
00279 static void
00280 dump_tn_16bit_info (TN *tn)
00281 {
00282 fprintf(TFile, "TN%d(%x)", TN_number(tn), (INT) TN_16bit_flags(tn));
00283 if (TN_def_is_16bit(tn) && TN_use_is_16bit(tn))
00284 fprintf(TFile, " is def and use 16bit\n");
00285 else if (TN_def_is_16bit(tn))
00286 fprintf(TFile, " is def 16bit\n");
00287 else if (TN_use_is_16bit(tn))
00288 fprintf(TFile, " is use 16bit\n");
00289 else
00290 fprintf(TFile, "\n");
00291 }
00292
00293
00294 static BOOL
00295 OP_def_is_16bit (OP *op)
00296 {
00297 return (TOP_is_load_16in32(OP_code(op))
00298 || TOP_is_load_8in32(OP_code(op))
00299 || TOP_is_cvt_8to32(OP_code(op))
00300 || TOP_is_cvt_32to8in32(OP_code(op))
00301 || TOP_is_cvt_16to32(OP_code(op))
00302 || TOP_is_cvt_32to16in32(OP_code(op))
00303 || (OP_code(op) == TOP_mov_s32_lit
00304 && ISA_LC_Value_In_Class(TN_value(OP_opnd(op,0)), LC_i16))
00305 || (OP_code(op) == TOP_mov_u32_lit
00306 && ISA_LC_Value_In_Class(TN_value(OP_opnd(op,0)), LC_u16)) );
00307 }
00308
00309
00310 static BOOL
00311 OP_use_is_16bit (OP *op)
00312 {
00313 return (TOP_is_store_16from32(OP_code(op))
00314 || TOP_is_store_8from32(OP_code(op))
00315 || TOP_is_cvt_32to8(OP_code(op))
00316 || TOP_is_cvt_32to8in32(OP_code(op))
00317 || TOP_is_cvt_32to16(OP_code(op))
00318 || TOP_is_cvt_32to16in32(OP_code(op)) );
00319 }
00320
00321 static void
00322 Look_For_16bit_Ops (void)
00323 {
00324 BB *bb;
00325 OP *op;
00326 TN *tn;
00327 INT i;
00328 for (bb = REGION_First_BB; bb != NULL; bb = BB_next(bb)) {
00329 FOR_ALL_BB_OPs (bb, op) {
00330
00331
00332
00333 if (OP_results(op)) {
00334 tn = OP_result(op,0);
00335 if (TN_is_register(tn) && ! TN_Is_Allocatable(tn))
00336 Set_TN_def_is_not16bit(tn);
00337 }
00338 for (i = 0; i < OP_opnds(op); ++i) {
00339 tn = OP_opnd(op,i);
00340 if (TN_is_register(tn) && ! TN_Is_Allocatable(tn))
00341 Set_TN_use_is_not16bit(tn);
00342 }
00343
00344 if (OP_def_is_16bit(op)) {
00345 tn = OP_result(op,0);
00346 if (!TN_is_register(tn))
00347 continue;
00348 if (TN_def_is_not16bit(tn))
00349 continue;
00350 if (TN_use_is_not16bit(tn))
00351 continue;
00352 else if (TN_def_is_maybe16bit(tn))
00353 continue;
00354 Set_TN_def_is_16bit(tn);
00355 }
00356 else if (OP_load(op)) {
00357
00358 tn = OP_result(op,0);
00359 Set_TN_def_is_not16bit(tn);
00360 Reset_TN_def_is_16bit(tn);
00361
00362 Reset_TN_use_is_16bit(tn);
00363 }
00364 else if (OP_results(op) && TN_is_register(OP_result(op,0))) {
00365
00366 tn = OP_result(op,0);
00367 Set_TN_def_is_maybe16bit(tn);
00368 if (TN_def_is_16bit(tn))
00369 Reset_TN_def_is_16bit(tn);
00370 }
00371
00372 if (OP_use_is_16bit(op)) {
00373 if (OP_store(op))
00374 tn = OP_opnd(op, OP_find_opnd_use(op,OU_storeval) );
00375 else
00376 tn = OP_opnd(op,0);
00377 if (!TN_is_register(tn))
00378 continue;
00379 if (TN_use_is_not16bit(tn))
00380 continue;
00381 if (TN_def_is_not16bit(tn))
00382 continue;
00383 else if (TN_use_is_maybe16bit(tn))
00384 continue;
00385 Set_TN_use_is_16bit(tn);
00386 }
00387 else if (OP_store(op)) {
00388
00389 tn = OP_opnd(op, OP_find_opnd_use(op,OU_storeval) );
00390 if (!TN_is_register(tn))
00391 continue;
00392 Set_TN_use_is_not16bit(tn);
00393 Reset_TN_use_is_16bit(tn);
00394
00395 Reset_TN_def_is_16bit(tn);
00396 }
00397 else {
00398
00399 for (i = 0; i < OP_opnds(op); ++i) {
00400 tn = OP_opnd(op,i);
00401 if (!TN_is_register(tn))
00402 continue;
00403 Set_TN_use_is_maybe16bit(tn);
00404 if (TN_use_is_16bit(tn))
00405 Reset_TN_use_is_16bit(tn);
00406 }
00407 }
00408 }
00409 }
00410 }
00411
00412 static void
00413 Propagate_16bit_Info (void)
00414 {
00415 BB *bb;
00416 OP *op;
00417 TN *tn;
00418 INT i;
00419 INT changed;
00420 INT count = 0;
00421 BOOL okay;
00422
00423 do {
00424 changed = 0;
00425
00426
00427 for (i = First_Regular_TN; i <= Last_TN; ++i) {
00428 tn = TNvec(i);
00429 Reset_TN_def_is_maybe16bit(tn);
00430 Reset_TN_use_is_maybe16bit(tn);
00431 }
00432
00433 for (bb = REGION_First_BB; bb != NULL; bb = BB_next(bb)) {
00434
00435 FOR_ALL_BB_OPs_REV (bb, op) {
00436 if (OP_use_is_16bit(op)) {
00437 okay = TRUE;
00438 }
00439
00440
00441
00442 else if (TOP_is_mul_lo_32(OP_code(op)))
00443 {
00444 okay = TRUE;
00445 if ( TN_use_is_16bit(OP_result(op,0)))
00446 ;
00447 else {
00448
00449 for (i = 0; i < OP_opnds(op); ++i) {
00450 TN *otn = OP_opnd(op,i);
00451 if (TN_is_register(otn) && TN_def_is_16bit(otn))
00452 ;
00453 else if (TN_has_value(otn)
00454 && ISA_LC_Value_In_Class(TN_value(otn),
00455 (OP_opnd_is_signed(op,i) ? LC_i16 : LC_u16) ) )
00456 ;
00457 else
00458 okay = FALSE;
00459 }
00460 }
00461 }
00462
00463 else if (TOP_is_convertible_to16_if_out16(OP_code(op)))
00464 {
00465 okay = TRUE;
00466 if (OP_results(op) == 0)
00467 okay = FALSE;
00468 tn = OP_result(op,0);
00469 if (!TN_is_register(tn))
00470 okay = FALSE;
00471 if (!TN_use_is_16bit(tn))
00472 okay = FALSE;
00473 }
00474
00475
00476 else if (TOP_is_compare_32(OP_code(op)))
00477 {
00478 okay = TRUE;
00479 for (i = 0; i < OP_opnds(op); ++i) {
00480 TN *otn = OP_opnd(op,i);
00481 if (TN_is_register(otn) && TN_def_is_16bit(otn))
00482 ;
00483 else if (TN_has_value(otn)
00484 && ISA_LC_Value_In_Class(TN_value(otn),
00485 (OP_opnd_is_signed(op,i) ? LC_i16 : LC_u16) ) )
00486 ;
00487 else
00488 okay = FALSE;
00489 }
00490 }
00491
00492
00493
00494
00495 else if (TOP_is_convertible_to16_if_in16(OP_code(op)))
00496 {
00497 okay = TRUE;
00498 if (OP_results(op)) {
00499 tn = OP_result(op,0);
00500 if (TN_is_register(tn) && !TN_use_is_16bit(tn))
00501 okay = FALSE;
00502 }
00503 for (i = 0; i < OP_opnds(op); ++i) {
00504 TN *otn = OP_opnd(op,i);
00505 if (TN_is_register(otn) && TN_def_is_16bit(otn))
00506 ;
00507 else if (TN_has_value(otn)
00508 && ISA_LC_Value_In_Class(TN_value(otn),
00509 (OP_opnd_is_signed(op,i) ? LC_i16 : LC_u16) ) )
00510 ;
00511 else
00512 okay = FALSE;
00513 }
00514 }
00515 else {
00516 okay = FALSE;
00517 }
00518 for (i = 0; i < OP_opnds(op); ++i) {
00519 tn = OP_opnd(op,i);
00520 if (!TN_is_register(tn))
00521 continue;
00522 if (okay) {
00523 if (TN_use_is_16bit(tn))
00524 continue;
00525 if (TN_use_is_not16bit(tn))
00526 continue;
00527 if (TN_def_is_not16bit(tn))
00528 continue;
00529 if (TN_use_is_maybe16bit(tn))
00530 continue;
00531 Set_TN_use_is_16bit(tn);
00532 ++changed;
00533 }
00534 else {
00535 Set_TN_use_is_maybe16bit(tn);
00536 if (TN_use_is_16bit(tn)) {
00537 Reset_TN_use_is_16bit(tn);
00538 --changed;
00539 }
00540 }
00541 }
00542 }
00543
00544
00545 FOR_ALL_BB_OPs_FWD (bb, op) {
00546 if (OP_results(op) == 0)
00547 continue;
00548 tn = OP_result(op,0);
00549 if (!TN_is_register(tn))
00550 continue;
00551 if (TN_def_is_not16bit(tn))
00552 continue;
00553 if (TN_use_is_not16bit(tn))
00554 continue;
00555
00556 if (OP_def_is_16bit(op)) {
00557 okay = TRUE;
00558 }
00559
00560 else if (TOP_is_convertible_to16_if_in16(OP_code(op)))
00561 {
00562 okay = TRUE;
00563 for (i = 0; i < OP_opnds(op); ++i) {
00564 TN *otn = OP_opnd(op,i);
00565 if (TN_is_register(otn) && TN_def_is_16bit(otn))
00566 ;
00567 else if (TN_has_value(otn)
00568 && ISA_LC_Value_In_Class(TN_value(otn),
00569 (OP_opnd_is_signed(op,i) ? LC_i16 : LC_u16) ) )
00570 ;
00571 else
00572 okay = FALSE;
00573 }
00574 }
00575
00576
00577
00578
00579
00580 else if (TOP_is_convertible_to16_if_out16(OP_code(op))
00581 && TN_use_is_16bit(tn) )
00582 {
00583 okay = TRUE;
00584 for (i = 0; i < OP_opnds(op); ++i) {
00585 TN *otn = OP_opnd(op,i);
00586 if (TN_is_register(otn) && TN_def_is_16bit(otn))
00587 ;
00588 else if (TN_has_value(otn)
00589 && ISA_LC_Value_In_Class(TN_value(otn),
00590 (OP_opnd_is_signed(op,i) ? LC_i16 : LC_u16) ) )
00591 ;
00592 else
00593 okay = FALSE;
00594 }
00595 }
00596 else {
00597 okay = FALSE;
00598 }
00599 if (okay && !TN_def_is_16bit(tn) && !TN_def_is_maybe16bit(tn)) {
00600 Set_TN_def_is_16bit(tn);
00601 ++changed;
00602 }
00603 else if (!okay) {
00604 Set_TN_def_is_maybe16bit(tn);
00605 if (TN_def_is_16bit(tn)) {
00606 Reset_TN_def_is_16bit(tn);
00607 --changed;
00608 }
00609 }
00610 }
00611 }
00612
00613 ++count;
00614 FmtAssert(count < 50, ("shouldn't iterate this much"));
00615 } while (changed);
00616 if (count > 3) DevWarn("propagate iterations = %d", count);
00617 if (tracing) {
00618 for (INT i = First_Regular_TN; i <= Last_TN; ++i) {
00619 dump_tn_16bit_info(TNvec(i));
00620 }
00621 }
00622 }
00623
00624
00625
00626
00627
00628 static BOOL
00629 Unpropagate_Unusable_16bit_Info (void)
00630 {
00631 BB *bb;
00632 OP *op;
00633 TN *tn;
00634 INT i;
00635 INT count = 0;
00636 INT changed;
00637
00638 do {
00639 changed = 0;
00640 for (bb = REGION_First_BB; bb != NULL; bb = BB_next(bb)) {
00641 FOR_ALL_BB_OPs (bb, op) {
00642 BOOL has_16bit_tn = FALSE;
00643 BOOL has_32bit_tn = FALSE;
00644 for (i = 0; i < OP_results(op); ++i) {
00645 tn = OP_result(op,i);
00646 if (!TN_is_register(tn))
00647 continue;
00648 if (TN_register_class(tn) != ISA_REGISTER_CLASS_integer)
00649 continue;
00650 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn))
00651 has_16bit_tn = TRUE;
00652 else if (TOP_is_cvt_32to16in32(OP_code(op))
00653 || TOP_is_cvt_32to8in32(OP_code(op)))
00654
00655
00656
00657
00658 ;
00659 else if (TOP_is_mul_lo_32(OP_code(op)))
00660
00661
00662 ;
00663 else
00664 has_32bit_tn = TRUE;
00665 }
00666 for (i = 0; i < OP_opnds(op); ++i) {
00667 tn = OP_opnd(op,i);
00668 if (!TN_is_register(tn))
00669 continue;
00670 if (TN_register_class(tn) != ISA_REGISTER_CLASS_integer)
00671 continue;
00672 if (OP_opnd_use(op,i) == OU_base)
00673 continue;
00674 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn))
00675 has_16bit_tn = TRUE;
00676 else
00677 has_32bit_tn = TRUE;
00678 }
00679 if (has_16bit_tn && has_32bit_tn) {
00680 if (tracing) {
00681 fprintf(TFile, "has 16bit tn mixed with 32bit tns:\n");
00682 Print_OP_No_SrcLine(op);
00683 }
00684 for (i = 0; i < OP_results(op); ++i) {
00685 tn = OP_result(op,i);
00686 if (!TN_is_register(tn))
00687 continue;
00688 if (TN_register_class(tn) != ISA_REGISTER_CLASS_integer)
00689 continue;
00690 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn)) {
00691 Reset_TN_use_is_16bit(tn);
00692 ++changed;
00693 }
00694 }
00695 for (i = 0; i < OP_opnds(op); ++i) {
00696 tn = OP_opnd(op,i);
00697 if (!TN_is_register(tn))
00698 continue;
00699 if (TN_register_class(tn) != ISA_REGISTER_CLASS_integer)
00700 continue;
00701 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn)) {
00702 Reset_TN_use_is_16bit(tn);
00703 ++changed;
00704 }
00705 }
00706 }
00707 }
00708 }
00709 ++count;
00710 FmtAssert(count < 50, ("shouldn't iterate this much"));
00711 } while (changed);
00712 if (count > 3) DevWarn("unpropagate iterations = %d", count);
00713 }
00714
00715
00716 static void
00717 Modify_16bit_TNs (void)
00718 {
00719 INT i;
00720 TN *tn;
00721 for (i = First_Regular_TN; i <= Last_TN; ++i) {
00722 tn = TNvec(i);
00723 if (tracing) dump_tn_16bit_info(tn);
00724 if (TN_def_is_16bit(tn) && TN_use_is_16bit(tn)
00725 && TN_register_class(tn) == ISA_REGISTER_CLASS_integer)
00726 {
00727 Set_TN_register_class(tn, ISA_REGISTER_CLASS_integer16);
00728 }
00729 }
00730 }
00731
00732
00733
00734 static void
00735 Modify_16bit_Ops (void)
00736 {
00737 BB *bb;
00738 OP *op;
00739 TN *tn;
00740 INT i;
00741 BOOL newop = FALSE;
00742 INT count = 0;
00743
00744 for (bb = REGION_First_BB; bb != NULL; bb = BB_next(bb)) {
00745 FOR_ALL_BB_OPs (bb, op) {
00746 TOP new_opc = InstructionMap[OP_code(op)];
00747 BOOL def_okay = TRUE;
00748 BOOL use_okay = TRUE;
00749 BOOL tn_def_is_16bit = FALSE;
00750 BOOL tn_use_is_16bit = FALSE;
00751 if (newop) {
00752
00753 newop = FALSE;
00754 continue;
00755 }
00756 for (i = 0; i < OP_results(op); ++i) {
00757 tn = OP_result(op,i);
00758 if (!TN_is_register(tn))
00759 continue;
00760 if (TN_register_class(tn) == ISA_REGISTER_CLASS_predicate)
00761 continue;
00762 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn))
00763 tn_def_is_16bit = TRUE;
00764 else if (TN_register_class(tn) == ISA_REGISTER_CLASS_integer16)
00765 continue;
00766 else
00767 def_okay = FALSE;
00768 }
00769 for (i = 0; i < OP_opnds(op); ++i) {
00770 if (OP_opnd_use(op,i) == OU_base)
00771 continue;
00772 tn = OP_opnd(op,i);
00773 if (TN_is_register(tn)) {
00774 if (OP_opnd_use(op, i) == OU_base)
00775 continue;
00776 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn))
00777 tn_use_is_16bit = TRUE;
00778 else if (TN_register_class(tn) == ISA_REGISTER_CLASS_integer16)
00779 continue;
00780 else
00781 use_okay = FALSE;
00782 }
00783 else if (TN_has_value(tn)
00784 && ISA_LC_Value_In_Class(TN_value(tn),
00785 (OP_opnd_is_signed(op,i) ? LC_i16 : LC_u16) ) )
00786 ;
00787 else if (TN_is_enum(tn))
00788 ;
00789 else {
00790 use_okay = FALSE;
00791 }
00792 }
00793
00794 if (CG_skip_local_16bit &&
00795 ((count < CG_local_skip_before) ||
00796 (count > CG_local_skip_after) ||
00797 (count == CG_local_skip_equal)))
00798 {
00799
00800
00801
00802 if (def_okay && use_okay && new_opc)
00803 ++count;
00804 else if (use_okay && TOP_is_mul_lo_32(OP_code(op)))
00805 ++count;
00806 use_okay = FALSE;
00807 def_okay = FALSE;
00808 }
00809
00810 if (def_okay && use_okay && new_opc) {
00811 if (tracing) {
00812 fprintf(TFile, "change op to 16bit %s\n", TOP_Name(new_opc));
00813 Print_OP_No_SrcLine(op);
00814 }
00815 OP_Change_Opcode(op, new_opc);
00816 ++count;
00817 }
00818 else if (use_okay && TOP_is_mul_lo_32(OP_code(op)))
00819 {
00820
00821 switch (OP_code(op)) {
00822 case TOP_mul_lo_s32: new_opc = TOP_mul_wide_s16; break;
00823 case TOP_mul_lo_u32: new_opc = TOP_mul_wide_u16; break;
00824 case TOP_mul_lo_s32_lit: new_opc = TOP_mul_wide_s16_lit; break;
00825 case TOP_mul_lo_u32_lit: new_opc = TOP_mul_wide_u16_lit; break;
00826 }
00827 if (tracing) {
00828 fprintf(TFile, "change op to mul.wide %s\n", TOP_Name(new_opc));
00829 Print_OP_No_SrcLine(op);
00830 }
00831 OP_Change_Opcode(op, new_opc);
00832 ++count;
00833 }
00834 else if (tn_def_is_16bit || tn_use_is_16bit) {
00835 DevWarn("16bit tn in unchanged op");
00836 if (tracing) {
00837 fprintf(TFile, "modified tn in unchanged op, will add converts:\n");
00838 Print_OP_No_SrcLine(op);
00839 }
00840 if (tn_def_is_16bit) {
00841
00842 for (i = 0; i < OP_results(op); ++i) {
00843 tn = OP_result(op,i);
00844 if (!TN_is_register(tn))
00845 continue;
00846 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn)) {
00847 OPS ops = OPS_EMPTY;
00848 TN *tmp = Build_RCLASS_TN (ISA_REGISTER_CLASS_integer);
00849 Set_OP_result(op,i,tmp);
00850 Build_OP (TOP_cvt_u16_u32, tn, tmp, &ops);
00851 OP_srcpos(OPS_last(&ops)) = OP_srcpos(op);
00852 BB_Insert_Ops_After(bb, op, &ops);
00853 newop = TRUE;
00854 }
00855 }
00856 }
00857 if (tn_use_is_16bit) {
00858
00859 for (i = 0; i < OP_opnds(op); ++i) {
00860 tn = OP_opnd(op,i);
00861 if (!TN_is_register(tn))
00862 continue;
00863 if (TN_use_is_16bit(tn) && TN_def_is_16bit(tn)) {
00864 OPS ops = OPS_EMPTY;
00865 TN *tmp = Build_RCLASS_TN (ISA_REGISTER_CLASS_integer);
00866 Set_OP_opnd(op,i,tmp);
00867 Build_OP (TOP_cvt_u32_u16, tmp, tn, &ops);
00868 OP_srcpos(OPS_last(&ops)) = OP_srcpos(op);
00869 BB_Insert_Ops_Before(bb, op, &ops);
00870 }
00871 }
00872 }
00873 }
00874 }
00875 }
00876 if (count > 0) DevWarn("changed %d ops to 16bit", count);
00877 }
00878
00879
00880
00881
00882
00883
00884 static void
00885 Modify_24bit_Muls (void)
00886 {
00887 BB *bb;
00888 OP *op;
00889 TN *tn;
00890 INT64 val;
00891 for (bb = REGION_First_BB; bb != NULL; bb = BB_next(bb)) {
00892 FOR_ALL_BB_OPs (bb, op) {
00893 switch (OP_code(op)) {
00894 case TOP_mul_lo_s32_lit:
00895 tn = OP_opnd(op,0);
00896 if (!TN_def_is_16bit(tn))
00897 continue;
00898 val = TN_value(OP_opnd(op,1));
00899 if (ISA_LC_Value_In_Class(val, LC_i8)) {
00900 if (tracing) {
00901 fprintf(TFile, "can use 24bit mul\n");
00902 Print_OP_No_SrcLine(op);
00903 }
00904 OP_Change_Opcode(op, TOP_mul24_lo_s32_lit);
00905 }
00906 break;
00907 case TOP_mul_lo_u32_lit:
00908 tn = OP_opnd(op,0);
00909 if (!TN_def_is_16bit(tn))
00910 continue;
00911 val = TN_value(OP_opnd(op,1));
00912 if (ISA_LC_Value_In_Class(val, LC_u8)) {
00913 if (tracing) {
00914 fprintf(TFile, "can use 24bit mul\n");
00915 Print_OP_No_SrcLine(op);
00916 }
00917 OP_Change_Opcode(op, TOP_mul24_lo_u32_lit);
00918 }
00919 break;
00920 }
00921 }
00922 }
00923 }
00924
00925 void
00926 Use_16bit_Ops (void)
00927 {
00928 tracing = Get_Trace(TP_EBO, 0x1000);
00929 tn_16bit_map = TN_MAP_Create();
00930 Create_Instruction_Map();
00931
00932 Look_For_16bit_Ops ();
00933 Propagate_16bit_Info ();
00934 Unpropagate_Unusable_16bit_Info ();
00935 Modify_16bit_TNs ();
00936 Modify_16bit_Ops ();
00937 Modify_24bit_Muls ();
00938
00939 InstructionMap.clear();
00940 TN_MAP_Delete(tn_16bit_map);
00941 }
00942