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 #include "sched_seq.h"
00050
00051
00052 SCHED_SEQ :: SCHED_SEQ (REGION* r, MEM_POOL* mp) :
00053 _candidates (mp) {
00054 _rgn = r ;
00055 _mp = mp;
00056 _cur = NULL;
00057 }
00058
00059 BOOL
00060 SCHED_SEQ :: Qualified (REGIONAL_CFG_NODE *nd) {
00061 if (nd->Is_Region()) return FALSE;
00062
00063 BB* bb = nd->BB_Node () ;
00064
00065 if (BB_Is_Isolated_From_Sched (bb)) {
00066 return FALSE;
00067 }
00068
00069 return !BB_entry(bb) && !BB_exit(bb);
00070 }
00071
00072 BOOL
00073 SCHED_SEQ :: Node1_Is_Sparser
00074 (REGIONAL_CFG_NODE *nd1, REGIONAL_CFG_NODE *nd2) {
00075
00076
00077
00078
00079 INT32 density1 = nd1->Is_Region () ? 0 : BB_length(nd1->BB_Node());
00080 INT32 density2 = nd2->Is_Region () ? 0 : BB_length(nd2->BB_Node());
00081
00082 return density1 > density2 ;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 REGIONAL_CFG_NODE*
00096 TOPDOWN_SCHED_SEQ::next_node (void) {
00097
00098 float freq = -1.0f ;
00099 REGIONAL_CFG_NODE * best = NULL;
00100 INT32 index = -1;
00101
00102 INT32 root_num = _candidates.size();
00103 for (INT32 idx = root_num - 1 ; idx >= 0 ; idx--) {
00104
00105 REGIONAL_CFG_NODE* cand = _candidates[idx] ;
00106 float node_freq = cand->Home_Region ()-> Regional_Cfg ()->
00107 Node_Freq (cand);
00108 float deviation = node_freq/200.0 ;
00109
00110 if (!best || (node_freq - deviation) > freq ||
00111 node_freq + deviation > freq &&
00112 Node1_Is_Sparser (cand,best)) {
00113 best = cand ;
00114 freq = node_freq ;
00115 index = idx ;
00116 }
00117 }
00118
00119 if (!best) return NULL;
00120
00121 if (index + 1 != root_num) {
00122 _candidates[index] = _candidates[root_num - 1];
00123 }
00124
00125 _candidates.resize(--root_num);
00126
00127 for (CFG_SUCC_NODE_ITER succs(best) ; succs != 0 ; ++succs) {
00128 if (! --_node_info_map[*succs]._n_pred) {
00129 _candidates.push_back(*succs);
00130 }
00131 }
00132
00133 return best ;
00134 }
00135
00136 TOPDOWN_SCHED_SEQ::TOPDOWN_SCHED_SEQ (REGION *rgn, MEM_POOL *mp) :
00137 SCHED_SEQ (rgn, mp) {
00138
00139
00140
00141 for (TOPOLOGICAL_REGIONAL_CFG_ITER iter(_rgn->Regional_Cfg());
00142 iter != 0; ++iter) {
00143 _node_info_map[*iter]._n_pred = (*iter)->Pred_Num();
00144 }
00145 }
00146
00147 BB*
00148 TOPDOWN_SCHED_SEQ :: First (void) {
00149
00150 _candidates.clear () ;
00151 _cur = NULL ;
00152 _candidates.push_back (_rgn->Entries()[0]);
00153
00154 return Next () ;
00155 }
00156
00157 BB*
00158 TOPDOWN_SCHED_SEQ :: Next (void) {
00159
00160 while (REGIONAL_CFG_NODE * nd = next_node ()) {
00161 if (Qualified(nd)) return _cur = nd->BB_Node();
00162 }
00163
00164 return _cur = NULL;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 DEEPDOWN_SCHED_SEQ :: DEEPDOWN_SCHED_SEQ (REGION* r, MEM_POOL* mp) :
00176 SCHED_SEQ (r, mp) {
00177 }
00178
00179 BB*
00180 DEEPDOWN_SCHED_SEQ :: First (void) {
00181
00182 _candidates.clear () ;
00183 _cur = NULL ;
00184 _candidates.push_back (_rgn->Entries()[0]);
00185
00186 return Next () ;
00187 }
00188
00189 BB*
00190 DEEPDOWN_SCHED_SEQ :: Next (void) {
00191
00192 INT nd_idx;
00193
00194 float most_freq = -1.0f;
00195 REGIONAL_CFG_NODE* n, *most_freq_n;
00196 INT idx = -1;
00197
00198 for (nd_idx = _candidates.size () - 1;
00199 nd_idx >= 0 ;
00200 nd_idx --) {
00201
00202 n = _candidates[nd_idx];
00203
00204 float node_freq = n->Home_Region ()-> Regional_Cfg ()->
00205 Node_Freq (n);
00206
00207 Is_True (node_freq >= 0.0f, ("Negative frequency"));
00208
00209 #define FREQ_DEVATION (0.1f)
00210 float u = node_freq * (1 + FREQ_DEVATION);
00211 float l = node_freq * (1 - FREQ_DEVATION);
00212 #undef FREQ_DEVATION
00213
00214 if (u < most_freq) { continue; }
00215 if (l > most_freq ||
00216 Node1_Is_Sparser (_candidates[nd_idx], _candidates[idx])) {
00217 idx = nd_idx;
00218 most_freq = node_freq;
00219 }
00220 }
00221
00222 if (idx == -1) return NULL;
00223 most_freq_n = _candidates[idx];
00224
00225
00226
00227 _candidates[idx] = _candidates[_candidates.size () - 1];
00228 _candidates.resize (_candidates.size () - 1);
00229
00230
00231
00232
00233 for (CFG_SUCC_NODE_ITER iter(most_freq_n); iter != 0; ++iter) {
00234 if (find(_candidates.begin (), _candidates.end (), *iter) ==
00235 _candidates.end ()) {
00236
00237 _candidates.push_back (*iter);
00238 }
00239 }
00240
00241 if (n->Is_Region () || !Qualified(most_freq_n)) {
00242 return Next ();
00243 }
00244
00245 return _cur = most_freq_n->BB_Node ();
00246 }
00247
00248