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 #define __STDC_LIMIT_MACROS
00041 #include <stdint.h>
00042 #include "linker.h"
00043 #include "process.h"
00044
00045 #include "errors.h"
00046 #include "glob.h"
00047 #include "config.h"
00048 #include "config_list.h"
00049 #include "config_targ.h"
00050 #include "wn.h"
00051
00052 #include "ipc_defs.h"
00053 #include "ipa_option.h"
00054 #include "ipo_main.h"
00055 #include "ipc_symtab_merge.h"
00056 #include "ipc_type_merge.h"
00057 #include "ipc_main.h"
00058 #include "ipc_pic.h"
00059 #include "ld_ipa_interface.h"
00060
00061 #include "ipc_weak.h"
00062
00063
00064
00065
00066
00067 static void
00068 IP_set_target(void)
00069 {
00070 #ifdef TARG_MIPS
00071
00072
00073 Target_ABI = IPA_Target_Type == IP_64_bit_ABI ? ABI_N64 : ABI_N32;
00074
00075 switch (ld_ipa_opt[LD_IPA_ISA].flag) {
00076 case 1:
00077 Target_ISA = TARGET_ISA_M1;
00078 break;
00079 case 2:
00080 Target_ISA = TARGET_ISA_M2;
00081 break;
00082 case 3:
00083 Target_ISA = TARGET_ISA_M3;
00084 break;
00085 case 4:
00086 Target_ISA = TARGET_ISA_M4;
00087 break;
00088 default:
00089 break;
00090 }
00091
00092 Use_32_Bit_Pointers = (Target_ABI == ABI_N32);
00093 #endif
00094
00095 #ifdef TARG_IA64
00096 Target_ABI = ABI_I64;
00097 Target_ISA = TARGET_ISA_I1;
00098 Use_32_Bit_Pointers = FALSE;
00099 #endif
00100
00101 #ifdef TARG_IA32
00102 Target_ABI = ABI_I32;
00103 Target_ISA = TRUE;
00104 #endif
00105
00106 #ifdef TARG_X8664
00107 Target_ABI = IPA_Target_Type == IP_64_bit_ABI ? ABI_n64 : ABI_n32;
00108 Target_ISA = TARGET_ISA_x86_64;
00109 Use_32_Bit_Pointers = IPA_Target_Type == IP_32_bit_ABI;
00110 #endif
00111
00112 #ifdef TARG_SL
00113 Target_ABI = IPA_Target_Type == IP_64_bit_ABI ? ABI_N64 : ABI_N32;
00114 Target_ISA = TARGET_ISA_M4;
00115 Use_32_Bit_Pointers = IPA_Target_Type == IP_32_bit_ABI;
00116 #endif
00117
00118 IPA_Configure_Target ();
00119 }
00120
00121
00122 static MEM_POOL Type_Merge_Pool;
00123
00124 static BOOL ipa_dot_so_initialized = FALSE;
00125
00126 void
00127 ipa_dot_so_init ()
00128 {
00129 Temporary_Error_Phase ephase ("IPA initialization");
00130
00131 ipa_dot_so_initialized = TRUE;
00132
00133 MEM_Initialize();
00134 Preconfigure ();
00135 IP_set_target();
00136 Dont_Use_WN_Free_List ();
00137
00138 Init_Operator_To_Opcode_Table ();
00139 Initialize_Symbol_Tables (TRUE);
00140 Initialize_Auxiliary_Tables ();
00141
00142 MEM_POOL_Initialize (&Type_Merge_Pool, "TY Merge Pool", 0);
00143 Initialize_Type_Merging_Hash_Tables (&Type_Merge_Pool);
00144
00145 Set_FILE_INFO_ipa (File_info);
00146
00147 if (ld_ipa_opt[LD_IPA_SHARABLE].flag == F_CALL_SHARED_RELOC)
00148 IPA_Enable_Relocatable_Opt = TRUE;
00149
00150 }
00151
00152 #ifdef KEY
00153
00154 static int get_num_procs (void)
00155 {
00156 FILE * fp;
00157 char buf[256];
00158 int cpus = 0;
00159
00160 if ((fp = fopen ("/proc/cpuinfo", "r")) == NULL)
00161 return 0;
00162
00163 while (fgets (buf, 256, fp))
00164 {
00165 if (!strncasecmp (buf, "processor", 9))
00166 cpus += 1;
00167 }
00168
00169 fclose (fp);
00170 return cpus;
00171 }
00172 #endif // KEY
00173
00174 void
00175 ipa_driver (INT argc, char **argv)
00176 {
00177 if (! ipa_dot_so_initialized)
00178
00179 ipa_dot_so_init ();
00180
00181 Verify_Common_Block_Layout ();
00182
00183 Clear_Extra_Auxiliary_Tables ();
00184
00185 MEM_POOL_Delete (&Type_Merge_Pool);
00186
00187
00188 IPA_Enable_Cloning = FALSE;
00189 #ifdef TARG_X8664
00190 IPA_Enable_AutoGnum = FALSE;
00191 #else
00192 IPA_Enable_AutoGnum = TRUE;
00193 #endif
00194 #if 1
00195 IPA_Enable_DST = FALSE;
00196 #else
00197 IPA_Enable_DST = TRUE;
00198 #endif
00199
00200 Process_IPA_Options (argc, argv);
00201
00202 #ifdef KEY
00203 if (Annotation_Filename == NULL )
00204 IPA_Enable_PU_Reorder = REORDER_DISABLE;
00205
00206
00207 if (IPA_Max_Jobs == 0)
00208 IPA_Max_Jobs = get_num_procs ();
00209 #endif // KEY
00210
00211 create_tmpdir ( Tracing_Enabled || List_Cite );
00212
00213 #ifdef TODO
00214 if (IPA_Target_Type == IP_32_bit_ABI)
00215 IP_update_space_status32();
00216 else
00217 IP_update_space_status64();
00218 #endif
00219
00220 if (ld_ipa_opt[LD_IPA_SHARABLE].flag & F_STATIC) {
00221 IPA_Enable_Picopt = FALSE;
00222 IPA_Enable_AutoGnum = FALSE;
00223 }
00224
00225 if (IPA_Enable_Picopt || IPA_Enable_Relocatable_Opt) {
00226 Pic_optimization ();
00227 } else {
00228 Fix_up_static_functions ();
00229 }
00230
00231 Perform_Interprocedural_Optimization ();
00232
00233 }
00234
00235
00236
00237
00238
00239
00240 void
00241 Signal_Cleanup (INT sig)
00242 {
00243 Cleanup_Files (FALSE, TRUE);
00244
00245
00246
00247
00248 #ifdef KEY
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 fprintf(stderr,"IPA processing aborted\n");
00259 return;
00260 #endif
00261
00262 #if defined(TARG_IA64)
00263 fprintf(stderr,"IPA processing aborted");
00264 exit(1);
00265 #else
00266 msg (ER_FATAL, ERN_MESSAGE, "IPA processing aborted");
00267 #endif
00268 }