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