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
00041
00042
00043
00044
00045
00046
00048
00049
00050
00051
00052
00053
00054
00055 #ifdef USE_PCH
00056 #include "cg_pch.h"
00057 #endif // USE_PCH
00058 #pragma hdrstop
00059
00060 #include <stdio.h>
00061 #include <stdarg.h>
00062 #include <unistd.h>
00063 #include "defs.h"
00064 #include "tracing.h"
00065 #include "cgir.h"
00066 #include "register.h"
00067 #include "gra_bb.h"
00068 #include "gra_lrange.h"
00069 #include "gra_region.h"
00070 #include "gra_interfere.h"
00071
00072 static INT trace_detail;
00073 static BOOL trace_color;
00074 static BOOL trace_split;
00075 static BOOL trace_split_priority;
00076 static BOOL trace_grants;
00077 static BOOL trace_preference;
00078 static BOOL trace_place;
00079 static BOOL trace_stats;
00080 static BOOL trace_neighbors;
00081 static BOOL trace_loops;
00082 static BOOL trace_homing;
00083 static BOOL trace_memory;
00084 static BOOL trace_perf_comp;
00085 static BOOL trace_check_splits;
00086
00087
00088 #undef long
00089
00091 void
00092 GRA_Trace_Color_LRANGE( const char* str, LRANGE* lrange )
00094
00096 {
00097 char buff[100];
00098
00099 if (trace_color && 1 <= trace_detail)
00100 fprintf(TFile,"<gra> %s p %g %s\n",str,lrange->Priority(),
00101 lrange->Format(buff));
00102 }
00103
00105 void
00106 GRA_Trace_Color_REGION( GRA_REGION* region )
00108
00110 {
00111 if ( trace_color ) {
00112 fprintf(TFile,"<gra> Coloring region ");
00113 RID_Fprint(TFile,region->Rid());
00114 }
00115 }
00116
00118 void
00119 GRA_Trace_Grant( GRA_BB* gbb, ISA_REGISTER_CLASS cl, REGISTER reg )
00121
00123 {
00124 if ( trace_grants ) {
00125 fprintf(TFile,"<gra> Granting local register %s to BB%d\n",
00126 REGISTER_name(cl,reg),BB_id(gbb->Bb()));
00127 }
00128 }
00129
00131 void
00132 GRA_Trace_Grant_Unused_Caller_Saved(void)
00134
00136 {
00137 if ( trace_grants ) {
00138 fprintf(TFile,
00139 "<gra> Attempting to grant unused caller saved registers.\n");
00140 }
00141 }
00142
00144 void
00145 GRA_Trace(INT detail, const char *fmt, ...)
00147
00149 {
00150 if (detail <= trace_detail) {
00151 va_list args;
00152 va_start(args, fmt);
00153 fprintf(TFile, "<gra> ");
00154 vfprintf(TFile,fmt,args);
00155 fprintf(TFile,"\n");
00156 va_end(args);
00157 }
00158 }
00159
00161 void
00162 GRA_Trace_Split(INT detail, const char *fmt, ...)
00164
00166 {
00167 if (trace_split && detail <= trace_detail) {
00168 va_list args;
00169 va_start(args, fmt);
00170 fprintf(TFile, "<gra> ");
00171 vfprintf(TFile,fmt,args);
00172 fprintf(TFile,"\n");
00173 va_end(args);
00174 }
00175 }
00176
00178 void
00179 GRA_Trace_Split_Removing_Block(GRA_BB* gbb)
00181
00183 {
00184 if (trace_split) {
00185 fprintf(TFile, "<gra> Removing BB:%d from split.\n",
00186 BB_id(gbb->Bb()));
00187 }
00188 }
00189
00191 void
00192 GRA_Trace_Split_Add_Priority(GRA_BB* gbb, BOOL is_store)
00194
00196 {
00197 if (trace_split_priority) {
00198 fprintf(TFile, "<gra> Adding to priority for %s in BB:%d \n",
00199 is_store ? "spill" : "restore",
00200 BB_id(gbb->Bb()));
00201 }
00202 }
00203
00205 void
00206 GRA_Trace_Split_Sub_Priority(GRA_BB* gbb, BOOL is_store)
00208
00210 {
00211 if (trace_split_priority) {
00212 fprintf(TFile, "<gra> Subtracting from priority for %s in BB:%d \n",
00213 is_store ? "spill" : "restore",
00214 BB_id(gbb->Bb()));
00215 }
00216 }
00217
00218 #ifdef KEY
00220 void
00221 GRA_Trace_Split_Reclaim_Add_Priority(GRA_BB* gbb, BOOL is_store, float priority)
00223
00225 {
00226 if (trace_split_priority) {
00227 fprintf(TFile, "<gra> Adding %f to priority for reclaim %s in BB:%d \n",
00228 priority,
00229 is_store ? "spill" : "restore",
00230 BB_id(gbb->Bb()));
00231 }
00232 }
00233
00235 void
00236 GRA_Trace_Split_Reclaim_Sub_Priority(GRA_BB* gbb, BOOL is_store, float priority)
00238
00240 {
00241 if (trace_split_priority) {
00242 fprintf(TFile, "<gra> Subtracting %f from priority for reclaim %s in BB:%d \n",
00243 priority,
00244 is_store ? "spill" : "restore",
00245 BB_id(gbb->Bb()));
00246 }
00247 }
00248 #endif
00249
00251 void
00252 GRA_Trace_Split_Priority_On(const char *msg)
00254
00256 {
00257 if (trace_check_splits) {
00258 trace_split_priority = TRUE;
00259 fprintf(TFile, "<gra> Calculate split priorities via %s:\n", msg);
00260 }
00261 }
00262
00264 void
00265 GRA_Trace_Split_Priority_Off()
00267
00269 {
00270 trace_split_priority = FALSE;
00271 }
00272
00274 void
00275 GRA_Trace_Color(INT detail, const char *fmt, ...)
00277
00279 {
00280 if (trace_color && detail <= trace_detail) {
00281 va_list args;
00282 va_start(args, fmt);
00283 fprintf(TFile, "<gra> ");
00284 vfprintf(TFile,fmt,args);
00285 fprintf(TFile,"\n");
00286 va_end(args);
00287 }
00288 }
00289
00290 void
00291 GRA_Trace_Place( INT detail, const char *fmt, ...)
00293
00295 {
00296 if (trace_place && detail <= trace_detail) {
00297 va_list args;
00298 va_start(args, fmt);
00299 fprintf(TFile, "<gra> ");
00300 vfprintf(TFile,fmt,args);
00301 fprintf(TFile,"\n");
00302 va_end(args);
00303 }
00304 }
00305
00307 void
00308 GRA_Trace_Place_LRANGE_GBB( const char* str, LRANGE* lrange,
00309 GRA_BB* gbb )
00311
00313 {
00314 if (trace_place && 1 <= trace_detail) {
00315 fprintf(TFile,"TN%d BB%d -- %s\n",TN_number(lrange->Tn()),
00316 BB_id(gbb->Bb()),
00317 str);
00318 }
00319 }
00320
00321
00323 static void
00324 print_lr( LRANGE *lr)
00326
00327
00329 {
00330 if (lr->Type() == LRANGE_TYPE_LOCAL) {
00331 if (lr->Has_Wired_Register()) {
00332 fprintf(TFile,"W%d(TN%d)",lr->Id(), lr->Reg());
00333 } else {
00334 fprintf(TFile,"L%d",lr->Id());
00335 }
00336 } else {
00337 fprintf(TFile,"C%d(TN%d)",lr->Id(), TN_number(lr->Tn()));
00338 }
00339 }
00340
00342 void
00343 GRA_Trace_Preference_Attempt(LRANGE* lrange0, LRANGE* lrange1,
00344 GRA_REGION* region, BOOL outcome )
00346
00348 {
00349 char buff0[80], buff1[80];
00350
00351 if ( trace_preference ) {
00352 GRA_Trace(0,"Preference %s with %s [%s]",
00353 lrange0->Format(buff0),
00354 lrange1->Format(buff1),
00355 outcome ? "yes" : "no");
00356 if (!outcome && lrange1->Allocated()) {
00357
00358
00359
00360
00361 fprintf(TFile,"<gra> LRANGES preventing preference: ");
00362 LRANGE_NEIGHBOR_ITER iter;
00363 REGISTER reg = lrange1->Reg();
00364 for (iter.Init(lrange0,region); ! iter.Done(); iter.Step()) {
00365 LRANGE* nlr = iter.Current();
00366 if (nlr->Allocated() &&
00367 nlr->Reg() == reg) {
00368 print_lr(nlr);
00369 fprintf(TFile," ");
00370 }
00371 }
00372 fprintf(TFile,"\n");
00373
00374 if (lrange0->Type() == LRANGE_TYPE_COMPLEMENT) {
00375 fprintf(TFile,"<gra> BBs preventing preference: ");
00376 LRANGE_LIVE_GBB_ITER gbb_iter;
00377 ISA_REGISTER_CLASS rc = lrange0->Rc();
00378 for (gbb_iter.Init(lrange0); ! gbb_iter.Done(); gbb_iter.Step()) {
00379 GRA_BB* gbb = gbb_iter.Current();
00380 if (REGISTER_SET_MemberP(gbb->Registers_Used(rc), reg)) {
00381 fprintf(TFile," BB%d", BB_id(gbb->Bb()));
00382 }
00383 }
00384 fprintf(TFile,"\n");
00385 }
00386 }
00387 }
00388 }
00389
00391 void
00392 GRA_Trace_Preference_Copy(LRANGE* lrange0, LRANGE* lrange1, GRA_BB* gbb )
00394
00396 {
00397 char buff0[80], buff1[80];
00398
00399 if ( trace_preference ) {
00400 char *str;
00401 if (lrange0->Type() == LRANGE_TYPE_REGION ||
00402 lrange1->Type() == LRANGE_TYPE_REGION) {
00403 str = "Glue";
00404 } else if (lrange0->Type() == LRANGE_TYPE_LOCAL ||
00405 lrange1->Type() == LRANGE_TYPE_LOCAL) {
00406 str = "Dedicated";
00407 } else {
00408 str = "Global";
00409 }
00410 GRA_Trace(0,"%s preference copy allowed in BB:%d %s with %s",
00411 str,
00412 BB_id(gbb->Bb()),
00413 lrange0->Format(buff0),
00414 lrange1->Format(buff1));
00415
00416 }
00417 }
00418
00420 void
00421 GRA_Trace_Preference_Conflict(LRANGE* lrange0, LRANGE* lrange1, GRA_BB* gbb )
00423
00425 {
00426 char buff0[80], buff1[80];
00427
00428 if ( trace_preference ) {
00429 GRA_Trace(0,"Preference: conflict for copy in BB:%d %s with %s",
00430 BB_id(gbb->Bb()),
00431 lrange0->Format(buff0),
00432 lrange1->Format(buff1));
00433
00434 }
00435 }
00436
00437
00439 void
00440 GRA_Trace_Possible_Preference_Copy(LRANGE* lrange0, LRANGE* lrange1, GRA_BB* gbb)
00442
00444 {
00445 char buff0[80], buff1[80];
00446
00447 if ( trace_preference ) {
00448 char *str;
00449 if (lrange0->Type() == LRANGE_TYPE_REGION ||
00450 lrange1->Type() == LRANGE_TYPE_REGION) {
00451 str = "Glue";
00452 } else if (lrange0->Type() == LRANGE_TYPE_LOCAL ||
00453 lrange1->Type() == LRANGE_TYPE_LOCAL) {
00454 str = "Dedicated";
00455 } else {
00456 str = "Global";
00457 }
00458 GRA_Trace(0,"%s TN preference copy possible in BB:%d %s with %s",
00459 str,
00460 BB_id(gbb->Bb()),
00461 lrange0->Format(buff0),
00462 lrange1->Format(buff1));
00463 }
00464 }
00465
00467 void
00468 GRA_Trace_Global_Preference_Failure(LRANGE* lrange0, LRANGE* lrange1, GRA_BB* gbb)
00470
00472 {
00473 char buff0[80], buff1[80];
00474
00475 if ( trace_preference ) {
00476 GRA_Trace(0,"Global TN preference conflict found in BB:%d %s with %s",
00477 BB_id(gbb->Bb()),
00478 lrange0->Format(buff0),
00479 lrange1->Format(buff1));
00480
00481 }
00482 }
00483
00485 void
00486 GRA_Trace_Global_Preference_Success(LRANGE* lrange0, LRANGE* lrange1)
00488
00490 {
00491 char buff0[80], buff1[80];
00492
00493 if ( trace_preference ) {
00494 GRA_Trace(0,"Global TN preference successful for %s with %s",
00495 lrange0->Format(buff0),
00496 lrange1->Format(buff1));
00497 }
00498 }
00499
00500
00502 void GRA_Trace_Spill_Stats(float freq_restore_count, INT restore_count,
00503 float freq_spill_count, INT spill_count,
00504 float priority_count)
00506
00508 {
00509 if ( trace_stats ) {
00510 GRA_Trace(0,"freq weighted restores %g spills %g allocated priority %g",
00511 freq_restore_count,freq_spill_count, priority_count);
00512 GRA_Trace(0,"absolute restores %d spills %d",restore_count,spill_count);
00513 } else if ( trace_perf_comp ) {
00514 GRA_Trace(0,"%s %g %g %d %d %g\n", ST_name(Get_Current_PU_ST()),
00515 freq_restore_count, freq_spill_count, restore_count,
00516 spill_count, priority_count);
00517 }
00518 }
00519
00521 void GRA_Trace_LRANGE_Stats( INT32 complement_count,
00522 INT32 region_count,
00523 INT32 local_count,
00524 INT32 split_count )
00526
00528 {
00529 if ( trace_stats ) {
00530 GRA_Trace(0,"LRANGE counts complement %d region %d local %d split %d",
00531 complement_count,
00532 region_count,
00533 local_count,
00534 split_count);
00535 }
00536 }
00537
00539 void GRA_Trace_Regs_Stats( ISA_REGISTER_CLASS rc,
00540 REGISTER_SET regs_all,
00541 REGISTER_SET ®s_used)
00542
00543 {
00544 if ( trace_stats )
00545 GRA_Trace(0,"rc %d: used %d regs out of %d", rc,
00546 REGISTER_SET_Size(regs_used), REGISTER_SET_Size(regs_all));
00547 }
00548
00550 void
00551 GRA_Trace_Wired_Local_Count( INT32 count )
00553
00555 {
00556 if ( trace_stats ) {
00557 GRA_Trace(0,"wired local LRANGE count %d\n",count);
00558 }
00559 }
00560
00562 void
00563 GRA_Trace_Complement_LRANGE_Neighbors( LRANGE *lr, GRA_REGION* region )
00565
00567 {
00568 LRANGE_NEIGHBOR_ITER iter;
00569 if ( trace_neighbors ) {
00570 fprintf(TFile,"<gra> Neighbors for ");
00571 print_lr(lr);
00572 fprintf(TFile,": ");
00573 for (iter.Init(lr,region); ! iter.Done(); iter.Step()) {
00574 LRANGE* nlr = iter.Current();
00575 print_lr(nlr);
00576 fprintf(TFile," ");
00577 }
00578 fprintf(TFile,"\n");
00579 if (lr->Type() == LRANGE_TYPE_COMPLEMENT) {
00580 fprintf(TFile, "live_bb_set: ");
00581 BB_SET_Print(lr->Live_BB_Set(), TFile); fprintf(TFile, "\n");
00582 }
00583 }
00584 }
00585
00587 BOOL
00588 GRA_Trace_Loops(void)
00590
00591
00593 {
00594 return trace_loops;
00595 }
00596
00598 void
00599 GRA_Trace_Homing(TN *tn, BB* bb)
00601 {
00602 if (trace_homing) {
00603 fprintf(TFile,"<gra> Homing TN%d in BB:%d\n", TN_number(tn), BB_id(bb));
00604 }
00605 }
00606
00608 void
00609 GRA_Trace_Home_Removal(TN *tn, GRA_BB* gbb, OP* op)
00611
00612
00614 {
00615 if (trace_homing) {
00616 fprintf(TFile,"<gra> Homing TN%d in BB:%d Delete op ",
00617 TN_number(tn), BB_id(gbb->Bb()));
00618 Print_OP_No_SrcLine(op);
00619 }
00620 }
00621
00622 static void *last_brk;
00623
00625 void
00626 GRA_Init_Trace_Memory(void)
00628 {
00629 if (trace_memory) {
00630 last_brk = sbrk(0);
00631 }
00632 }
00633
00635 void
00636 GRA_Trace_Memory(const char *string)
00638 {
00639 if (trace_memory) {
00640 unsigned usage = ((INTPTR) sbrk(0)) - (INTPTR) last_brk;
00641 fprintf(TFile,"<gra> Memory use %s: %d\n", string, usage);
00642 }
00643 }
00644
00646 void
00647 GRA_Trace_Memory_Realloc(const char *string)
00649 {
00650 if (trace_memory) {
00651 fprintf(TFile,"<gra> Memory realloc in %s\n", string);
00652 }
00653 }
00654
00656 void
00657 GRA_Trace_Memory_Counts()
00659 {
00660 if (trace_memory) {
00661 fprintf(TFile,"<gra> Memory use for GRA_BBs: %ld\n",
00662 (long)(gbb_mgr.Alloc_Count()*sizeof(GRA_BB)));
00663 fprintf(TFile,"<gra> Memory count of GRA_BBs: %d\n",
00664 gbb_mgr.Alloc_Count());
00665 fprintf(TFile,"<gra> Memory use for GRA_REGIONs: %ld\n",
00666 (long)(gra_region_mgr.Alloc_Count()*sizeof(GRA_REGION)));
00667 fprintf(TFile,"<gra> Memory count of GRA_REGIONs: %ld\n",
00668 (long)(gra_region_mgr.Alloc_Count()));
00669 }
00670 }
00671
00672 void
00673 GRA_Trace_Split_LUNIT_Spill(LUNIT *lunit)
00674 {
00675 GRA_BB* gbb = lunit->Gbb();
00676
00677 if (trace_split && gbb->Freq() > 1.0 && lunit->Split_Lunit()) {
00678 LRANGE* lrange = lunit->Lrange();
00679 TN* tn = lrange->Tn();
00680 fprintf(TFile,"<gra> Split spill in high frequency block BB:%d ",
00681 BB_id(gbb->Bb()));
00682 fprintf(TFile,"for TN%d\n",TN_number(tn));
00683 }
00684 }
00685
00687 BOOL
00688 GRA_Trace_Check_Splits()
00689 {
00690 return trace_check_splits;
00691 }
00692
00694 void
00695 GRA_Trace_LRANGE_Allocate(LRANGE* lrange )
00697
00699 {
00700 char buff0[80];
00701
00702 if ( trace_color ) {
00703 GRA_Trace(0,"Allocated: %s", lrange->Format(buff0));
00704 }
00705 }
00706
00707 #ifdef KEY
00709 void
00710 GRA_Trace_LRANGE_Choose(LRANGE* lrange, REGISTER_SET allowed)
00711 {
00712 if ( trace_color && lrange->Type() != LRANGE_TYPE_LOCAL) {
00713 fprintf(TFile, "<gra> choose from allowed ");
00714 REGISTER_SET_Print(allowed, TFile);
00715 fprintf(TFile, " for GTN%d\n", TN_number(lrange->Tn()));
00716 }
00717 }
00719 void
00720 GRA_Trace_LRANGE_Choose_Reclaimable(LRANGE* lrange, REGISTER_SET reclaimable)
00721 {
00722 if ( trace_color && lrange->Type() != LRANGE_TYPE_LOCAL) {
00723 fprintf(TFile, "<gra> choose from reclaimable ");
00724 REGISTER_SET_Print(reclaimable, TFile);
00725 fprintf(TFile, " for GTN%d\n", TN_number(lrange->Tn()));
00726 }
00727 }
00728 #endif
00729
00731 void
00732 GRA_Trace_Initialize(void)
00734
00736 {
00737 if (Get_Trace(TP_GRA, 0xffffffff))
00738 fprintf(TFile, "<gra> start gra trace for %s\n",
00739 ST_name(Get_Current_PU_ST()));
00740 trace_detail = Get_Trace(TP_GRA, 0x1) ? 1 : 0;
00741 trace_color = Get_Trace(TP_GRA, 0x2);
00742 trace_split = Get_Trace(TP_GRA, 0x4);
00743 trace_split_priority = FALSE;
00744 trace_grants = Get_Trace(TP_GRA, 0x8);
00745 trace_preference = Get_Trace(TP_GRA, 0x10);
00746 trace_place = Get_Trace(TP_GRA, 0x20);
00747 trace_stats = Get_Trace(TP_GRA, 0x40);
00748 trace_neighbors = Get_Trace(TP_GRA, 0x80);
00749 trace_loops = Get_Trace(TP_GRA, 0x100);
00750 trace_homing = Get_Trace(TP_GRA, 0x200);
00751 trace_memory = Get_Trace(TP_GRA, 0x400);
00752 trace_perf_comp = Get_Trace(TP_GRA, 0x800);
00753 trace_check_splits = Get_Trace(TP_GRA, 0x1000);
00754
00755 }