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