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 #include "bb.h"
00044 #include "DaVinci.h"
00045 #include "glob.h"
00046 #include "mempool.h"
00047 #include "op.h"
00048 #include "region.h"
00049 #include "vt_dag.h"
00050 #include "vt_region.h"
00051 #include <ipfec_options.h>
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 typedef struct cfg_label_info {
00064 float prob;
00065 float freq;
00066 NODE_ID dest_node_id;
00067 }CFG_LABEL_INFO;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 void draw_bb_op (BB *bb,const char *mes)
00082 {
00083 if (! DaVinci::enabled(TRUE)) return;
00084
00085 MEM_POOL dv_pool;
00086 dv_pool.magic_num = 0;
00087 MEM_POOL_Constructor pool( &dv_pool, "DaVinci", FALSE);
00088
00089 DaVinci dv (&dv_pool, NULL);
00090
00091 char window_title[128];
00092 if ( NULL == mes)
00093 sprintf(window_title,"OP in BB %d , BB Freq is %#.5f - %s",
00094 BB_id(bb), bb -> freq, Cur_PU_Name);
00095 else
00096 sprintf(window_title,"OP in BB %d , BB Freq is %#.5f - %s - %s ",
00097 BB_id(bb), bb -> freq, Cur_PU_Name, mes);
00098 Is_True(strlen(window_title) < 128, ("Window Title buf overflowed"));
00099 dv.Title(window_title);
00100
00101
00102 NODE_TYPE nt;
00103 EDGE_TYPE et;
00104
00105 et.Direction(ED_NONE);
00106 et.Color ("gray");
00107
00108 dv.Graph_Begin();
00109
00110 OPS op_list = bb->ops;
00111
00112 for (OP* op = op_list.first ; op != NULL ; op = op -> next)
00113 {
00114
00115 char buffer[1024];
00116 char *nlabel = Print_OP (op, buffer);
00117 Is_True(strlen(nlabel) < 1024, ("Node Label buf overflowed"));
00118
00119 dv.Node_Begin (NODE_ID (op), nlabel, nt);
00120 if ( NULL != (op -> next) )
00121 dv.Out_Edge ( EDGE_ID ( NODE_ID(op), NODE_ID(op -> next)),
00122 et,
00123 NODE_ID (op -> next));
00124 dv.Node_End();
00125 }
00126
00127 dv.Graph_End();
00128 dv.Event_Loop(NULL);
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 class Regional_CFG_Callback : public DaVinci_Callback {
00151 private:
00152 DaVinci *_dv;
00153 INT32 _pseudo_node_num;
00154 REGIONAL_CFG *_cfg;
00155 public:
00156 Regional_CFG_Callback (DaVinci *dv,REGIONAL_CFG *cfg,INT32 label_num = 0)
00157 {
00158 _dv = dv;
00159 _pseudo_node_num = label_num;
00160 _cfg = cfg;
00161 }
00162 ~Regional_CFG_Callback (){}
00163
00164 virtual void Node_Select( const INT n_ids, const NODE_ID id_array[] );
00165 virtual void Edge_Select( const EDGE_ID& edge_id);
00166 };
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 void
00180 Regional_CFG_Callback::Node_Select(const INT n_ids, const NODE_ID id_array[])
00181 {
00182 REGIONAL_CFG_NODE* node;
00183 for (INT32 i = 0; i < n_ids; ++i) {
00184 node = (REGIONAL_CFG_NODE*) id_array[i];
00185 if ( ((INT32)(INTPTR)node) > _pseudo_node_num)
00186 if ( node -> Is_Region() )
00187 draw_regional_cfg ( node -> Region_Node() );
00188 else draw_bb_op ( node -> BB_Node() );
00189 }
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 void
00202 Regional_CFG_Callback::Edge_Select(const EDGE_ID& edge_id)
00203 {
00204 if (! VT_Enable_CFG_Label)
00205 {
00206 REGIONAL_CFG_NODE *src_node = (REGIONAL_CFG_NODE*) edge_id.src;
00207 REGIONAL_CFG_NODE *dst_node = (REGIONAL_CFG_NODE*) edge_id.dst;
00208 REGIONAL_CFG_EDGE *edge = src_node -> Find_Succ_Edge(dst_node);
00209 float freq = _cfg -> Edge_Freq (edge);
00210
00211 char message[128];
00212 sprintf ( message, "Selected Edge Frequence: %#.5f", freq);
00213 Is_True(strlen(message)<128, ("daVinci message buffer overflowed"));
00214 _dv -> Show_Message (message);
00215 }
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 void draw_regional_cfg (REGION *r,const char *mes)
00233 {
00234 if (! DaVinci::enabled (TRUE)) return;
00235
00236 MEM_POOL dv_pool;
00237 dv_pool.magic_num = 0;
00238 MEM_POOL_Constructor pool (&dv_pool, "DaVinci", FALSE);
00239
00240 DaVinci dv (&dv_pool, NULL);
00241
00242 char window_title[128];
00243 if ( NULL == mes)
00244 sprintf(window_title,"Regional CFG for Region %d - %s",
00245 r -> Id(), Cur_PU_Name);
00246 else
00247 sprintf(window_title,"Regional CFG for Region %d - %s - %s ",
00248 r -> Id(), Cur_PU_Name, mes);
00249 Is_True(strlen(window_title) < 128, ("Window Title buf overflowed"));
00250 dv.Title(window_title);
00251
00252
00253 char nlabel[64];
00254 INT32 pseudo_node_id=0;
00255 CFG_LABEL_INFO label_info_item;
00256 std::vector<CFG_LABEL_INFO> label_info_vector;
00257 BOOL show_edge_label;
00258 NODE_TYPE nt,nt_bb,nt_region,nt_pseudo;
00259 EDGE_TYPE et_source,et_destination;
00260 REGIONAL_CFG_NODE *being_drawn_node;
00261
00262 nt_bb.Shape (NS_CIRCLE);
00263 nt_region.Color ("pink");
00264 nt_region.Boarder (NB_DOUBLE);
00265 nt_pseudo.Shape (NS_TEXT);
00266 et_source.Direction (ED_NONE);
00267
00268 if (VT_Enable_CFG_Label) show_edge_label = TRUE;
00269 else show_edge_label = FALSE;
00270
00271 dv.Graph_Begin();
00272
00273 REGIONAL_CFG *cfg = r -> Regional_Cfg();
00274
00275 for (SEQ_REGIONAL_CFG_ITER iter(cfg) ; iter != 0 ; ++ iter)
00276 {
00277 being_drawn_node = *iter;
00278
00279 if ( being_drawn_node -> Is_Region() ) {
00280 nt = nt_region;
00281 sprintf(nlabel, " %d ", being_drawn_node->Region_Node()->Id() );
00282 }
00283 else {
00284 nt = nt_bb;
00285 if (BB_entry(being_drawn_node -> BB_Node())) nt.Shape(NS_RHOMBUS);
00286 if (BB_exit(being_drawn_node -> BB_Node())) nt.Shape(NS_ELLIPSE);
00287 sprintf(nlabel, "%d", being_drawn_node -> BB_Node() -> id );
00288 }
00289
00290 Is_True(strlen(nlabel) < 64, ("Node Label buf overflowed"));
00291 dv.Node_Begin (NODE_ID (being_drawn_node), nlabel, nt);
00292
00293 for (CFG_SUCC_NODE_ITER kid_iter(being_drawn_node);
00294 kid_iter!=0; ++ kid_iter)
00295 {
00296 REGIONAL_CFG_NODE *kid_node = *kid_iter;
00297 if (show_edge_label)
00298 {
00299 REGIONAL_CFG_EDGE
00300 *edge = being_drawn_node -> Find_Succ_Edge(kid_node);
00301
00302 label_info_item.prob = cfg -> Edge_Prob (edge);
00303 label_info_item.freq = cfg -> Edge_Freq (edge);
00304 label_info_item.dest_node_id = NODE_ID (kid_node);
00305 label_info_vector.push_back (label_info_item);
00306
00307 dv.Out_Edge (EDGE_ID (NODE_ID ((INTPTR)being_drawn_node),
00308 NODE_ID ((INTPTR)pseudo_node_id)),
00309 et_source,
00310 NODE_ID ((INTPTR)pseudo_node_id));
00311
00312 pseudo_node_id ++;
00313 }
00314 else {
00315
00316 dv.Out_Edge(EDGE_ID(NODE_ID(being_drawn_node),
00317 NODE_ID(kid_node)),
00318 et_destination,
00319 NODE_ID(kid_node));
00320 }
00321
00322 }
00323 dv.Node_End();
00324 }
00325
00326
00327 if (show_edge_label)
00328 for (INT32 i=0; i<pseudo_node_id ; i++)
00329 {
00330
00331 sprintf(nlabel,"%#.2f / %#.2f", label_info_vector [i].prob,
00332 label_info_vector [i].freq);
00333 Is_True(strlen(nlabel) < 64, ("Node Label buf overflowed"));
00334 dv.Node_Begin (NODE_ID ((INTPTR)i), nlabel, nt_pseudo);
00335 dv.Out_Edge(EDGE_ID(NODE_ID((INTPTR)i),label_info_vector[i].dest_node_id),
00336 et_destination,
00337 label_info_vector [i].dest_node_id );
00338 dv.Node_End ();
00339 }
00340 dv.Graph_End ();
00341
00342 Regional_CFG_Callback regional_cfg_callback(&dv, cfg, pseudo_node_id);
00343 dv.Event_Loop( (DaVinci_Callback*) ®ional_cfg_callback );
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 class Region_Tree_Callback : public DaVinci_Callback {
00368 public:
00369 Region_Tree_Callback (){}
00370 ~Region_Tree_Callback (){}
00371
00372 virtual void Node_Select( const INT n_ids, const NODE_ID id_array[] );
00373 };
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 void
00386 Region_Tree_Callback::Node_Select(const INT n_ids, const NODE_ID id_array[])
00387 {
00388 NODE_ID node_id;
00389 for (INT32 i = 0; i < n_ids; ++i) {
00390 node_id = id_array[i];
00391 draw_regional_cfg ( (REGION*) node_id );
00392 }
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 void draw_region_tree (REGION *r,const char *mes)
00411 {
00412 if (! DaVinci::enabled(TRUE)) return;
00413
00414 MEM_POOL dv_pool;
00415 dv_pool.magic_num = 0;
00416 MEM_POOL_Constructor pool( &dv_pool, "DaVinci", FALSE);
00417
00418 DaVinci dv (&dv_pool, NULL);
00419
00420 char window_title[128];
00421 if ( NULL == mes)
00422 sprintf(window_title,"Region Tree for Region %d - %s",
00423 r -> Id(), Cur_PU_Name);
00424 else
00425 sprintf(window_title,"Region Tree for Region %d - %s - %s ",
00426 r -> Id(), Cur_PU_Name, mes);
00427 Is_True(strlen(window_title) < 128, ("Window Title buf overflowed"));
00428 dv.Title(window_title);
00429
00430
00431 char nlabel[16];
00432 NODE_TYPE nt, nt_plain;
00433 EDGE_TYPE et;
00434 std::deque<REGION*> r_deque;
00435 REGION *being_drawn_region, *kid_r;
00436
00437 r_deque.push_back (r);
00438 dv.Graph_Begin();
00439
00440 while ( ! r_deque.empty() )
00441 {
00442 being_drawn_region = r_deque[0];
00443 r_deque.pop_front();
00444
00445 nt = nt_plain;
00446 switch( being_drawn_region -> Region_Type() )
00447 {
00448 case UNKNOWN : break;
00449 case ROOT : nt.Color ("lightgoldenrod"); break;
00450 case MEME : nt.Color ("pink"); break;
00451 case SEME : nt.Color ("palegreen"); break;
00452 case IMPROPER : nt.Color ("gray"); break;
00453 case LOOP : nt.Shape (NS_CIRCLE); break;
00454 }
00455 switch( being_drawn_region -> Attribute() )
00456 {
00457 case NONE : break;
00458 case NO_FURTHER_OPTIMIZATION: nt.Shape (NS_RHOMBUS);
00459 nt.Boarder(NB_DOUBLE); break;
00460 case RIGID : nt.Shape (NS_RHOMBUS); break;
00461 case PERSISTENT_BOUNDARY : nt.Boarder(NB_DOUBLE); break;
00462 case NO_OPTIMIZAION_ACROSS_BOUNDARY:
00463 nt.Shape (NS_ELLIPSE); break;
00464 }
00465
00466
00467 sprintf(nlabel,"%d",being_drawn_region -> Id() );
00468 Is_True(strlen(nlabel) < 16, ("Node Label buf overflowed"));
00469 dv.Node_Begin (NODE_ID (being_drawn_region), nlabel, nt);
00470
00471 if (being_drawn_region -> N_Kids() > 0 )
00472 for (REGION_KID_ITER r_kid_iter(being_drawn_region);
00473 r_kid_iter != 0; ++ r_kid_iter )
00474 {
00475 kid_r = * r_kid_iter;
00476 r_deque.push_back (kid_r);
00477 dv.Out_Edge ( EDGE_ID ( NODE_ID(being_drawn_region),
00478 NODE_ID(kid_r) ),
00479 et, NODE_ID (kid_r));
00480 }
00481
00482 dv.Node_End();
00483 }
00484
00485 dv.Graph_End();
00486
00487 Region_Tree_Callback region_tree_callback;
00488 dv.Event_Loop( (DaVinci_Callback*) ®ion_tree_callback );
00489 }
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 class Global_CFG_Callback : public DaVinci_Callback {
00512 private:
00513 INT32 _pseudo_node_num;
00514 public:
00515 Global_CFG_Callback (INT32 label_num = 0)
00516 {_pseudo_node_num = label_num;}
00517 ~Global_CFG_Callback (){}
00518
00519 virtual void Node_Select( const INT n_ids, const NODE_ID id_array[] );
00520 };
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531 void
00532 Global_CFG_Callback::Node_Select(const INT n_ids, const NODE_ID id_array[])
00533 {
00534 BB* node;
00535 for (INT32 i = 0; i < n_ids; ++i) {
00536 node = (BB*) id_array[i];
00537 if ( ((INT32)(INTPTR)node) > _pseudo_node_num)
00538 draw_bb_op ( (BB*) node );
00539 }
00540 }
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557 void
00558 draw_global_cfg(const char *mes)
00559 {
00560 if (! DaVinci::enabled (TRUE)) return;
00561
00562 MEM_POOL dv_pool;
00563 dv_pool.magic_num = 0;
00564 MEM_POOL_Constructor pool (&dv_pool, "DaVinci", FALSE);
00565
00566 DaVinci dv (&dv_pool, NULL);
00567
00568 char window_title[128];
00569 if ( NULL == mes)
00570 sprintf(window_title,"Global CFG - %s", Cur_PU_Name);
00571 else
00572 sprintf(window_title,"Global CFG - %s - %s ", Cur_PU_Name, mes);
00573 Is_True(strlen(window_title) < 128, ("Window Title buf overflowed"));
00574 dv.Title(window_title);
00575
00576
00577 char nlabel[64];
00578 INT32 pseudo_node_id=0;
00579 CFG_LABEL_INFO label_info_item;
00580 std::vector<CFG_LABEL_INFO> label_info_vector;
00581 BOOL show_edge_label;
00582 NODE_TYPE nt, nt_plain, nt_entry, nt_exit, nt_multi,
00583 nt_call, nt_pseudo;
00584 EDGE_TYPE et_source,et_destination;
00585
00586
00587 nt_entry.Shape (NS_RHOMBUS);
00588 nt_exit.Shape (NS_ELLIPSE);
00589 nt_multi.Shape (NS_CIRCLE);
00590 nt_pseudo.Shape (NS_TEXT);
00591
00592 et_source.Direction(ED_NONE);
00593
00594 if (VT_Enable_CFG_Label) show_edge_label = TRUE;
00595 else show_edge_label = FALSE;
00596
00597 dv.Graph_Begin ();
00598
00599
00600 for (BB* bb = REGION_First_BB; bb != NULL; bb = BB_next(bb)) {
00601 sprintf(nlabel,"%d",BB_id(bb));
00602 Is_True(strlen(nlabel) < 64, ("Node Label buf overflowed"));
00603
00604 nt = nt_plain;
00605 if (BBlist_Len(BB_preds(bb)) > 1 || BBlist_Len(BB_succs(bb)) > 1)
00606 nt = nt_multi;
00607 if (BB_entry(bb)) nt = nt_entry;
00608 if (BB_exit(bb)) nt = nt_exit;
00609
00610 if (BB_call(bb)) nt.Boarder (NB_DOUBLE);
00611
00612
00613 OP *br_op = BB_xfer_op(bb);
00614 if ( NULL != br_op )
00615 switch (OP_code(br_op))
00616 {
00617 case TOP_br_r_call :
00618 case TOP_br_call :
00619 case TOP_brl_call : nt.Color ("palegreen"); break;
00620
00621 case TOP_br_cloop : nt.Color ("pink"); break;
00622
00623 case TOP_br_ctop :
00624 case TOP_br_wtop : nt.Color ("lightgoldenrod"); break;
00625
00626 default : nt.Color ("gray");
00627 }
00628
00629
00630
00631 dv.Node_Begin (NODE_ID (bb), nlabel, nt);
00632 BBLIST *sedge;
00633 BB *succ_bb;
00634 for (sedge = bb->succs; sedge != NULL; sedge = sedge-> next)
00635 {
00636 succ_bb = sedge -> item;
00637
00638 if (show_edge_label)
00639 {
00640
00641 label_info_item.prob = sedge -> prob;
00642 label_info_item.freq = sedge -> freq;
00643 label_info_item.dest_node_id = NODE_ID (succ_bb);
00644 label_info_vector.push_back (label_info_item);
00645
00646 dv.Out_Edge (EDGE_ID (NODE_ID (bb), NODE_ID ((INTPTR)pseudo_node_id)),
00647 et_source,
00648 NODE_ID ((INTPTR)pseudo_node_id));
00649
00650 pseudo_node_id ++;
00651 }
00652 else {
00653
00654 dv.Out_Edge (EDGE_ID (NODE_ID (bb), NODE_ID (succ_bb)),
00655 et_destination,
00656 NODE_ID (succ_bb));
00657 }
00658 }
00659 dv.Node_End ();
00660 }
00661
00662
00663 if (show_edge_label)
00664 for (INT32 i=0; i<pseudo_node_id ; i++)
00665 {
00666
00667 sprintf(nlabel,"%#.2f / %#.2f", label_info_vector [i].prob,
00668 label_info_vector [i].freq);
00669 Is_True(strlen(nlabel) < 64, ("Node Label buf overflowed"));
00670 dv.Node_Begin (NODE_ID ((INTPTR)i), nlabel, nt_pseudo);
00671 dv.Out_Edge(EDGE_ID(NODE_ID((INTPTR)i),label_info_vector[i].dest_node_id),
00672 et_destination,
00673 label_info_vector [i].dest_node_id );
00674 dv.Node_End ();
00675 }
00676
00677 dv.Graph_End ();
00678
00679 Global_CFG_Callback global_cfg_callback(pseudo_node_id);
00680 dv.Event_Loop( (DaVinci_Callback*) &global_cfg_callback );
00681 }