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 #define __STDC_LIMIT_MACROS
00062 #include <stdint.h>
00063 #ifdef USE_PCH
00064 #include "lno_pch.h"
00065 #endif // USE_PCH
00066 #pragma hdrstop
00067
00068 #include <sys/elf_whirl.h>
00069 #include <sys/types.h>
00070 #include "pu_info.h"
00071 #include "defs.h"
00072 #include "config.h"
00073 #include "config_lno.h"
00074 #include "config_debug.h"
00075 #include "errors.h"
00076 #include "erauxdesc.h"
00077 #include "glob.h"
00078 #include "timing.h"
00079
00080 #include "wn.h"
00081 #include "stab.h"
00082 #include "region_util.h"
00083
00084 #include "optimizer.h"
00085 #include "lnoptimizer.h"
00086 #include "region_main.h"
00087
00088 #include "debug.h"
00089 #include "cxx_template.h"
00090 #include "parids.h"
00091 #include "prompf.h"
00092 #include "cxx_memory.h"
00093 #include "ipa_lno_file.h"
00094 #include "lnodriver.h"
00095 #include "erglob.h"
00096 #include "file_util.h"
00097 #include "tracing.h"
00098 #include "ir_reader.h"
00099 #ifdef KEY
00100 #include "wn_simp.h"
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 void
00116 lno_main (INT lno_argc, char **lno_argv, INT be_argc, char **be_argv)
00117 {
00118 extern char *Whirl_Revision;
00119
00120 if (strcmp (Whirl_Revision, WHIRL_REVISION) != 0)
00121 FmtAssert (!DEBUG_Ir_Version_Check,
00122 ("WHIRL revision mismatch between be.so (%s) and lno.so (%s)",
00123 Whirl_Revision, WHIRL_REVISION));
00124
00125 Set_Error_Descriptor (EP_BE, EDESC_BE);
00126 }
00127
00128 extern "C" {
00129 extern void Lego_File_Init (void);
00130 extern void Mp_File_Init (void);
00131 extern void Lego_File_Fini (void);
00132 extern void Generate_Runtime_Stuff ();
00133 extern BOOL Run_Dsm_Check;
00134 }
00135
00136 IPA_LNO_READ_FILE* IPA_LNO_File = NULL;
00137 extern FILE* STDOUT;
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 static IPA_LNO_READ_FILE* IPA_LNO_Open_Input_File(const char* input_file)
00148 {
00149 Set_Error_Phase("Reading IPA LNO file");
00150 IPA_LNO_READ_FILE* IPA_LNO_Input_File =
00151 CXX_NEW(IPA_LNO_READ_FILE(Malloc_Mem_Pool), Malloc_Mem_Pool);
00152 INT error_code = IPA_LNO_Input_File->Open_Read_File(input_file);
00153 Input_File* ifl = IPA_LNO_Input_File->ifl;
00154 if (error_code == IPALNO_ABI_MISMATCH
00155 || error_code == IPALNO_REVISION_MISMATCH)
00156 FmtAssert(ifl != NULL, ("Missing IPALNO revision number"));
00157 if (error_code == IPALNO_FORMAT_ERROR)
00158 ErrMsg(EC_IPALNO_Open, input_file, errno);
00159 else if (error_code == IPALNO_ABI_MISMATCH)
00160 ErrMsg(EC_IPALNO_Revision, ifl->file_revision, input_file);
00161 else if (error_code == IPALNO_REVISION_MISMATCH)
00162 ErrMsg( EC_IPALNO_Revision, ifl->file_revision, input_file);
00163 else if (error_code == IPALNO_READER_ERROR)
00164 ErrMsg(EC_IPALNO_Open, input_file, errno);
00165 return IPA_LNO_Input_File;
00166 }
00167
00168
00169
00170
00171
00172
00173 static void IPA_LNO_Close_Output_Info(IPA_LNO_READ_FILE* IPA_LNO_Input_File)
00174 {
00175 Set_Error_Phase("Reading IPA LNO file");
00176 if (IPA_LNO_Input_File->ifl != NULL)
00177 IPA_LNO_Input_File->Close_Read_File();
00178 }
00179
00180
00181 void
00182 Lno_Init (void)
00183 {
00184 Set_Error_Phase ( "LNO Initialization" );
00185
00186 #ifdef _NEW_SYMTAB
00187 if ((LNO_Run_Lego_Set && LNO_Run_Lego) ||
00188 (!LNO_Run_Lego_Set && FILE_INFO_needs_lno(File_info)))
00189 Lego_File_Init ();
00190 else if (Run_Dsm_Check)
00191 Generate_Runtime_Stuff ();
00192
00193 if (FILE_INFO_has_mp(File_info))
00194 Mp_File_Init();
00195
00196 #else
00197 if ((LNO_Run_Lego_Set && LNO_Run_Lego) ||
00198 (!LNO_Run_Lego_Set && SYMTAB_mp_needs_lno(Global_Symtab)))
00199 Lego_File_Init ();
00200 else if (Run_Dsm_Check)
00201 Generate_Runtime_Stuff ();
00202
00203 if (SYMTAB_has_mp(Global_Symtab))
00204 Mp_File_Init();
00205 #endif
00206
00207
00208 if (Run_autopar && LNO_IPA_Enabled)
00209 IPA_LNO_File = IPA_LNO_Open_Input_File("IPA.LNO");
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 WN *
00219 Perform_Loop_Nest_Optimization (PU_Info* current_pu, WN *pu_wn,
00220 WN *region_wn, BOOL alloca)
00221 {
00222 WN *opt_pu = NULL;
00223 struct DU_MANAGER *du_mgr;
00224 struct ALIAS_MANAGER *alias_mgr;
00225 if (!alloca) LNO_Use_Malloc = TRUE;
00226 STDOUT = stdout;
00227
00228 MEM_POOL_Popper popper(&MEM_local_pool);
00229
00230 ST *current_pu_st = WN_st(pu_wn);
00231 Cur_PU_Name = ST_name(current_pu_st);
00232 if ( Cur_PU_Name ) {
00233
00234
00235
00236
00237
00238
00239 Cur_PU_Name = strcpy(
00240 TYPE_MEM_POOL_ALLOC_N(char, &MEM_local_pool,
00241 strlen(Cur_PU_Name) + 1),Cur_PU_Name);
00242 }
00243
00244 if (region_wn != pu_wn) {
00245 Cur_PU_Name = TYPE_MEM_POOL_ALLOC_N(char, &MEM_local_pool,
00246 strlen(Cur_PU_Name) + 9);
00247 sprintf(Cur_PU_Name,"%s.RGN%04d", ST_name(current_pu_st),
00248 RID_id(REGION_get_rid(region_wn)));
00249 }
00250
00251 Is_True(!WN_Tree_Has_Duplicate_Labels(region_wn, &MEM_local_pool),
00252 ("region_wn has duplicate labels on entry to LNO"));
00253
00254 Start_Timer ( T_Preopt_CU );
00255 Set_Error_Phase ( "Global Optimizer" );
00256
00257 #ifdef KEY
00258
00259
00260
00261 WN_Simp_Rsqrt_Newton_Raphson = FALSE;
00262 #endif
00263
00264 du_mgr = Create_Du_Manager(MEM_pu_nz_pool_ptr);
00265 alias_mgr = Create_Alias_Manager(MEM_pu_nz_pool_ptr);
00266
00267 STACK<WN*> st_before_wn(&MEM_local_pool);
00268 STACK<INT> st_before_id(&MEM_local_pool);
00269 STACK<WN*> st_after_wn(&MEM_local_pool);
00270 STACK<INT> st_after_id(&MEM_local_pool);
00271 if (Run_prompf) {
00272 Prompf_Collect_Ids(region_wn, &st_before_wn, &st_before_id);
00273 }
00274
00275 region_wn =
00276 Pre_Optimizer(PREOPT_LNO_PHASE, region_wn, du_mgr, alias_mgr);
00277 Check_for_IR_Dump(TP_LNOPT3, region_wn, "LNO PREOPT");
00278
00279 if (Run_prompf) {
00280 Prompf_Info->Mark_Preopt();
00281 Prompf_Assign_New_Ids(region_wn);
00282 Prompf_Collect_Ids(region_wn, &st_after_wn, &st_after_id);
00283 Print_Prompf_Preopt_Transaction_Log(Prompf_Info, &st_before_id,
00284 &st_after_wn, &MEM_local_pool);
00285 }
00286
00287 RID_level(REGION_get_rid(region_wn)) = RL_LNO_PREOPT;
00288 Is_True(REGION_consistency_check(region_wn),(""));
00289
00290 Stop_Timer ( T_Preopt_CU );
00291 Start_Timer ( T_LNO_CU );
00292 Set_Error_Phase ( "Loop Nest Optimizer" );
00293
00294 WB_LNO_Initialize(region_wn, du_mgr, alias_mgr, WBC_DISABLE);
00295 opt_pu = Lnoptimizer (current_pu, region_wn, du_mgr, alias_mgr);
00296 REGION_new_wn(opt_pu, region_wn);
00297 RID_level(REGION_get_rid(opt_pu)) = RL_LNO;
00298 Is_True(REGION_consistency_check(opt_pu),(""));
00299 WB_LNO_Terminate();
00300
00301 #ifdef __REGIONS_IN_LNO__
00302 if (Regions_Around_Inner_Loops && PU_has_region(Get_Current_PU())) {
00303 Set_Error_Phase ( "Region Around Inner Loops" );
00304 Rail(opt_pu);
00305 }
00306 #endif
00307
00308 if (Region_Boundary_Info && PU_has_region(Get_Current_PU())) {
00309 Set_Error_Phase ( "Region Boundary Info" );
00310 Region_Bound_Info(opt_pu, du_mgr, alias_mgr);
00311 }
00312
00313 Copy_Restricted_Map(region_wn, alias_mgr);
00314 Invalidate_Persistent_Alias_Info(alias_mgr, opt_pu);
00315
00316 Delete_Du_Manager(du_mgr, MEM_pu_nz_pool_ptr);
00317 Delete_Alias_Manager(alias_mgr, MEM_pu_nz_pool_ptr);
00318
00319 Stop_Timer ( T_LNO_CU );
00320
00321 Is_True(!WN_Tree_Has_Duplicate_Labels(opt_pu, &MEM_local_pool),
00322 ("duplicate labels introduced by Perform_Loop_Nest_Optimization"));
00323
00324 Cur_PU_Name = NULL;
00325
00326 #ifdef KEY
00327
00328 WN_Simp_Rsqrt_Newton_Raphson = TRUE;
00329 #endif
00330
00331 return opt_pu;
00332 }
00333
00334
00335 void
00336 Lno_Fini (void)
00337 {
00338 #ifdef _NEW_SYMTAB
00339 if ((LNO_Run_Lego_Set && LNO_Run_Lego) ||
00340 (!LNO_Run_Lego_Set && FILE_INFO_needs_lno(File_info))) {
00341 #else
00342 if ((LNO_Run_Lego_Set && LNO_Run_Lego) ||
00343 (!LNO_Run_Lego_Set && SYMTAB_mp_needs_lno(Global_Symtab))) {
00344 #endif
00345 Lego_File_Fini ();
00346
00347
00348
00349
00350 }
00351
00352 if (Run_autopar && LNO_IPA_Enabled)
00353 IPA_LNO_Close_Output_Info(IPA_LNO_File);
00354 }