Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

cfg.h

Go to the documentation of this file.
00001 /*
00002         Copyright (C) 1997 CFU Corporation
00003 
00004         Author: Chao-yinig Fu
00005         Date: Oct. 21 1997
00006 
00007         ^..^
00008         (00)
00009 
00010          $__$
00011         <~00~>
00012          (oo)
00013           ||
00014 
00015         ```````
00016         C ^|^ D
00017          \ O /
00018 */
00019 
00020 #ifndef INCLUDED_CFG_H
00021 #define INCLUDED_CFG_H
00022 
00023 #include <lego.H>
00024 #include <assert.h>
00025 
00026 class MST;
00027 
00028 #define ExitNodeId -2           // define node id of an artificial exit node
00029 #define ExitToEntryEdgeId -2    // define edge id from _exit to the _entry
00030 #define LastToExitEdgeId -3     // define edge id from last node to _exit
00031                                 // (from -3, -4, .....)
00032 
00033 enum Color
00034 {
00035         WHITE=0,
00036         GRAY,
00037         BLACK
00038 };
00039 
00040 enum Edge_Type
00041 {
00042         ET_UNDEFINED=0,         // undefined
00043         ET_TREE,                // Tree edge
00044         ET_BACK,                // Back edge
00045         ET_FORWARD,             // Forward edge
00046         ET_CROSS,               // Cross edge
00047         ET_NEW,                 // New edge which is added after removing
00048         ET_SELFLOOP             // Selfloop edge (back edge)
00049 };
00050 
00051 class Node
00052 {
00053 public:
00054         Node():_node_id(-1),_weight(0),_edge_id(0),_direction(1),_next_node(NULL),_edge_type(ET_UNDEFINED),_hidden(0),_num_paths(0),_entry_to_dest(NULL),_src_to_exit(NULL),_eff_sum(0)
00055         {}
00056 
00057         Node(int node_id):_node_id(node_id),_weight(0),_edge_id(0),_direction(1),_next_node(NULL),_edge_type(ET_UNDEFINED),_hidden(0),_num_paths(0),_entry_to_dest(NULL),_src_to_exit(NULL), _eff_sum(0)
00058         {}
00059 
00060         ~Node() 
00061         {
00062         }
00063 
00064         void set_next_node(Node *n) {_next_node=n;}
00065         void set_node_id(int i) {_node_id=i;}
00066         void set_weight(int i) {_weight=i;}
00067         void set_edge_id(int i) {_edge_id=i;}
00068         void set_direction(int i) {_direction=i;}
00069         void set_edge_type(Edge_Type i) {_edge_type=i;}
00070         void set_hidden(int i) {_hidden=i;}
00071         void set_num_paths(int i) {_num_paths=i;}
00072         void set_entry_to_dest(Node *i) {_entry_to_dest=i;}
00073         void set_src_to_exit(Node *i) {_src_to_exit=i;}
00074         void set_eff_sum(int i) {_eff_sum=i;}
00075 
00076         Node *next_node() {return _next_node;}
00077         int node_id() {return _node_id;}
00078         int weight() {return _weight;}
00079         int edge_id() {return _edge_id;}
00080         int direction() {return _direction;}
00081         Edge_Type edge_type() {return _edge_type;}
00082         int hidden() {return _hidden;}
00083         int num_paths() {return _num_paths;}
00084         Node *entry_to_dest() {return _entry_to_dest;}
00085         Node *src_to_exit() {return _src_to_exit;}
00086         int eff_sum() {return _eff_sum;}
00087 
00088 private:
00089         Node *_next_node;
00090         int _node_id;
00091         int _weight;    // edge weight
00092         int _edge_id;   // edge id
00093         int _direction; // 0=in, 1=out
00094         Edge_Type _edge_type;
00095         int _hidden;    // 1=this edge is hidden, 0=not hidden
00096         int _num_paths;
00097 
00098         //
00099         // Used for transforming back_edge to _entry->dest and src->_exit
00100         // Record this two nodes (adjacency-list)
00101         //
00102         Node *_entry_to_dest;
00103         Node *_src_to_exit;
00104 
00105         //
00106         // For efficient event counting
00107         //
00108         int _eff_sum;
00109 };
00110 
00111 class Node_List
00112 {
00113 public:
00114         Node_List():_node(NULL),_visit(0),_next_node_list(NULL),_color(WHITE),_predecessor(NULL),_start_time(0),_finish_time(0),_num_paths(0) {}
00115 
00116         ~Node_List()
00117         {
00118                 Node *current_node,*next_node;
00119                 for(current_node=node();current_node!=NULL;current_node=next_node)
00120                 {
00121                         next_node=current_node->next_node();
00122                         delete current_node;
00123                 }
00124         }
00125 
00126         Node *node() {return _node;}
00127         int visit() {return _visit;}
00128         Node_List *next_node_list() {return _next_node_list;}
00129 
00130         void set_node(Node *n) {_node=n;}
00131         void set_visit(int i) {_visit=1;}
00132         void set_next_node_list(Node_List *nl) {_next_node_list=nl;}
00133 
00134         Color color() {return _color;}
00135         Node_List *predecessor() {return _predecessor;}
00136         int start_time() {return _start_time;}
00137         int finish_time() {return _finish_time;}
00138         int num_paths() {return _num_paths;}
00139 
00140         void set_color(Color i) {_color=i;}
00141         void set_predecessor(Node_List *i) {_predecessor=i;}
00142         void set_start_time(int i) {_start_time=i;}
00143         void set_finish_time(int i) {_finish_time=i;}
00144         void set_num_paths(int i) {_num_paths=i;}
00145 private:
00146         Node *_node;
00147         Node_List *_next_node_list;
00148         int _visit;     // 0=not visit, 1=visit;
00149 
00150         //
00151         // For depth first search
00152         //
00153         Color _color;
00154         Node_List *_predecessor;        // predecessor in the DFS tree
00155         int _start_time;
00156         int _finish_time;
00157         int _num_paths;
00158 };
00159 
00160 class CFG
00161 {
00162 public:
00163         CFG():_root(NULL),_out_edge_count(0),_in_edge_count(0),_node_count(0),_max_edge_id(0),_entry(NULL),_exit(0),_time(0),_last_to_exit_edge_id(LastToExitEdgeId),_topological_list(NULL) {}
00164 
00165         ~CFG() 
00166         {
00167                 delete[] _proc_name;
00168 
00169                 Node_List *current_nl,*next_nl;
00170                 for(current_nl=_root;current_nl!=NULL;current_nl=next_nl)
00171                 {
00172                         next_nl=current_nl->next_node_list();
00173                         delete current_nl;
00174                 }
00175 
00176                 delete[] _topological_list;
00177         }
00178 
00179         void set_root(Node_List *nl) {_root=nl;}
00180         void set_entry(Node_List *nl) {_entry=nl;}
00181         void set_exit(Node_List *nl) {_exit=nl;}
00182 
00183         void set_proc_name(char *i)
00184         {
00185                 _proc_name=new char[strlen(i)+1];
00186                 strcpy(_proc_name,i);
00187         }
00188 
00189         Node_List *root() {return _root;}
00190         char *proc_name() {return _proc_name;}
00191         int node_count() {return _node_count;}
00192         Node_List *entry() {return _entry;}
00193         Node_List *exit() {return _exit;}
00194 
00195         void read_file();
00196 
00197         void build(legoProc *proc_ptr);
00198         void recursive_build(legoProc *proc_ptr,legoRegion *region_ptr);
00199         void build_one_block(legoProc *proc_ptr,legoRegion *region_ptr);
00200 
00201         void print(FILE *f);
00202         Node_List *find_node(int node_id);
00203         
00204         int edge_count() 
00205         {
00206                 assert(_in_edge_count==_out_edge_count);
00207                 return _in_edge_count;
00208         }
00209 
00210         void dfs(int option);           // depth first search
00211         void dfs_visit(Node_List *nl,int option);       // depth first search visit     
00212 
00213         void process_back_edge();
00214         Node *add_edge(Node_List *souce,Node_List *dest,int edge_id);
00215         void add_edge_from_exit_to_entry();
00216 
00217         void print_dfs_tree();
00218         void print_edge_type(Edge_Type et);
00219         void print_color(Color c);
00220         void print_topological_list();
00221 
00222         void unhide_EXIT_edge();
00223         int assign_value();     // path profiling Figure 5 (Micro 29)
00224 
00225         //
00226         // For event counting algorithm
00227         //
00228         void event_counting(MST *mst);
00229         void event_dfs(int events,Node_List *v,Node_List *e_nl,Node *e,MST *mst);
00230         void print_eff_sum(MST *mst);
00231 
00232         //
00233         // First edge: e_nl -> e_n
00234         // Second edge: f_nl -> f_n
00235         //
00236         // Return 1: same direction
00237         //        0: opposite direction
00238         //
00239         int event_dir(Node_List *e_nl,Node *e_n,Node_List *f_nl,Node *f_n);
00240 
00241         void find_type_of_instrumentation(MST *mst);
00242         int num_of_incoming_edge(Node_List *vertex);
00243         void hide_ET_NEW_edge();
00244         void regenerate_path(FILE *ifp);
00245 
00246 private:
00247         Node_List *_root;       // The root of the adjacency list
00248         Node_List *_entry;      //Node_List of the entry node in CFG
00249         Node_List *_exit;       //Node_List of the exit node in CFG
00250         int _in_edge_count;     // number of in edges
00251         int _out_edge_count;    // number of out edges
00252         int _node_count;        // number of nodes
00253         char *_proc_name;
00254         int _max_edge_id;       // max edge id in CFG
00255         int _last_to_exit_edge_id;      // define the edge id from last to _exit
00256 
00257         //
00258         // For DFS
00259         //
00260         int _time;              // global time
00261 
00262         //
00263         // For topological sort
00264         //
00265         int *_topological_list;
00266         int _index_of_topological_list;
00267 };
00268 
00269 #endif //INCLUDED_CFG_H

Generated on Mon Jul 21 20:24:04 2003 for TINKER LEGO DOC by doxygen 1.3.2