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 static char *source_file = __FILE__;
00063 static char *rcs_id = "$Source: /depot/CVSROOT/javi/src/sw/cmplr/common/util/tracing.c,v $ $Revision: 1.1 $";
00064
00065 #include <string.h>
00066 #include "defs.h"
00067 #include "tracing.h"
00068 #include "erglob.h"
00069 #include "flags.h"
00070 #include "util.h"
00071
00072
00073 char *SBar =
00074 "-----------------------------------------------------------------------\n";
00075 char *DBar =
00076 "=======================================================================\n";
00077 char *Sharps =
00078 "#######################################################################\n";
00079
00080 #define INDENT 2
00081
00082
00083 static FILE *TFile_internal = NULL;
00084
00085
00086 #ifdef FRONT_END_F77
00087 extern FILE *Kqqgso();
00088 #endif
00089
00090
00091 INT32 Progress_Flags = 0;
00092
00093
00094 static BOOL Non_stdout_TFile = FALSE;
00095 static char *TFile_Name = "stdout";
00096
00097
00098 #define BB_COUNT 50
00099 #define PU_COUNT 10
00100 #define REGION_COUNT 10
00101 #define CTRL_COUNT 50
00102 static UINT TI_Mask;
00103 static UINT TD_Mask;
00104 static UINT TI_Phase[TP_COUNT];
00105 static UINT TS_Phase[TP_COUNT];
00106 static UINT TN_Phase[TP_COUNT];
00107 static UINT TA_Phase[TP_COUNT];
00108 static UINT TP_Mask[TP_COUNT];
00109 static UINT TB_Enable[BB_COUNT];
00110 static UINT BB_Cnt = 0;
00111 static UINT Xstop_Phase = TP_LAST;
00112 static UINT TC_Enable[CTRL_COUNT];
00113 static char *PU_Enable[PU_COUNT];
00114 static INT PU_Num_Enable[PU_COUNT];
00115 static UINT PU_Cnt = 0;
00116 static UINT PU_NCnt = 0;
00117 static INT Region_Num_Enable[REGION_COUNT];
00118 static UINT REGION_NCnt = 0;
00119
00120 static char *Current_PU_Name = NULL;
00121 static INT Current_PU_Number = 0;
00122 static INT Current_Region_Number = 0;
00123
00124 extern int trace_stack(int, int);
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 typedef struct {
00139 INT32 num;
00140 char *id;
00141 char *name;
00142 } PDESC;
00143
00144 #define PD_num(p) (p->num)
00145 #define PD_id(p) (p->id)
00146 #define PD_name(p) (p->name)
00147
00148
00149
00150
00151
00152
00153
00154
00155 static PDESC Phases[] = {
00156
00157 { TP_PTRACE1, "PT1", "Performance #1" },
00158 { TP_PTRACE2, "PT2", "Performance #2" },
00159 { TP_MISC, "MSC", "Miscellaneous" },
00160
00161
00162 { TP_SEMANTICS, "SEM", "Semantic analyzer" },
00163 { TP_WGEN, "WGN", "WGEN GIMPLE to WHIRL bridge" },
00164 { TP_IRB, "IRB", "IR (WHIRL) builder" },
00165
00166
00167 { TP_IR_READ, "IRR", "IR (WHIRL) reader/writer" },
00168 { TP_WHIRL2FC, "WH2", "WHIRL to Fortran/C" },
00169 { TP_WHIRLSIMP, "SMP", "WHIRL simplifier" },
00170 { TP_REGION, "RGN", "Region support" },
00171 { TP_ORI, "ORI", "Olimit Region Insertion" },
00172 { TP_FEEDBACK, "FDB", "Feedback support" },
00173 { TP_VHO_LOWER, "VHO", "VHO lowering" },
00174 { TP_LOWER, "LOW", "WHIRL lowering" },
00175 { TP_LOWER90, "L90", "F90 WHIRL lowering" },
00176
00177
00178 { TP_INLINE, "INL", "Inliner" },
00179 { TP_IPL, "IPL", "IPA local summary phase" },
00180 { TP_IPA, "IPA", "IPA analysis phase" },
00181 { TP_IPO, "IPO", "IPA optimization phase" },
00182 { TP_IPM, "IPM", "IPA miscellaneous" },
00183
00184
00185 { TP_ALIAS, "ALI", "Alias/mod/ref analysis" },
00186 { TP_WOPT1, "OPT", "Global optimization" },
00187 { TP_WOPT2, "OP2", "More global optimization" },
00188 { TP_WOPT3, "OP3", "Even more global optimization" },
00189
00190
00191 { TP_VECDD, "VDD", "Vector data dependency analysis" },
00192 { TP_LNOPT, "LNO", "Loop Nest Optimization" },
00193 { TP_LNOPT2, "LN2", "More Loop Nest Optimization" },
00194 { TP_LNOPT3, "LN3", "Even more Loop Nest Optimization" },
00195
00196
00197 { TP_CG, "CGM", "Code Generator miscellaneous" },
00198 { TP_DATALAYOUT, "LAY", "Data layout" },
00199 { TP_CGEXP, "EXP", "Code generator expansion" },
00200 { TP_LOCALIZE, "LOC", "Localize TNs" },
00201 { TP_FIND_GLOB, "GLR", "Find global register live ranges" },
00202 { TP_EBO, "EBO", "Extended Block Optimizer" },
00203 { TP_FLOWOPT, "FLW", "Control flow optimization" },
00204 { TP_HBF, "HBF", "Hyperblock Formation" },
00205 { TP_PQS, "PQS", "Predicate query system" },
00206 { TP_CGPREP, "PRP", "Code generator scheduling prep" },
00207 { TP_CGLOOP, "LOP", "Code generator loop optimization" },
00208 { TP_SWPIPE, "SWP", "Software pipelining" },
00209 { TP_SRA, "SRA", "Software pipelining register allocation" },
00210 { TP_SCHED, "SCH", "Scheduling" },
00211 { TP_GCM, "GCM", "Global code motion" },
00212 { TP_GRA, "GRA", "Global register allocation" },
00213 { TP_ALLOC, "LRA", "Local register allocation" },
00214 { TP_PSGCM, "PSG", "Post Schedule Global code motion" },
00215 { TP_THR, "THR", "Tree-Height Reduction" },
00216 { TP_EMIT, "EMT", "Code emission" },
00217
00218 { TP_TEMP, "TMP", "Temporary use" },
00219 { TP_IPISR, "ISR", "Interprocedural ISR register allocation" },
00220
00221
00222 { TP_COUNT, NULL, NULL }
00223 };
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 INT32
00239 Get_Trace_Phase_Number (
00240 char **cp,
00241 char *arg )
00242 {
00243
00244 if ( **cp >= '0' && **cp <= '9' ) {
00245 return Get_Numeric_Flag ( cp, 0, TP_LAST, 0, arg );
00246
00247
00248 } else {
00249 PDESC *phase = Phases;
00250
00251 while ( PD_num(phase) != TP_COUNT ) {
00252 if ( strncasecmp ( *cp, PD_id(phase), 3 ) == 0 ) {
00253 *cp += 3;
00254 return PD_num(phase);
00255 }
00256 ++phase;
00257 }
00258 ErrMsg ( EC_Trace_Phase, -1, TP_MIN, TP_LAST );
00259 return 0;
00260 }
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 void
00273 List_Phase_Numbers ( void )
00274 {
00275 PDESC *phase = Phases;
00276
00277 fprintf ( Get_Trace_File(),
00278 "Trace phase numbers supported and their values:\n" );
00279 while ( PD_num(phase) != TP_COUNT ) {
00280 fprintf ( Get_Trace_File(), " %3s: -tt%02d:0x%08x (%s)\n",
00281 PD_id(phase), PD_num(phase), TP_Mask[PD_num(phase)],
00282 PD_name(phase) );
00283 ++phase;
00284 }
00285 }
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 void
00308 Set_Trace ( INT func, INT arg )
00309 {
00310
00311 if ( func < TKIND_MIN || func == 0 ) {
00312 ErrMsg ( EC_Trace_Func, func );
00313 return;
00314 } else if ( func > TP_LAST ) {
00315 ErrMsg ( EC_Trace_Phase, func, TKIND_MIN, TP_LAST );
00316 return;
00317 }
00318
00319
00320 switch ( func ) {
00321
00322 case TKIND_INFO:
00323 TI_Mask |= arg;
00324 return;
00325
00326
00327 case TKIND_DEBUG:
00328 TD_Mask |= arg;
00329 return;
00330
00331
00332 case TKIND_IR:
00333 if ( arg != Check_Range (arg, TP_MIN, TP_LAST, 0) ) {
00334 ErrMsg ( EC_Trace_Phase, arg, TP_MIN, TP_LAST );
00335 } else {
00336 TI_Phase[arg] = TRUE;
00337 }
00338 return;
00339
00340
00341 case TKIND_SYMTAB:
00342 if ( arg != Check_Range (arg, TP_MIN, TP_LAST, 0) ) {
00343 ErrMsg ( EC_Trace_Phase, arg, TP_MIN, TP_LAST );
00344 } else {
00345 TS_Phase[arg] = TRUE;
00346 }
00347 return;
00348
00349
00350 case TKIND_TN:
00351 if ( arg != Check_Range (arg, TP_MIN, TP_LAST, 0) ) {
00352 ErrMsg ( EC_Trace_Phase, arg, TP_MIN, TP_LAST );
00353 } else {
00354 TN_Phase[arg] = TRUE;
00355 }
00356 return;
00357
00358
00359 case TKIND_ALLOC:
00360 if ( arg != Check_Range (arg, TP_MIN, TP_LAST, 0) ) {
00361 ErrMsg ( EC_Trace_Phase, arg, TP_MIN, TP_LAST );
00362 } else {
00363 TA_Phase[arg] = TRUE;
00364 }
00365 return;
00366
00367
00368 case TKIND_BB:
00369 if ( ++BB_Cnt >= BB_COUNT ) {
00370 ErrMsg ( EC_Trace_BBs, arg );
00371 --BB_Cnt;
00372 } else {
00373 TB_Enable[BB_Cnt] = arg;
00374 }
00375 return;
00376
00377
00378 case TKIND_XPHASE:
00379 if ( arg != Check_Range (arg, TP_MIN, TP_LAST, 0) ) {
00380 ErrMsg ( EC_Trace_Phase, arg, TP_MIN, TP_LAST );
00381 } else {
00382 Xstop_Phase = arg;
00383 }
00384 return;
00385
00386
00387 case TKIND_CTRL:
00388 if ( arg != Check_Range (arg, 0, CTRL_COUNT-1, 0) ) {
00389 ErrMsg ( EC_Trace_Control, arg, CTRL_COUNT-1 );
00390 } else {
00391 TC_Enable[arg] = TRUE;
00392 }
00393 return;
00394
00395
00396 default:
00397 TP_Mask[func] |= arg;
00398 return;
00399 }
00400 }
00401
00402
00403 #define RID_CREATE_NEW_ID -1
00404 void
00405 Set_Current_PU_For_Trace ( char *name, INT number )
00406 {
00407 Current_PU_Name = name;
00408 Current_PU_Number = number;
00409
00410 Set_Current_Region_For_Trace(RID_CREATE_NEW_ID);
00411 }
00412
00413 void
00414 Set_Current_Region_For_Trace ( INT number )
00415 {
00416 Current_Region_Number = number;
00417 }
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 void
00429 Set_Trace_Pu ( char *name )
00430 {
00431 if ( ++PU_Cnt >= PU_COUNT ) {
00432 ErrMsg ( EC_Trace_PUs, name );
00433 --PU_Cnt;
00434 } else {
00435 PU_Enable[PU_Cnt] = name;
00436 }
00437 return;
00438 }
00439
00440 void
00441 Set_Trace_Pu_Number ( INT number )
00442 {
00443 if ( ++PU_NCnt >= PU_COUNT ) {
00444 ErrMsg ( EC_Trace_PUs, "<number>");
00445 --PU_NCnt;
00446 } else {
00447 PU_Num_Enable[PU_NCnt] = number;
00448 }
00449 return;
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 void
00461 Set_Trace_Region_Number ( INT number )
00462 {
00463 if ( ++REGION_NCnt >= REGION_COUNT ) {
00464 ErrMsg ( EC_Trace_REGIONs, "<number>");
00465 --REGION_NCnt;
00466 } else
00467 Region_Num_Enable[REGION_NCnt] = number;
00468 return;
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 BOOL
00483 Get_BB_Trace ( INT32 bb_id )
00484 {
00485 INT16 i;
00486 BOOL enabled = TRUE;
00487
00488 if ( PU_Cnt > 0 ) {
00489 for ( i = 1; i <= PU_Cnt; i++ ) {
00490 if ( strcmp(PU_Enable[i],Current_PU_Name) == 0 ) return TRUE;
00491 }
00492 enabled = FALSE;
00493 }
00494 if ( PU_NCnt > 0 ) {
00495 for ( i = 1; i <= PU_NCnt; i++ ) {
00496 if ( PU_Num_Enable[i] == Current_PU_Number ) return TRUE;
00497 }
00498 enabled = FALSE;
00499 }
00500
00501 if ( BB_Cnt > 0 ) {
00502 for ( i = 1; i <= BB_Cnt; i++ ) {
00503 if (TB_Enable[i] == bb_id) return TRUE;
00504 }
00505 return FALSE;
00506 }
00507
00508
00509 return enabled;
00510 }
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521 BOOL
00522 Get_Trace ( INT func, INT arg )
00523 {
00524 BOOL result;
00525 INT16 i;
00526
00527
00528 switch ( func ) {
00529
00530 case TKIND_INFO:
00531 result = (TI_Mask & arg) != 0;
00532 break;
00533
00534 case TKIND_DEBUG:
00535 result = (TD_Mask & arg) != 0;
00536 break;
00537
00538 case TKIND_IR:
00539 result = TI_Phase[arg];
00540 break;
00541
00542 case TKIND_SYMTAB:
00543 result = TS_Phase[arg];
00544 break;
00545
00546 case TKIND_TN:
00547 result = TN_Phase[arg];
00548 break;
00549
00550 case TKIND_CTRL:
00551 result = TC_Enable[arg];
00552 break;
00553
00554 case TKIND_ALLOC:
00555 result = TA_Phase[arg];
00556 break;
00557
00558 case TKIND_BB:
00559 case TKIND_XPHASE:
00560
00561 default:
00562 result = (TP_Mask[func] & arg) != 0;
00563 break;
00564 }
00565
00566 if ( result && PU_Cnt > 0 ) {
00567 #ifdef KEY
00568 if( Current_PU_Name == NULL ){
00569 result = FALSE;
00570 } else
00571 #endif
00572 for ( i = 1; i <= PU_Cnt; i++ ) {
00573 if ( strcmp(PU_Enable[i], Current_PU_Name) == 0 )
00574 break;
00575 }
00576 if (i > PU_Cnt)
00577 result = FALSE;
00578 }
00579
00580 if ( result && PU_NCnt > 0 ) {
00581 for ( i = 1; i <= PU_NCnt; i++ ) {
00582 if ( PU_Num_Enable[i] == Current_PU_Number )
00583 break;
00584 }
00585 if (i > PU_NCnt)
00586 result = FALSE;
00587 }
00588
00589 if (result && REGION_NCnt > 0) {
00590 for ( i = 1; i <= REGION_NCnt; i++ ) {
00591 if ( Region_Num_Enable[i] == Current_Region_Number )
00592 break;
00593 }
00594 if ( i > REGION_NCnt )
00595 result = FALSE;
00596 }
00597
00598 return result;
00599 }
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612 BOOL
00613 Stop_Execution ( INT phase )
00614 {
00615 return phase >= Xstop_Phase;
00616 }
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 void
00632 Set_Trace_File (
00633 char *filename )
00634 {
00635 if ( Non_stdout_TFile && TFile_internal != NULL ) {
00636 #ifndef FRONT_END_F77
00637 fclose (TFile_internal);
00638 #endif
00639 Set_Error_Trace (NULL);
00640 }
00641
00642 if ( filename != NULL ) {
00643 #ifdef FRONT_END_F77
00644 TFile_internal = Kqqgso();
00645 #else
00646 TFile_internal = fopen ( filename, "w" );
00647 #endif
00648 if ( TFile_internal != NULL ) {
00649 TFile_Name = filename;
00650 Non_stdout_TFile = TRUE;
00651 Set_Error_Trace (TFile_internal);
00652 return;
00653 }
00654 ErrMsg ( EC_Trace_Open, filename, errno );
00655 }
00656 TFile_internal = stdout;
00657 TFile_Name = NULL;
00658 Non_stdout_TFile = FALSE;
00659 Set_Error_Trace (NULL);
00660 }
00661
00662 void Set_Trace_File_internal(FILE *f)
00663 {
00664 TFile_internal = f;
00665 }
00666
00667 FILE *Get_Trace_File(void)
00668 {
00669 if (TFile_internal == NULL)
00670 TFile_internal = stdout;
00671
00672 return TFile_internal;
00673 }
00674
00675 void
00676 Trace_To_Stderr(void)
00677 {
00678 if ( Non_stdout_TFile && TFile_internal != NULL ) {
00679 #ifndef FRONT_END_F77
00680 fclose (TFile_internal);
00681 #endif
00682 Set_Error_Trace (NULL);
00683 }
00684
00685 TFile_internal = stderr;
00686 TFile_Name = NULL;
00687 Non_stdout_TFile = FALSE;
00688 Set_Error_Trace (NULL);
00689 }
00690
00691
00692 #ifndef MONGOOSE_BE
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703 void
00704 Nest_Indent ( FILE *fp )
00705 {
00706 fprintf ( fp, "%*c", ( INDENT * ( trace_stack(0,0) - 1 ) ), ' ' );
00707 }
00708 #endif