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 #include <stdio.h>
00062 #include <string.h>
00063
00064 #include "workaround.h"
00065 #include "resource.h"
00066 #include "timing.h"
00067 #include "tracing.h"
00068 #include "resource.h"
00069 #include "messg.h"
00070
00071
00072 static BOOL Enabled = FALSE;
00073
00074
00075 static RSTATE *timers[T_LAST+1];
00076 #define Timer(i) timers[i]
00077
00078
00079
00080
00081 static INT CU_Count = 0;
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 void
00093 Reset_Timers (void)
00094 {
00095 INT i;
00096
00097 if ( Enabled ) {
00098 for ( i=0; i <= T_LAST; i++ ) Resource_Accum (Timer(i), RR_Clear);
00099 }
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 void
00114 Initialize_Timing ( BOOL enable )
00115 {
00116
00117 if ( Enabled = enable ) {
00118
00119
00120 Resource_Init ();
00121
00122
00123 Timer ( T_BE_Comp ) =
00124 Resource_Alloc ( "Total Back End", NULL );
00125 Timer ( T_BE_PU_Comp ) =
00126 Resource_Alloc ( "Back End on PU", NULL );
00127 Timer ( T_BE_PU_CU ) =
00128 Resource_Alloc ( "Back End on PU", Timer(T_BE_PU_Comp) );
00129 Timer ( T_ReadIR_Comp ) =
00130 Resource_Alloc ( " Reading IR", NULL );
00131 Timer ( T_ReadIR_CU ) =
00132 Resource_Alloc ( " Reading IR", Timer(T_ReadIR_Comp) );
00133 Timer ( T_Lower_Comp ) =
00134 Resource_Alloc ( " Lowering WHIRL", NULL );
00135 Timer ( T_Lower_CU ) =
00136 Resource_Alloc ( " Lowering WHIRL", Timer(T_Lower_Comp) );
00137 Timer ( T_ORI_Comp ) =
00138 Resource_Alloc ( " Olimit Region Insertion", NULL );
00139 Timer ( T_ORI_CU ) =
00140 Resource_Alloc ( " Olimit Region Insertion", Timer(T_ORI_Comp) );
00141
00142 Timer ( T_Preopt_Comp ) =
00143 Resource_Alloc ( "Pre-optimize", NULL );
00144 Timer ( T_Preopt_CU ) =
00145 Resource_Alloc ( "Pre-optimize", Timer(T_Preopt_Comp) );
00146 Timer ( T_Wopt_Comp ) =
00147 Resource_Alloc ( "Global optimize", NULL );
00148 Timer ( T_Wopt_CU ) =
00149 Resource_Alloc ( "Global optimize", Timer(T_Wopt_Comp) );
00150 Timer ( T_LNO_Comp ) =
00151 Resource_Alloc ( "Loop Nest Optimization", NULL );
00152 Timer ( T_LNO_CU ) =
00153 Resource_Alloc ( "Loop Nest Optimization", Timer(T_LNO_Comp) );
00154
00155 Timer ( T_W2C_Comp ) =
00156 Resource_Alloc ( "WHIRL To C", NULL );
00157 Timer ( T_W2C_CU ) =
00158 Resource_Alloc ( "WHIRL To C", Timer(T_W2C_Comp) );
00159 Timer ( T_W2F_Comp ) =
00160 Resource_Alloc ( "WHIRL To Fortran", NULL );
00161 Timer ( T_W2F_CU ) =
00162 Resource_Alloc ( "WHIRL To Fortran", Timer(T_W2F_Comp) );
00163
00164 Timer ( T_CodeGen_Comp ) =
00165 Resource_Alloc ( "Total Code Generator", NULL );
00166 Timer ( T_CodeGen_CU ) =
00167 Resource_Alloc ( "Total Code Generator", Timer(T_CodeGen_Comp) );
00168
00169 Timer ( T_GLRA_Comp ) =
00170 Resource_Alloc ( " Global Live Range Analysis", NULL );
00171 Timer ( T_GLRA_CU ) =
00172 Resource_Alloc ( " Global Live Range Analysis", Timer(T_GLRA_Comp) );
00173 Timer ( T_Localize_Comp ) =
00174 Resource_Alloc ( " Localize", NULL );
00175 Timer ( T_Localize_CU ) =
00176 Resource_Alloc ( " Localize", Timer(T_Localize_Comp) );
00177 Timer ( T_Expand_Comp ) =
00178 Resource_Alloc ( " Code Expansion", NULL );
00179 Timer ( T_Expand_CU ) =
00180 Resource_Alloc ( " Code Expansion", Timer(T_Expand_Comp) );
00181 Timer ( T_SWpipe_Comp ) =
00182 Resource_Alloc ( " Software pipelining", NULL );
00183 Timer ( T_SWpipe_CU ) =
00184 Resource_Alloc ( " Software pipelining", Timer(T_SWpipe_Comp) );
00185 Timer ( T_GCM_Comp ) =
00186 Resource_Alloc ( " Global Code Motion", NULL );
00187 Timer ( T_GCM_CU ) =
00188 Resource_Alloc ( " Global Code Motion", Timer(T_GCM_Comp) );
00189 Timer ( T_EBO_Comp ) =
00190 Resource_Alloc ( " Extended Block Optimization", NULL );
00191 Timer ( T_EBO_CU ) =
00192 Resource_Alloc ( " Extended BLock Optimization", Timer(T_EBO_Comp) );
00193 Timer ( T_CFLOW_Comp ) =
00194 Resource_Alloc ( " Control Flow Optimization", NULL );
00195 Timer ( T_CFLOW_CU ) =
00196 Resource_Alloc ( " Control Flow Optimization", Timer(T_CFLOW_Comp) );
00197 Timer ( T_Loop_Comp ) =
00198 Resource_Alloc ( " CG Loop", NULL );
00199 Timer ( T_Loop_CU ) =
00200 Resource_Alloc ( " CG Loop", Timer(T_Loop_Comp) );
00201 Timer ( T_Freq_Comp ) =
00202 Resource_Alloc ( " Compute Frequency", NULL );
00203 Timer ( T_Freq_CU ) =
00204 Resource_Alloc ( " Compute Frequency", Timer(T_Freq_Comp) );
00205 Timer ( T_HBF_Comp ) =
00206 Resource_Alloc ( " HyperBlock Formation", NULL );
00207 Timer ( T_HBF_CU ) =
00208 Resource_Alloc ( " HyperBlock Formation", Timer(T_HBF_Comp) );
00209 Timer ( T_Sched_Comp ) =
00210 Resource_Alloc ( " HyperBlock Scheduling", NULL );
00211 Timer ( T_Sched_CU ) =
00212 Resource_Alloc ( " HyperBlock Scheduling", Timer(T_Sched_Comp) );
00213 Timer ( T_THR_Comp ) =
00214 Resource_Alloc ( " Tree-Height Reduction", NULL );
00215 Timer ( T_THR_CU ) =
00216 Resource_Alloc ( " Tree-Height Reduction", Timer(T_THR_Comp) );
00217 Timer ( T_LRA_Comp ) =
00218 Resource_Alloc ( " Local Register Allocation", NULL );
00219 Timer ( T_LRA_CU ) =
00220 Resource_Alloc ( " Local Register Allocation", Timer(T_LRA_Comp));
00221 Timer ( T_GRA_Comp ) =
00222 Resource_Alloc ( " Global Register Allocation", NULL );
00223 Timer ( T_GRA_CU ) =
00224 Resource_Alloc ( " Global Register Allocation", Timer(T_GRA_Comp));
00225 Timer ( T_Emit_Comp ) =
00226 Resource_Alloc ( " Assembly Code Emission", NULL );
00227 Timer ( T_Emit_CU ) =
00228 Resource_Alloc ( " Assembly Code Emission", Timer(T_Emit_Comp) );
00229 Timer ( T_Region_Finalize_Comp ) =
00230 Resource_Alloc ( " Region Finalize", NULL );
00231 Timer ( T_Region_Finalize_CU ) =
00232 Resource_Alloc ( " Region Finalize", Timer(T_Region_Finalize_Comp));
00233 Timer ( T_CalcDom_Comp) =
00234 Resource_Alloc ( " Calculate_Dominators", NULL );
00235 Timer ( T_CalcDom_CU) =
00236 Resource_Alloc ( " Calculate_Dominators", Timer(T_CalcDom_Comp));
00237
00238 }
00239 }
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 #ifndef MONGOOSE_BE
00251 void
00252 Clear_Timer ( INT Timer_ID )
00253 {
00254 if ( Enabled ) {
00255 Resource_Accum ( Timer(Timer_ID), RR_Clear );
00256 }
00257 }
00258 #endif
00259
00260 void
00261 Start_Timer ( INT Timer_ID )
00262 {
00263 if ( Enabled ) {
00264 Resource_Accum ( Timer(Timer_ID), RR_Start );
00265 }
00266 }
00267
00268 void
00269 Stop_Timer ( INT Timer_ID )
00270 {
00271 if ( Enabled ) {
00272 Resource_Accum ( Timer(Timer_ID), RR_Stop );
00273 }
00274 }
00275
00276 double Get_User_Time(INT Timer_ID)
00277 {
00278 if (Enabled) {
00279 RSTATE *r;
00280
00281 Resource_Accum ( Timer(Timer_ID), RR_Stop );
00282 Resource_Accum ( Timer(Timer_ID), RR_Start );
00283 r = Timer(Timer_ID);
00284 TIME_INFO *utime = Get_Time ( r, RR_Delta_User );
00285 return utime->secs + 0.000001 * utime->usecs;
00286 }
00287 return 0.0;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 void
00300 Add_Timer_To_Parent ( INT Timer_ID )
00301 {
00302 if ( Enabled ) {
00303 Resource_Accum ( Timer(Timer_ID), RR_End );
00304 }
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 void
00319 Report_Delta_Time (
00320 FILE *file,
00321 INT Timer_ID )
00322 {
00323 char *name;
00324 TIME_INFO *utime, *stime, *etime;
00325 RSTATE *r = Timer(Timer_ID);
00326 INT mem;
00327
00328 if ( Enabled ) {
00329 name = Get_Timer_Name (r);
00330 utime = Get_Time ( r, RR_Delta_User );
00331 stime = Get_Time ( r, RR_Delta_System );
00332 etime = Get_Time ( r, RR_Delta_Elapsed );
00333 mem = Get_Memory ( r, RR_Delta_Memory );
00334
00335 #if (1)
00336 fprintf ( file, "%-32s %4d.%06du %4d.%06ds %4d.%06de",
00337 name,
00338 utime->secs, utime->usecs,
00339 stime->secs, stime->usecs,
00340 etime->secs, etime->usecs );
00341 #else
00342 fprintf ( file, "%-32s %4d.%03du %4d.%03ds %4d.%02de",
00343 name,
00344 utime->secs, utime->usecs/1000,
00345 stime->secs, stime->usecs/1000,
00346 etime->secs, etime->usecs/10000 );
00347 #endif
00348 if ( mem ) fprintf ( file, " %7dm", mem );
00349 fprintf ( file, "\n" );
00350 }
00351 }
00352
00353 void
00354 Report_CG_Region_Timing (FILE *file, char *name)
00355 {
00356 if ( ! Enabled ) return;
00357 if ( file == NULL || Get_Trace ( TKIND_INFO, TINFO_CTIME ) ) return;
00358
00359 fprintf ( file, "%s%s: CG Timing Report:\n\n", DBar, name);
00360 Report_Delta_Time ( file, T_CodeGen_CU );
00361 Report_Delta_Time ( file, T_Expand_CU );
00362 Report_Delta_Time ( file, T_Localize_CU );
00363 Report_Delta_Time ( file, T_GLRA_CU );
00364 Report_Delta_Time ( file, T_EBO_CU );
00365 Report_Delta_Time ( file, T_CFLOW_CU );
00366 Report_Delta_Time ( file, T_Loop_CU );
00367 Report_Delta_Time ( file, T_CalcDom_CU );
00368 Report_Delta_Time ( file, T_SWpipe_CU );
00369 Report_Delta_Time ( file, T_Freq_CU );
00370 Report_Delta_Time ( file, T_GRA_CU );
00371 Report_Delta_Time ( file, T_LRA_CU );
00372 Report_Delta_Time ( file, T_HBF_CU );
00373 Report_Delta_Time ( file, T_Sched_CU );
00374 Report_Delta_Time ( file, T_THR_CU );
00375 Report_Delta_Time ( file, T_GCM_CU );
00376 Report_Delta_Time ( file, T_Region_Finalize_CU );
00377 fprintf ( file, "%s\n", DBar );
00378 }
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 void
00390 Finish_BE_Timing (
00391 FILE *file,
00392 char *name )
00393 {
00394 if ( Enabled ) {
00395
00396 ++CU_Count;
00397
00398
00399 if ( file != NULL && ! Get_Trace ( TKIND_INFO, TINFO_CTIME ) ) {
00400 fprintf ( file,
00401 "%s%s (#%d): Back End Timing Report:\n\n",
00402 DBar, name, CU_Count );
00403
00404 Report_Delta_Time ( file, T_BE_PU_CU );
00405 Report_Delta_Time ( file, T_ReadIR_CU );
00406 Report_Delta_Time ( file, T_Lower_CU );
00407 Report_Delta_Time ( file, T_ORI_CU );
00408
00409 fprintf(file, "\n");
00410 Report_Delta_Time ( file, T_Preopt_CU );
00411 Report_Delta_Time ( file, T_LNO_CU );
00412 Report_Delta_Time ( file, T_Wopt_CU );
00413 Report_Delta_Time ( file, T_W2C_CU );
00414 Report_Delta_Time ( file, T_W2F_CU );
00415
00416 fprintf(file, "\n");
00417 Report_Delta_Time ( file, T_CodeGen_CU );
00418 Report_Delta_Time ( file, T_Expand_CU );
00419 Report_Delta_Time ( file, T_Localize_CU );
00420 Report_Delta_Time ( file, T_GLRA_CU );
00421 Report_Delta_Time ( file, T_EBO_CU );
00422 Report_Delta_Time ( file, T_CFLOW_CU );
00423 Report_Delta_Time ( file, T_Loop_CU );
00424 Report_Delta_Time ( file, T_CalcDom_CU);
00425 Report_Delta_Time ( file, T_SWpipe_CU );
00426 Report_Delta_Time ( file, T_Freq_CU );
00427 Report_Delta_Time ( file, T_GRA_CU );
00428 Report_Delta_Time ( file, T_LRA_CU );
00429 Report_Delta_Time ( file, T_HBF_CU );
00430 Report_Delta_Time ( file, T_Sched_CU );
00431 Report_Delta_Time ( file, T_THR_CU );
00432 Report_Delta_Time ( file, T_GCM_CU );
00433 Report_Delta_Time ( file, T_Emit_CU );
00434 Report_Delta_Time ( file, T_Region_Finalize_CU );
00435 fprintf ( file, "%s\n", DBar );
00436 }
00437
00438
00439 Add_Timer_To_Parent ( T_BE_PU_CU );
00440 Add_Timer_To_Parent ( T_ReadIR_CU );
00441 Add_Timer_To_Parent ( T_Lower_CU );
00442 Add_Timer_To_Parent ( T_ORI_CU );
00443
00444 Add_Timer_To_Parent ( T_Preopt_CU );
00445 Add_Timer_To_Parent ( T_LNO_CU );
00446 Add_Timer_To_Parent ( T_Wopt_CU );
00447
00448 Add_Timer_To_Parent ( T_W2C_CU );
00449 Add_Timer_To_Parent ( T_W2F_CU );
00450
00451 Add_Timer_To_Parent ( T_CodeGen_CU );
00452 Add_Timer_To_Parent ( T_Expand_CU );
00453 Add_Timer_To_Parent ( T_Localize_CU );
00454 Add_Timer_To_Parent ( T_GLRA_CU );
00455 Add_Timer_To_Parent ( T_EBO_CU );
00456 Add_Timer_To_Parent ( T_CFLOW_CU );
00457 Add_Timer_To_Parent ( T_Loop_CU );
00458 Add_Timer_To_Parent ( T_CalcDom_CU );
00459 Add_Timer_To_Parent ( T_SWpipe_CU );
00460 Add_Timer_To_Parent ( T_Freq_CU );
00461 Add_Timer_To_Parent ( T_GRA_CU );
00462 Add_Timer_To_Parent ( T_LRA_CU );
00463 Add_Timer_To_Parent ( T_HBF_CU );
00464 Add_Timer_To_Parent ( T_Sched_CU );
00465 Add_Timer_To_Parent ( T_THR_CU );
00466 Add_Timer_To_Parent ( T_GCM_CU );
00467 Add_Timer_To_Parent ( T_Emit_CU );
00468 Add_Timer_To_Parent ( T_Region_Finalize_CU );
00469 }
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 void
00482 Finish_Compilation_Timing (
00483 FILE *file,
00484 char *source )
00485 {
00486 if ( Enabled ) {
00487
00488 if ( file != NULL ) {
00489 fprintf ( file, "%s\n%s: Compilation Timing Report\n",
00490 DBar, source );
00491
00492 fprintf ( file, "\n" );
00493 Report_Delta_Time ( file, T_BE_Comp );
00494 fprintf ( file, "\n" );
00495 Report_Delta_Time ( file, T_BE_PU_Comp );
00496 Report_Delta_Time ( file, T_ReadIR_Comp );
00497 Report_Delta_Time ( file, T_Lower_Comp );
00498 Report_Delta_Time ( file, T_ORI_Comp );
00499
00500 fprintf ( file, "\n" );
00501 Report_Delta_Time ( file, T_Preopt_Comp );
00502 Report_Delta_Time ( file, T_LNO_Comp );
00503 Report_Delta_Time ( file, T_Wopt_Comp );
00504 Report_Delta_Time ( file, T_W2C_Comp );
00505 Report_Delta_Time ( file, T_W2F_Comp );
00506
00507 fprintf ( file, "\n" );
00508 Report_Delta_Time ( file, T_CodeGen_Comp );
00509 Report_Delta_Time ( file, T_Expand_Comp );
00510 Report_Delta_Time ( file, T_Localize_Comp );
00511 Report_Delta_Time ( file, T_GLRA_Comp );
00512 Report_Delta_Time ( file, T_EBO_Comp );
00513 Report_Delta_Time ( file, T_CFLOW_Comp );
00514 Report_Delta_Time ( file, T_Loop_Comp );
00515 Report_Delta_Time ( file, T_CalcDom_Comp );
00516 Report_Delta_Time ( file, T_SWpipe_Comp );
00517 Report_Delta_Time ( file, T_Freq_Comp );
00518 Report_Delta_Time ( file, T_GRA_Comp );
00519 Report_Delta_Time ( file, T_LRA_Comp );
00520 Report_Delta_Time ( file, T_HBF_Comp );
00521 Report_Delta_Time ( file, T_Sched_Comp );
00522 Report_Delta_Time ( file, T_THR_Comp );
00523 Report_Delta_Time ( file, T_GCM_Comp );
00524 Report_Delta_Time ( file, T_Emit_Comp );
00525 Report_Delta_Time ( file, T_Region_Finalize_Comp );
00526 fprintf ( file, "%s\n", DBar );
00527 }
00528 }
00529 }
00530
00531
00532 RSTATE * Get_Rstate(INT ID)
00533 {
00534 return Timer(ID);
00535 }
00536
00537 void Alloc_Phase(INT curId, const char *name, INT parentId)
00538 {
00539 Timer(curId) = Resource_Alloc((char *)name, (parentId<0) ? NULL : Timer(parentId));
00540 }