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 #include "defs.h"
00071 #include "config.h"
00072 #include "config_asm.h"
00073 #include "config_debug.h"
00074 #include "config_targ_opt.h"
00075 #include "config_opt.h"
00076 #include "config_list.h"
00077 #include "config_vho.h"
00078 #include "config_wopt.h"
00079 #include "erglob.h"
00080 #include "tracing.h"
00081 #include "mtypes.h"
00082 #include "stab.h"
00083 #include "targ_sim.h"
00084
00085 #if defined(FRONT_END_C) || defined(FRONT_END_CPLUSPLUS)
00086 typedef unsigned char an_integer_kind;
00087 #include "c_int_model.h"
00088 #endif
00089
00090 extern char *Ofast;
00091
00092
00093
00094 BOOL ARCH_generate_nor = FALSE;
00095 BOOL ARCH_mask_shift_counts = FALSE;
00096
00097
00098 TARGET_ABI Target_ABI = ABI_UNDEF;
00099 TARGET_PROCESSOR Target = TARGET_UNDEF;
00100 TARGET_ISA Target_ISA = TARGET_ISA_UNDEF;
00101
00102
00103
00104
00105 CLASS_INDEX Spill_Int_Mtype = 0;
00106 CLASS_INDEX Spill_Float_Mtype = 0;
00107 CLASS_INDEX Spill_Int32_Mtype = 0;
00108 CLASS_INDEX Spill_Float32_Mtype = 0;
00109
00110
00111
00112
00113 CLASS_INDEX Max_Int_Mtype = 0;
00114 CLASS_INDEX Max_Uint_Mtype = 0;
00115 CLASS_INDEX Def_Int_Mtype = 0;
00116 CLASS_INDEX Def_Uint_Mtype = 0;
00117
00118
00119 BOOL Use_32_Bit_Pointers = FALSE;
00120
00121
00122 INT Pointer_Size;
00123 CLASS_INDEX Pointer_Mtype;
00124 CLASS_INDEX Pointer_Mtype2;
00125
00126
00127 TYPE_ID Pointer_type;
00128 TYPE_ID Pointer_type2;
00129 TYPE_ID Boolean_type;
00130 TYPE_ID Boolean_type2;
00131 TYPE_ID Integer_type;
00132
00133
00134 INT Comparison_Result_Size;
00135 CLASS_INDEX Comparison_Result_Mtype;
00136
00137
00138
00139
00140 char *AS_ADDRESS;
00141 char *AS_ADDRESS_UNALIGNED;
00142
00143
00144 BOOL Char_Type_Is_Signed = FALSE;
00145
00146
00147 static BOOL Target_int64;
00148
00149
00150 #define FPX_DEF EXC_ALL
00151 INT16 FP_Exception_Enable_Max = FPX_DEF;
00152 INT16 FP_Exception_Enable_Min = 0;
00153
00154 INT32 Align_Instructions = 0;
00155 BOOL Avoid_TFP_blikely_bug = FALSE;
00156 BOOL Avoid_TFP_blikely_bug_overridden = FALSE;
00157
00158
00159 BOOL Force_IEEE_Comparisons = TRUE;
00160
00161
00162
00163 BOOL WHIRL_Return_Val_On = TRUE;
00164 BOOL WHIRL_Mldid_Mstid_On = TRUE;
00165 BOOL WHIRL_Return_Info_On = TRUE;
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 INT16 Symbolic_Debug_Mode;
00181 INT16 Max_Symbolic_Debug_Mode;
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 BOOL Allow_Word_Aligned_Doubles = FALSE;
00193
00194
00195 BOOL Generate_Position_Independent_Code = FALSE;
00196
00197
00198 BOOL Split_64_Bit_Int_Ops = FALSE;
00199
00200
00201 BOOL Split_Quad_Ops = TRUE;
00202
00203
00204 BOOL Simulate_32_Bit_Interface = FALSE;
00205
00206
00207 BOOL No_Quad_Aligned_Branch = FALSE;
00208
00209
00210 BOOL Only_Unsigned_64_Bit_Ops = FALSE;
00211
00212 BOOL Has_GP_Groups = FALSE;
00213
00214
00215
00216
00217 BOOL Use_Load_Store_Offset = TRUE;
00218
00219 #if defined (FRONT_END_C) || defined (FRONT_END_CPLUSPLUS)
00220
00221
00222
00223 PREG_NUM Map_Reg_To_Preg [] = {
00224 0x001 ,
00225 0x007 ,
00226 0x008 ,
00227 0x002 ,
00228 0x006 ,
00229 0x005 ,
00230 0x003 ,
00231 0x004 ,
00232 0x021 ,
00233 0x022 ,
00234 0x023 ,
00235 0x024 ,
00236 0x025 ,
00237 0x026 ,
00238 0x027 ,
00239 0x028 ,
00240 -1 ,
00241 -1 ,
00242 -1 ,
00243 -1 ,
00244 -1 ,
00245 0x011 ,
00246 0x012 ,
00247 0x013 ,
00248 0x014 ,
00249 0x015 ,
00250 0x016 ,
00251 0x017 ,
00252 0x018 ,
00253 -1 ,
00254 -1 ,
00255 -1 ,
00256 -1 ,
00257 -1 ,
00258 -1 ,
00259 -1 ,
00260 -1 ,
00261 0x009 ,
00262 0x00a ,
00263 0x00b ,
00264 0x00c ,
00265 0x00d ,
00266 0x00e ,
00267 0x00f ,
00268 0x010 ,
00269 0x019 ,
00270 0x01a ,
00271 0x01b ,
00272 0x01c ,
00273 0x01d ,
00274 0x01e ,
00275 0x01f ,
00276 0x020 ,
00277 -1
00278 };
00279
00280 #endif
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 static struct bnm {
00293 char name[16];
00294 } bnb[4];
00295 static INT16 bnb_used = 0;
00296
00297 #ifndef MONGOOSE_BE
00298 char *
00299 Abi_Name ( TARGET_ABI b)
00300 {
00301 char *r;
00302
00303 switch ( b ) {
00304 case ABI_n32: return "n32";
00305 case ABI_n64: return "n64";
00306 case ABI_w64: return "w64";
00307 default:
00308 r = bnb[bnb_used].name;
00309 bnb_used = (bnb_used + 1) % 4;
00310 sprintf (r, "ABI_%d", b);
00311 return r;
00312 }
00313 }
00314 #endif
00315
00316 char *
00317 Isa_Name ( TARGET_ISA b)
00318 {
00319 char *r;
00320
00321 switch ( b ) {
00322 case TARGET_ISA_compute_10:
00323 return "sm_10";
00324 case TARGET_ISA_compute_11:
00325 return "sm_11";
00326 case TARGET_ISA_compute_12:
00327 return "sm_12";
00328 case TARGET_ISA_compute_13:
00329 return "sm_13";
00330 case TARGET_ISA_compute_14:
00331 return "sm_14";
00332 case TARGET_ISA_compute_15:
00333 return "sm_15";
00334 default:
00335 r = bnb[bnb_used].name;
00336 bnb_used = (bnb_used + 1) % 4;
00337 sprintf (r, "ISA_%d", b);
00338 return r;
00339 }
00340 }
00341
00342 char *
00343 Targ_Name ( TARGET_PROCESSOR b)
00344 {
00345 char *r;
00346
00347 switch ( b ) {
00348 case TARGET_nvisa: return "ptx";
00349 default:
00350 r = bnb[bnb_used].name;
00351 bnb_used = (bnb_used + 1) % 4;
00352 sprintf (r, "PROCESSOR_%d", b);
00353 return r;
00354 }
00355 }
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 void
00367 Preconfigure_Target ( void )
00368 {
00369
00370 List_Software_Names = TRUE;
00371 List_Source = FALSE;
00372
00373 WOPT_Enable_DIVREM = FALSE;
00374 WOPT_Enable_MINMAX = FALSE;
00375 WOPT_Enable_Const_PRE = FALSE;
00376 WOPT_Enable_Aggressive_Code_Motion = FALSE;
00377 CIS_Allowed = FALSE;
00378 OPT_Lower_To_Memlib = FALSE;
00379 VHO_Switch_If_Else_Limit = 4096;
00380 Recip_Allowed = TRUE;
00381 Rsqrt_Allowed = TRUE;
00382 WOPT_Enable_CFG_Opt = FALSE;
00383 WOPT_Enable_Goto = FALSE;
00384 WOPT_Enable_WN_Unroll = 2;
00385 WOPT_Enable_Cvt_Folding = FALSE;
00386 Olimit = 30000;
00387 WOPT_Enable_Folded_Scalar_Limit = 4000;
00388 UseAlignedCopyForStructs = TRUE;
00389 return;
00390 }
00391
00392
00393
00394
00395 static void Adjust_m32_MTYPE_Info()
00396 {
00397 return;
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 static void
00421 Prepare_Target ( void )
00422 {
00423
00424
00425
00426 TARGET_ISA isa = TARGET_ISA_compute_10;
00427 TARGET_PROCESSOR targ = TARGET_nvisa;
00428 Target_ABI = ABI_n32;
00429
00430
00431
00432 if ( ABI_Name != NULL ) {
00433 if ( strcmp ( ABI_Name, "n64" ) == 0 ) {
00434 Target_ABI = ABI_n64;
00435 } else if( strcmp( ABI_Name, "w64" ) == 0 ){
00436 Target_ABI = ABI_w64;
00437 } else if( strcmp( ABI_Name, "n32" ) == 0 ){
00438 Target_ABI = ABI_n32;
00439 } else {
00440 ErrMsg ( EC_Inv_TARG, "abi", ABI_Name );
00441 }
00442 }
00443
00444
00445 if ( ISA_Name != NULL ) {
00446
00447 if ( strcasecmp ( ISA_Name, "compute_10" ) == 0) {
00448 isa = TARGET_ISA_compute_10;
00449 }
00450 else if ( strcasecmp ( ISA_Name, "compute_11" ) == 0 ) {
00451 isa = TARGET_ISA_compute_11;
00452 }
00453 else if ( strcasecmp ( ISA_Name, "compute_12" ) == 0 ) {
00454 isa = TARGET_ISA_compute_12;
00455 }
00456 else if ( strcasecmp ( ISA_Name, "compute_13" ) == 0 ) {
00457 isa = TARGET_ISA_compute_13;
00458 }
00459 else if ( strcasecmp ( ISA_Name, "compute_14" ) == 0 ) {
00460 isa = TARGET_ISA_compute_14;
00461 }
00462 else if ( strcasecmp ( ISA_Name, "compute_15" ) == 0 ) {
00463 isa = TARGET_ISA_compute_15;
00464 }
00465 else if ( strcasecmp ( ISA_Name, "sm_10" ) == 0) {
00466 isa = TARGET_ISA_compute_10;
00467 }
00468 else if ( strcasecmp ( ISA_Name, "sm_11" ) == 0 ) {
00469 isa = TARGET_ISA_compute_11;
00470 }
00471 else if ( strcasecmp ( ISA_Name, "sm_12" ) == 0 ) {
00472 isa = TARGET_ISA_compute_12;
00473 }
00474 else if ( strcasecmp ( ISA_Name, "sm_13" ) == 0 ) {
00475 isa = TARGET_ISA_compute_13;
00476 }
00477 else if ( strcasecmp ( ISA_Name, "sm_14" ) == 0 ) {
00478 isa = TARGET_ISA_compute_14;
00479 }
00480 else if ( strcasecmp ( ISA_Name, "sm_15" ) == 0 ) {
00481 isa = TARGET_ISA_compute_15;
00482 }
00483 else {
00484 ErrMsg ( EC_Inv_TARG, "isa", ISA_Name );
00485 }
00486
00487
00488 if ( Target_ISA != TARGET_ISA_UNDEF && Target_ISA != isa ) {
00489 ErrMsg ( EC_Incons_TARG, "isa", ISA_Name,
00490 "isa", Isa_Name(Target_ISA) );
00491 }
00492 }
00493 Target_ISA = isa;
00494
00495 #if 0
00496
00497
00498
00499 switch ( Target_ISA ) {
00500 case TARGET_ISA_UNDEF:
00501 Target_ISA = ..;
00502 break;
00503 }
00504 #endif
00505
00506
00507 if ( Processor_Name != NULL ) {
00508 if ( strcasecmp ( Processor_Name, "nvisa" ) == 0 ) {
00509 targ = TARGET_nvisa;
00510 }
00511 else {
00512 ErrMsg ( EC_Inv_TARG, "processor", Processor_Name );
00513 targ = TARGET_UNDEF;
00514 }
00515
00516
00517 if ( Target != TARGET_UNDEF && Target != targ ) {
00518 ErrMsg ( EC_Incons_TARG, "processor", Processor_Name,
00519 "processor", Targ_Name(Target) );
00520 }
00521 }
00522 Target = targ;
00523
00524
00525 switch ( Target_FPRs ) {
00526 default:
00527 ErrMsg ( EC_Inv_FPRs, Target_FPRs );
00528
00529 case 0:
00530 Target_FPRs = 128;
00531 break;
00532 case 16:
00533 ErrMsg ( EC_FPR_16 );
00534 break;
00535 case 32:
00536 ErrMsg ( EC_FPR_32 );
00537 break;
00538 }
00539
00540
00541 Target_int64 = TRUE;
00542 Use_32_Bit_Pointers = (Target_ABI == ABI_n32);
00543
00544 if( Target_ABI == ABI_n32 ){
00545 Adjust_m32_MTYPE_Info();
00546 }
00547
00548 #if defined(FRONT_END_C) || defined(FRONT_END_CPLUSPLUS)
00549 if (Target_ABI == ABI_n64)
00550 Target_Int_Model = TARGET_INT_LP64;
00551 else if (Target_ABI == ABI_w64)
00552 Target_Int_Model = TARGET_INT_P64;
00553 else
00554 Target_Int_Model = TARGET_INT_ILP32;
00555 Make_Int_Model_Consistent ();
00556 #endif
00557 }
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568 void
00569 Configure_Target ( void )
00570 {
00571
00572 Target_Byte_Sex = LITTLE_ENDIAN;
00573 Same_Byte_Sex = ( Target_Byte_Sex == Host_Byte_Sex );
00574
00575 Gen_PIC_Calls = FALSE;
00576 GP_Is_Preserved = FALSE;
00577
00578
00579 Prepare_Target ();
00580
00581
00582 if (OPT_unroll_times > 0 && !OPT_unroll_times_overridden && !OPT_Space)
00583 OPT_unroll_times = 16;
00584
00585
00586 Spill_Int_Mtype = Is_Target_64bit() ? MTYPE_I8 : MTYPE_I4;
00587 Spill_Float_Mtype = MTYPE_F4;
00588 Spill_Int32_Mtype = MTYPE_I4;
00589 Spill_Float32_Mtype = MTYPE_F4;
00590 Max_Int_Mtype = Def_Int_Mtype = Is_Target_64bit() ? MTYPE_I8 : MTYPE_I4;
00591 Max_Uint_Mtype = Def_Uint_Mtype = Is_Target_64bit() ? MTYPE_U8 : MTYPE_U4;
00592 Boolean_type = MTYPE_I4;
00593 Boolean_type2 = MTYPE_I4;
00594 Integer_type = MTYPE_I4;
00595
00596 Split_Quad_Ops = TRUE;
00597 Split_64_Bit_Int_Ops = FALSE;
00598
00599 #if defined(FRONT_END_C) || defined(FRONT_END_CPLUSPLUS)
00600 #ifndef EDG_FORTRAN
00601 Make_Int_Model_Consistent();
00602 #endif
00603 #endif
00604
00605
00606
00607 if ( Use_32_Bit_Pointers ) {
00608 Pointer_Size = 4;
00609 Pointer_Mtype = WHIRL_Mtype_A_On ? MTYPE_A4 : MTYPE_U4;
00610 Pointer_type = Pointer_Mtype;
00611 Pointer_Mtype2 = MTYPE_U4;
00612 Pointer_type2 = MTYPE_U4;
00613 } else {
00614 Pointer_Size = 8;
00615 Pointer_Mtype = WHIRL_Mtype_A_On ? MTYPE_A8: MTYPE_U8;
00616 Pointer_type = Pointer_Mtype;
00617 Pointer_Mtype2 = MTYPE_U8;
00618 Pointer_type2 = MTYPE_U8;
00619 }
00620
00621 if ( Use_32_Bit_Pointers ) {
00622 AS_ADDRESS = AS_WORD;
00623 AS_ADDRESS_UNALIGNED = AS_WORD;
00624 } else {
00625 AS_ADDRESS = AS_DWORD;
00626 AS_ADDRESS_UNALIGNED = AS_DWORD_UNALIGNED;
00627 }
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 if ( Aggregate_Alignment > 0 ) {
00638 INT32 i = 1;
00639 while ( i < Aggregate_Alignment ) i <<= 1;
00640 Aggregate_Alignment = i;
00641
00642 if (Aggregate_Alignment < (Target_int64 ? 8 : 4))
00643 {
00644 Align_Object = FALSE;
00645 }
00646 }
00647
00648 #if defined(BACK_END)
00649 Init_Targ_Sim();
00650 #endif
00651
00652 #define IS_POW2(n) (((n) & ((n)-1))==0)
00653 FmtAssert (IS_POW2(Align_Instructions),
00654 ("-OPT:align_instructions=<n> must equal power of two"));
00655
00656 if ( Target_ISA >= TARGET_ISA_compute_13 ) {
00657 FP_Double = TRUE;
00658 }
00659
00660 return;
00661 }
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672 void
00673 IPA_Configure_Target (void)
00674 {
00675 if (Target_ABI == ABI_n32) {
00676 Pointer_Size = 4;
00677 Pointer_Mtype = WHIRL_Mtype_A_On ? MTYPE_A4 : MTYPE_U4;
00678 Pointer_type = Pointer_Mtype;
00679 Pointer_Mtype2 = MTYPE_U4;
00680 Pointer_type2 = MTYPE_U4;
00681 Split_64_Bit_Int_Ops = TRUE;
00682
00683 Adjust_m32_MTYPE_Info();
00684 } else {
00685 Pointer_Size = 8;
00686 Pointer_Mtype = WHIRL_Mtype_A_On ? MTYPE_A8 : MTYPE_U8;
00687 Pointer_type = Pointer_Mtype;
00688 Pointer_Mtype2 = MTYPE_U8;
00689 Pointer_type2 = MTYPE_U8;
00690 Split_64_Bit_Int_Ops = FALSE;
00691 }
00692
00693 Integer_type = MTYPE_I4;
00694 Boolean_type = MTYPE_I4;
00695 Boolean_type2 = MTYPE_I4;
00696
00697 }
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 void
00709 Configure_Source_Target ( char * )
00710 {
00711 char *option;
00712
00713
00714
00715 Indexed_Loads_Allowed = FALSE;
00716
00717
00718 if ( Kernel_Code ) {
00719 Zeroinit_in_bss = FALSE;
00720 }
00721
00722
00723 if ( FP_Excp_Max != NULL ) {
00724 FP_Exception_Enable_Max = 0;
00725 option = FP_Excp_Max;
00726 while ( *option ) {
00727 switch ( *option ) {
00728 case 'I': FP_Exception_Enable_Max |= FPX_I; break;
00729 case 'U': FP_Exception_Enable_Max |= FPX_U; break;
00730 case 'O': FP_Exception_Enable_Max |= FPX_O; break;
00731 case 'Z': FP_Exception_Enable_Max |= FPX_Z; break;
00732 case 'V': FP_Exception_Enable_Max |= FPX_V; break;
00733 }
00734 option++;
00735 }
00736 }
00737 if ( FP_Excp_Min != NULL ) {
00738 FP_Exception_Enable_Min = 0;
00739 option = FP_Excp_Min;
00740 while ( *option ) {
00741 switch ( *option ) {
00742 case 'I': FP_Exception_Enable_Min |= FPX_I; break;
00743 case 'U': FP_Exception_Enable_Min |= FPX_U; break;
00744 case 'O': FP_Exception_Enable_Min |= FPX_O; break;
00745 case 'Z': FP_Exception_Enable_Min |= FPX_Z; break;
00746 case 'V': FP_Exception_Enable_Min |= FPX_V; break;
00747 }
00748 option++;
00749 }
00750 }
00751
00752 if ( DEBUG_Trap_Uv )
00753 FP_Exception_Enable_Min |= FPX_V;
00754
00755
00756 if (Gen_PIC_Call_Shared)
00757 Gen_PIC_Call_Shared = FALSE;
00758
00759 return;
00760 }
00761
00762
00763 extern BOOL
00764 Set_Target_ABI (BOOL is_64bit, INT isa)
00765 {
00766 if (is_64bit) {
00767 switch (Target_ABI) {
00768 case ABI_UNDEF:
00769 Target_ABI = ABI_n64;
00770 break;
00771 case ABI_n64:
00772 case ABI_w64:
00773 break;
00774 default:
00775 return FALSE;
00776 }
00777 } else {
00778 switch (Target_ABI) {
00779 case ABI_UNDEF:
00780 Target_ABI = ABI_n32;
00781 break;
00782 case ABI_n32:
00783 break;
00784 default:
00785 return FALSE;
00786 }
00787 }
00788
00789 if (Target_ISA == TARGET_ISA_UNDEF) {
00790 Target_ISA = TARGET_ISA_compute_10;
00791 }
00792
00793 return TRUE;
00794 }