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 #ifndef fb_cfg_INCLUDED
00061 #define fb_cfg_INCLUDED
00062
00063 #include "mempool_allocator.h"
00064 #include <vector>
00065 #include <deque>
00066 #include <ext/hash_map>
00067 #include "fb_whirl.h"
00068
00069
00070
00071
00072
00073 typedef INT32 FB_NODEX;
00074 #define FB_NODEX_UNINIT (-1)
00075 #define FB_NODEX_VALID(nx) ((nx) >= 0)
00076
00077
00078
00079
00080
00081
00082
00083
00084 struct FB_NODE {
00085
00086 vector<FB_NODEX> preds;
00087 vector<FB_NODEX> succs;
00088
00089 bool one_edge_preds;
00090 bool one_edge_succs;
00091
00092 INT undelayed_succs;
00093
00094
00095 FB_EDGE_TYPE node_type;
00096 WN *source;
00097
00098
00099
00100 bool in_out_same;
00101 FB_FREQ freq_total_in;
00102 FB_FREQ freq_total_out;
00103
00104 INT unknown_in;
00105 INT unknown_out;
00106 INT unexact_in;
00107 INT unexact_out;
00108
00109 FB_NODE() :
00110 one_edge_preds( true ),
00111 one_edge_succs( true ),
00112 undelayed_succs( 0),
00113 node_type( FB_EDGE_UNINIT ),
00114 source( NULL ),
00115 in_out_same( true ),
00116 freq_total_in( FB_FREQ_UNKNOWN ),
00117 freq_total_out( FB_FREQ_UNKNOWN ),
00118 unknown_in( 1 ),
00119 unknown_out( 1 ),
00120 unexact_in( 1 ),
00121 unexact_out( 1 ) {}
00122
00123 FB_NODE( FB_EDGE_TYPE type, WN *src, bool same,
00124 FB_FREQ freq_in, FB_FREQ freq_out ) :
00125 one_edge_preds( true ),
00126 one_edge_succs( true ),
00127 undelayed_succs( 0 ),
00128 node_type( type ),
00129 source( src ),
00130 in_out_same( same ),
00131 freq_total_in( freq_in ),
00132 freq_total_out( freq_out ),
00133 unknown_in( freq_in.Known() ? 0 : 1 ),
00134 unknown_out( freq_out.Known() ? 0 : 1 ),
00135 unexact_in( freq_in.Exact() ? 0 : 1 ),
00136 unexact_out( freq_out.Exact() ? 0 : 1 ) {}
00137
00138 void Print( FILE *fp, FB_NODEX nx ) const {
00139 INT t;
00140 char buffer[FB_EDGE_TYPE_NAME_LENGTH];
00141 FB_EDGE_TYPE_sprintf( buffer, node_type );
00142 fprintf( fp, "node %d: node_type %s, source 0x%p, in_out_same %c,\n",
00143 nx, buffer, source, ( in_out_same ? 'Y' : 'N' ) );
00144 fprintf( fp, " one_edge_preds %c, one_edge_succs %c,"
00145 " undelayed_succs %d,\n", ( one_edge_preds ? 'Y' : 'N' ),
00146 ( one_edge_succs ? 'Y' : 'N' ), undelayed_succs );
00147 fprintf( fp, " unknown_in %d, unexact_in %d, freq_total_in ",
00148 unknown_in, unexact_in );
00149 freq_total_in.Print( fp );
00150 fprintf( fp, ", preds [" );
00151 for ( t = 0; t < preds.size(); t++ )
00152 fprintf( fp, " %d", preds[t] );
00153 fprintf( fp, " ],\n");
00154 fprintf( fp, " unknown_out %d, unexact_out %d, freq_total_out ",
00155 unknown_out, unexact_out );
00156 freq_total_out.Print( fp );
00157 fprintf( fp, ", succs [" );
00158 for ( t = 0; t < succs.size(); t++ )
00159 fprintf( fp, " %d", succs[t] );
00160 fprintf( fp, " ]\n");
00161 }
00162 };
00163
00164 struct FB_EDGE_DELAYED {
00165 FB_NODEX source;
00166 LABEL_IDX destination;
00167
00168 FB_EDGE_DELAYED( FB_NODEX src, LABEL_IDX dst ) {
00169 source = src;
00170 destination = dst;
00171 }
00172 };
00173
00174
00175
00176 class FB_CFG_MEM {
00177 protected:
00178 MEM_POOL _m;
00179
00180 FB_CFG_MEM() {
00181 MEM_POOL_Initialize( &_m, "FB_CFG_MEM", true );
00182 MEM_POOL_Push( &_m );
00183 }
00184 ~FB_CFG_MEM() {
00185 MEM_POOL_Pop( &_m );
00186 MEM_POOL_Delete(&_m );
00187 }
00188 };
00189
00190 class FB_CFG : public FB_CFG_MEM {
00191 private:
00192
00193 bool _trace;
00194 bool _trace_draw;
00195 bool _trace_before;
00196 bool _trace_prop;
00197
00198
00199 vector< FB_NODE, mempool_allocator<FB_NODE> > _nodes;
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 hash_map< LABEL_IDX, FB_NODEX, __gnu_cxx::hash<LABEL_IDX>, std::equal_to<LABEL_IDX>,
00212 mempool_allocator< pair<LABEL_IDX,FB_NODEX> > > _lblx_to_nx;
00213
00214 std::deque< FB_EDGE_DELAYED, mempool_allocator<FB_EDGE_DELAYED> > _delayed_edges;
00215
00216 FB_NODEX _curr_nx;
00217
00218 private:
00219
00220
00221
00222 FB_NODEX New_node();
00223 FB_NODEX New_node( FB_EDGE_TYPE node_type, WN *source, FB_FREQ freq_total_in,
00224 FB_FREQ freq_total_out, bool in_out_same = false );
00225 FB_NODEX New_node( FB_EDGE_TYPE node_type, WN *source,
00226 FB_FREQ freq_total_in ) {
00227 return New_node( node_type, source, freq_total_in, freq_total_in, true );
00228 }
00229
00230 void Add_label( LABEL_IDX labelx, FB_NODEX nx ) { _lblx_to_nx[labelx] = nx; }
00231
00232 void Add_edge(FB_NODEX nx_src, FB_NODEX nx_dst, bool delayed = false );
00233 void Adjust_edge( FB_NODEX nodex);
00234 void Add_delayed_edge( FB_NODEX nx_src, WN *wn );
00235 void Complete_delayed_edges();
00236
00237 FB_NODEX Curr() const { return _curr_nx; }
00238 void Set_curr( FB_NODEX nx ) { _curr_nx = nx; }
00239 FB_NODEX Get_curr();
00240
00241
00242
00243 void Walk_WN_expression( WN *wn );
00244 void Walk_WN_test_expression( WN *wn, FB_NODEX true_nx, FB_NODEX false_nx );
00245 void Walk_WN_statement( WN *wn );
00246
00247 void Freq_propagate_node_in( FB_NODEX nx );
00248 void Freq_propagate_node_out( FB_NODEX nx );
00249 void Freq_propagate();
00250
00251 char *Node_label( FB_NODEX nx ) const;
00252
00253 public:
00254
00255 FB_CFG() :
00256 _trace( Get_Trace( TP_FEEDBACK, TP_FEEDBACK_CFG ) ),
00257 _trace_draw( Get_Trace( TP_FEEDBACK, TP_FEEDBACK_CFG_DRAW ) ),
00258 _trace_before( Get_Trace( TP_FEEDBACK, TP_FEEDBACK_CFG_BEFORE ) ),
00259 _trace_prop( Get_Trace( TP_FEEDBACK, TP_FEEDBACK_CFG_PROP ) ),
00260 _nodes( mempool_allocator<FB_NODE>(&_m) ),
00261 _lblx_to_nx( 100, __gnu_cxx::hash<LABEL_IDX>(), std::equal_to<LABEL_IDX>(),
00262 mempool_allocator< pair<LABEL_IDX,FB_NODEX> >(&_m) ),
00263 _delayed_edges( mempool_allocator<FB_EDGE_DELAYED>(&_m) ),
00264 _curr_nx( FB_NODEX_UNINIT ) {}
00265
00266 ~FB_CFG() {}
00267
00268 void Construct_from_whirl( WN *wn_root, const char *caller );
00269 void Guess_unknowns( WN *wn_root, const char *caller );
00270 FB_VERIFY_STATUS Verify_frequencies() const;
00271 void Patch_whirl_frequencies() const;
00272
00273 void Print( FILE *fp ) const;
00274 void Print_node( FILE *fp, FB_NODEX nx ) const;
00275 void Print_edge( FILE *fp, FB_NODEX src_nx, FB_NODEX dst_nx ) const;
00276 void Draw() const;
00277 };
00278
00279 void dV_view_fb_cfg(const FB_CFG& cfg, WN *root_wn, const char *caller);
00280
00281 #endif