Changeset 52 for sources/src/process_dependency.cc
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/process_dependency.cc
r27 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : process_dependancy.cc |6 | |7 | Author : Buchmann Richard |8 | |9 | Date : 21_09_2004 |10 | |11 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : process_dependancy.cc | 6 | | 7 | Author : Buchmann Richard | 8 | | 9 | Date : 21_09_2004 | 10 | | 11 \------------------------------------------------------------*/ 12 12 13 13 /* … … 37 37 #include <iostream> 38 38 #include <fstream> 39 39 40 #include "assert.h" 40 41 #include "process_dependency.h" … … 44 45 #include "sc_module.h" 45 46 #include "sc_ver.h" 47 46 48 #ifdef HAVE_CONFIG_H 47 49 #include "config.h" … … 52 54 namespace sc_core { 53 55 54 bool 55 ProcessDependency::operator < (const ProcessDependency &a) const 56 { 57 if (a.source < source) 58 return false; 59 if (a.destination < destination) 60 return false; 61 return true; 62 } 63 64 static 65 void 66 dot_write (ofstream &o, 67 const ProcessDependencyGraph &g) 68 { 69 string s; 70 ProcessDependencyGraph::const_iterator it; 71 for (it = g.begin (); it != g.end (); ++it) 72 { 73 string name; 74 name = it->source->module->name(); 75 name += "_"; 76 name += it->source->name; 77 o << simplify_name(name.c_str(),s); 78 o << " -> "; 79 name = it->destination->module->name(); 80 name += "_"; 81 name += it->destination->name; 82 o << simplify_name(name.c_str(),s); 83 o << "\n"; 84 } 85 } 86 87 static 88 void 89 dot_write (ofstream &o, 90 const ProcessDependencyList &l) 91 { 92 const method_process_t *old = NULL; 93 string s; 94 ProcessDependencyList::const_iterator it; 95 for (it = l.begin (); it != l.end (); ++it) 96 { 97 const method_process_t *current = *it; 98 if (old) 99 { 100 string name; 101 name = old->module->name(); 102 name += "_"; 103 name += old->name; 104 o << simplify_name(name.c_str(),s); 105 o << " -> "; 106 name = current->module->name(); 107 name += "_"; 108 name += current->name; 109 o << simplify_name(name.c_str(),s); 110 o << "\n"; 111 } 112 old = current; 113 } 114 } 115 116 bool 117 ProcessDependencyGraph2dot (const char *name, 118 const ProcessDependencyGraph& g) 119 { 120 if (!name) 121 return false; 122 string filename; 123 filename = name; 124 filename += ".dot"; 125 ofstream o; 126 o.open (filename.c_str(),ios::out | ios::trunc); 127 if (o.is_open () == false) 128 return false; 129 o << "// Ordered process list\n" 130 "// Generated by " 131 << sc_version () << "\n"; 132 o << "strict digraph " << name << " {\n"; 133 dot_write (o,g); 134 o << "}\n"; 135 o.close (); 136 if (dump_stage) 137 cerr << "Port Dependency Graph written into '" 138 << filename << "'.\n"; 139 return true; 140 } 141 142 bool 143 ProcessDependencyList2dot (const char *name, 144 const ProcessDependencyList& l) 145 { 146 if (!name) 147 return false; 148 string filename; 149 filename = name; 150 filename += ".dot"; 151 ofstream o; 152 o.open (filename.c_str(),ios::out | ios::trunc); 153 if (o.is_open () == false) 154 return false; 155 o << "// Ordered process list\n" 156 "// Generated by " 157 << sc_version () << "\n"; 158 o << "digraph " << name << " {\n"; 159 dot_write (o,l); 160 o << "}\n"; 161 o.close (); 162 return true; 163 } 164 165 #if 0 166 ProcessDependencyGraph* 167 sc_core::MakeProcessDependencyGraph (const SignalDependencyGraph& g) 168 { 169 if (dump_stage) 170 cerr << "Making module dependency graph...\n"; 171 172 ProcessDependencyGraph *mod_g = new ProcessDependencyGraph (); 173 SignalDependencyGraph::const_iterator it; 174 for (it = g.begin(); it != g.end(); ++it) 175 { 176 ProcessDependency s; 177 s.destination = it->method; 178 SignalDependencyGraph::const_iterator it2; 179 for (it2 = g.begin(); it2 != g.end(); ++it2) 180 { 181 if (it2->source == it->destination) 182 { 183 s.source = it2->method; 184 mod_g->insert(s); 185 } 186 } 187 } 188 return mod_g; 189 } 190 191 static 192 const method_process_t* 193 get_method (const equi_t &e, const SignalDependencyGraph &sig) 194 { 195 SignalDependencyGraph::const_iterator it; 196 for (it = sig.begin (); it != sig.end (); ++it) 197 { 198 if (it->destination == &e) 199 return it->method; 200 } 201 return NULL; 202 } 203 #endif 204 205 206 static 207 bool 208 is_leef (const SignalDependencyGraph &g, 209 const equi_t *e) 210 { 211 SignalDependencyGraph::const_iterator it; 212 for (it = g.begin (); it != g.end (); ++it) 213 { 214 if (it->source == e) 215 return false; 216 } 217 return true; 218 } 219 220 static 221 bool 222 has_all_leef (const SignalDependencyGraph &sig, 223 const method_process_t *m) 224 { 225 SignalDependencyGraph::const_iterator sig_it; 226 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 227 if ((sig_it->method == m) 228 && (!is_leef (sig, sig_it->destination))) 229 return false; 230 return true; 231 } 232 233 static 234 const method_process_t* 235 get_best_process (const SignalDependencyGraph &sig) 236 { 237 SignalDependencyGraph::const_iterator sig_it; 238 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 239 { 240 if (has_all_leef (sig, sig_it->method)) 241 return sig_it->method; 242 } 243 return NULL; 244 } 56 bool ProcessDependency::operator < (const ProcessDependency &a) const { 57 if (a.source < source) { 58 return false; 59 } 60 if (a.destination < destination) { 61 return false; 62 } 63 return true; 64 } 65 66 67 static void dot_write (ofstream & o, const ProcessDependencyGraph & g) { 68 string s; 69 ProcessDependencyGraph::const_iterator it; 70 for (it = g.begin (); it != g.end (); ++it) { 71 string name; 72 name = it->source->module->name(); 73 name += "_"; 74 name += it->source->name; 75 o << simplify_name(name.c_str(),s); 76 o << " -> "; 77 name = it->destination->module->name(); 78 name += "_"; 79 name += it->destination->name; 80 o << simplify_name(name.c_str(),s); 81 o << "\n"; 82 } 83 } 84 85 86 static void dot_write(ofstream &o, const ProcessDependencyList &l) { 87 const method_process_t * old = NULL; 88 string s; 89 ProcessDependencyList::const_iterator it; 90 for (it = l.begin (); it != l.end (); ++it) { 91 const method_process_t * current = *it; 92 if (old) { 93 string name; 94 name = old->module->name(); 95 name += "_"; 96 name += old->name; 97 o << simplify_name(name.c_str(),s); 98 o << " -> "; 99 name = current->module->name(); 100 name += "_"; 101 name += current->name; 102 o << simplify_name(name.c_str(),s); 103 o << "\n"; 104 } 105 old = current; 106 } 107 } 108 109 110 bool ProcessDependencyGraph2dot(const char * name, const ProcessDependencyGraph& g) { 111 if (!name) { 112 return false; 113 } 114 string filename; 115 filename = name; 116 filename += ".dot"; 117 ofstream o; 118 o.open (filename.c_str(),ios::out | ios::trunc); 119 if (o.is_open () == false) { 120 return false; 121 } 122 o << "// Ordered process list\n" 123 "// Generated by " 124 << sc_version () << "\n"; 125 o << "strict digraph " << name << " {\n"; 126 dot_write (o,g); 127 o << "}\n"; 128 o.close (); 129 if (dump_stage) { 130 cerr << "Port Dependency Graph written into '" 131 << filename << "'.\n"; 132 } 133 return true; 134 } 135 136 137 bool ProcessDependencyList2dot(const char * name, const ProcessDependencyList& l) { 138 if (!name) { 139 return false; 140 } 141 string filename; 142 filename = name; 143 filename += ".dot"; 144 ofstream o; 145 o.open (filename.c_str(),ios::out | ios::trunc); 146 if (o.is_open () == false) { 147 return false; 148 } 149 o << "// Ordered process list\n" 150 "// Generated by " 151 << sc_version () << "\n"; 152 o << "digraph " << name << " {\n"; 153 dot_write (o,l); 154 o << "}\n"; 155 o.close (); 156 return true; 157 } 158 159 160 static bool is_leef(const SignalDependencyGraph & g, const equi_t * e) { 161 SignalDependencyGraph::const_iterator it; 162 for (it = g.begin(); it != g.end(); ++it) { 163 if (it->source == e) { 164 return false; 165 } 166 } 167 return true; 168 } 169 170 171 static bool has_all_leef(const SignalDependencyGraph & sig, const method_process_t * m) { 172 SignalDependencyGraph::const_iterator sig_it; 173 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 174 if ((sig_it->method == m) && (!is_leef (sig, sig_it->destination))) { 175 return false; 176 } 177 } 178 return true; 179 } 180 181 182 static const method_process_t * get_best_process(const SignalDependencyGraph & sig) { 183 SignalDependencyGraph::const_iterator sig_it; 184 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 185 if (has_all_leef(sig, sig_it->method)) { 186 return sig_it->method; 187 } 188 } 189 return NULL; 190 } 191 245 192 246 193 /* 247 194 * Remove signals 248 195 */ 249 static 250 void 251 remove_leefs (SignalDependencyGraph &g, 252 const method_process_t &m) 253 { 254 SignalDependencyGraph::iterator it; 255 it = g.begin (); 256 while (it != g.end ()) 257 { 258 const method_process_t *cur_m = it->method; 259 if ((cur_m == &m) && (is_leef (g,it->destination))) 260 { 261 SignalDependencyGraph::iterator x = it++; 262 g.erase (x); 263 } 264 else 265 ++it; 266 } 267 } 196 static void remove_leefs (SignalDependencyGraph & g, const method_process_t & m) { 197 SignalDependencyGraph::iterator it; 198 it = g.begin(); 199 while (it != g.end()) { 200 const method_process_t * cur_m = it->method; 201 if ((cur_m == &m) && (is_leef (g,it->destination))) { 202 SignalDependencyGraph::iterator x = it++; 203 g.erase (x); 204 } 205 else { 206 ++it; 207 } 208 } 209 } 210 268 211 269 212 #if defined(UNUSED) 270 static 271 void 272 print_signals (ostream &o, 273 const SignalDependencyGraph &sig, 274 const method_process_t *method, 275 bool source) 276 { 277 int count = 0; 278 SignalDependencyGraph::const_iterator it; 279 for (it = sig.begin (); it != sig.end (); ++it) 280 { 281 const SignalDependency &dep = *it; 282 const method_process_t *cur_m = dep.method; 283 if (cur_m == method) 284 { 285 const equi_t *e = (source)?dep.source:dep.destination; 286 o << ((count++)?",":"") << get_name (*e); 287 } 288 } 213 static void print_signals (ostream & o, 214 const SignalDependencyGraph & sig, 215 const method_process_t * method, 216 bool source) { 217 int count = 0; 218 SignalDependencyGraph::const_iterator it; 219 for (it = sig.begin(); it != sig.end(); ++it) { 220 const SignalDependency & dep = *it; 221 const method_process_t * cur_m = dep.method; 222 if (cur_m == method) { 223 const equi_t * e = (source) ? dep.source : dep.destination; 224 o << ((count++)?",":"") << get_name (*e); 225 } 226 } 289 227 } 290 228 #endif 291 229 292 static 293 void 294 print_leef_list (SignalDependencyGraph &sig) 295 { 296 typedef map<const equi_t *, const method_process_t *> table_t; 297 table_t table; 298 299 // For each arrow, add destination node into table 300 SignalDependencyGraph::const_iterator sig_it; 301 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 302 { 303 const SignalDependency sd = *sig_it; 304 const equi_t *equi = sd.destination; 305 const method_process_t *method = sd.method; 306 table[equi] = method; 307 } 308 309 // For each arrow, remove source node into table 310 for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) 311 { 312 const SignalDependency sd = *sig_it; 313 const equi_t *e = sd.source; 314 table_t::const_iterator tab_it = table.find (e); 315 if (tab_it != table.end ()) 316 table.erase (e); 317 } 318 319 typedef multimap<const method_process_t *, const equi_t *> table2_t; 320 typedef pair<const method_process_t *, const equi_t *> table2_pair_t; 321 table2_t table2; 322 323 // Build table2 324 table_t::const_iterator it; 325 for (it = table.begin(); it != table.end(); ++it) 326 { 327 const method_process_t *method = it->second; 328 const equi_t *equi = it->first; 329 table2_pair_t pair = table2_pair_t(method,equi); 330 table2.insert(pair); 331 } 332 333 // Print leef list 334 cerr << "Please split following methods :"; 335 table2_t::const_iterator low_it = table2.begin(); 336 table2_t::const_iterator up_it; 337 while (low_it != table2.end ()) 338 { 339 const method_process_t *method = low_it->first; 340 const char *method_name = method->name; 341 const sc_module *module = method->module; 342 const char *module_name = module->name(); 343 cerr << "\n\t - " << module_name << "::" << method_name; 344 cerr << "() to evaluate '"; 345 int count = 0; 346 up_it = table2.upper_bound(low_it->first); 347 table2_t::const_iterator it2; 348 for (it2 = low_it; it2 != up_it; ++it2) 349 { 350 const equi_t *equi = it2->second; 351 const char *signal_name = get_name (*equi); 352 cerr << ((count++)?",":"") << signal_name; 353 } 354 cerr << "' signal(s) separetly"; 355 low_it = up_it; 356 } 357 cerr << "\n"; 358 } 359 360 static 361 void 362 help2resolve (SignalDependencyGraph &sig) 363 { 364 print_leef_list (sig); 365 MethodProcessDependencyGraph2dot ("methodprocess_graph", sig); 366 cerr << "Please look at 'methodprocess_graph.dot' " 367 "to know how to get ride of circular dependencies.\n"; 368 if (dump_all_graph) 369 { 370 SignalDependencyGraph2dot ("reduced_signal_graph", sig); 371 } 372 } 373 374 ProcessDependencyList* 375 MakeProcessDependencyList (const SignalDependencyGraph & _sig_g) 376 { 377 if (dump_stage) 378 cerr << "Making process dependency list...\n"; 379 ProcessDependencyList *mod_l = new ProcessDependencyList (); 380 SignalDependencyGraph sig_g = _sig_g; 381 while (!sig_g.empty ()) 382 { 383 const method_process_t *process = get_best_process (sig_g); 384 #if 1 385 if (process == NULL) 386 { 387 cerr << "Internal Error : Unable to select the best process to schedule.\n"; 388 help2resolve (sig_g); 389 exit (31032005); // 197 390 } 391 #endif 392 mod_l->push_front(process); 393 #if 0 394 cerr << "Process found : " << *process << "\n"; 395 #endif 396 remove_leefs (sig_g, *process); 397 } 398 return mod_l; 230 231 static void print_leef_list (SignalDependencyGraph & sig) { 232 typedef map<const equi_t *, const method_process_t *> table_t; 233 table_t table; 234 235 // For each arrow, add destination node into table 236 SignalDependencyGraph::const_iterator sig_it; 237 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 238 const SignalDependency sd = *sig_it; 239 const equi_t * equi = sd.destination; 240 const method_process_t * method = sd.method; 241 table[equi] = method; 242 } 243 244 // For each arrow, remove source node into table 245 for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) { 246 const SignalDependency sd = *sig_it; 247 const equi_t * e = sd.source; 248 table_t::const_iterator tab_it = table.find(e); 249 if (tab_it != table.end()) { 250 table.erase(e); 251 } 252 } 253 254 typedef multimap<const method_process_t *, const equi_t *> table2_t; 255 typedef pair<const method_process_t *, const equi_t *> table2_pair_t; 256 table2_t table2; 257 258 // Build table2 259 table_t::const_iterator it; 260 for (it = table.begin(); it != table.end(); ++it) { 261 const method_process_t * method = it->second; 262 const equi_t * equi = it->first; 263 table2_pair_t pair = table2_pair_t(method,equi); 264 table2.insert(pair); 265 } 266 267 // Print leef list 268 cerr << "Please split following methods :"; 269 table2_t::const_iterator low_it = table2.begin(); 270 table2_t::const_iterator up_it; 271 while (low_it != table2.end()) { 272 const method_process_t * method = low_it->first; 273 const char * method_name = method->name; 274 const sc_module * module = method->module; 275 const char * module_name = module->name(); 276 cerr << "\n\t - " << module_name << "::" << method_name; 277 cerr << "() to evaluate '"; 278 int count = 0; 279 up_it = table2.upper_bound(low_it->first); 280 table2_t::const_iterator it2; 281 for (it2 = low_it; it2 != up_it; ++it2) { 282 const equi_t * equi = it2->second; 283 const char * signal_name = get_name(*equi); 284 cerr << ((count++) ? ",":"") << signal_name; 285 } 286 cerr << "' signal(s) separetly"; 287 low_it = up_it; 288 } 289 cerr << "\n"; 290 } 291 292 293 static void help2resolve(SignalDependencyGraph & sig) { 294 print_leef_list(sig); 295 MethodProcessDependencyGraph2dot ("methodprocess_graph", sig); 296 cerr << "Please look at 'methodprocess_graph.dot' " 297 "to know how to get ride of circular dependencies.\n"; 298 if (dump_all_graph) { 299 SignalDependencyGraph2dot ("reduced_signal_graph", sig); 300 } 301 } 302 303 304 ProcessDependencyList * MakeProcessDependencyList(const SignalDependencyGraph & _sig_g) { 305 if (dump_stage) { 306 cerr << "Making process dependency list...\n"; 307 } 308 ProcessDependencyList * mod_l = new ProcessDependencyList(); 309 SignalDependencyGraph sig_g = _sig_g; 310 while (!sig_g.empty()) { 311 const method_process_t * process = get_best_process(sig_g); 312 if (process == NULL) 313 { 314 cerr << "Internal Error : Unable to select the best process to schedule.\n"; 315 help2resolve(sig_g); 316 exit (31032005); // 197 317 } 318 mod_l->push_front(process); 319 if (dump_stage) { 320 cerr << "Process found : " << *process << "\n"; 321 } 322 remove_leefs (sig_g, * process); 323 } 324 return mod_l; 399 325 } 400 326 401 327 } // end of sc_core namespace 402 328 329 /* 330 # Local Variables: 331 # tab-width: 4; 332 # c-basic-offset: 4; 333 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 334 # indent-tabs-mode: nil; 335 # End: 336 # 337 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 338 */ 339 340
Note: See TracChangeset
for help on using the changeset viewer.