yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TechmapWorker Struct Reference

Data Structures

struct  TechmapWireData
 

Public Types

typedef std::map< std::string,
std::vector< TechmapWireData > > 
TechmapWires
 

Public Member Functions

 TechmapWorker ()
 
std::string constmap_tpl_name (SigMap &sigmap, RTLIL::Module *tpl, RTLIL::Cell *cell, bool verbose)
 
TechmapWires techmap_find_special_wires (RTLIL::Module *module)
 
void techmap_module_worker (RTLIL::Design *design, RTLIL::Module *module, RTLIL::Cell *cell, RTLIL::Module *tpl)
 
bool techmap_module (RTLIL::Design *design, RTLIL::Module *module, RTLIL::Design *map, std::set< RTLIL::Cell * > &handled_cells, const std::map< RTLIL::IdString, std::set< RTLIL::IdString, RTLIL::sort_by_id_str >> &celltypeMap, bool in_recursion)
 

Data Fields

std::map< RTLIL::IdString,
void(*)(RTLIL::Module
*, RTLIL::Cell *)> 
simplemap_mappers
 
std::map< std::pair
< RTLIL::IdString, std::map
< RTLIL::IdString,
RTLIL::Const >
>, RTLIL::Module * > 
techmap_cache
 
std::map< RTLIL::Module *, bool > techmap_do_cache
 
std::set< RTLIL::Module
*, RTLIL::IdString::compare_ptr_by_name
< RTLIL::Module > > 
module_queue
 
bool extern_mode
 
bool assert_mode
 
bool flatten_mode
 
bool recursive_mode
 
bool autoproc_mode
 

Detailed Description

Definition at line 65 of file techmap.cc.

Member Typedef Documentation

typedef std::map<std::string, std::vector<TechmapWireData> > TechmapWorker::TechmapWires

Definition at line 77 of file techmap.cc.

Constructor & Destructor Documentation

TechmapWorker::TechmapWorker ( )
inline

Definition at line 85 of file techmap.cc.

86  {
87  extern_mode = false;
88  assert_mode = false;
89  flatten_mode = false;
90  recursive_mode = false;
91  autoproc_mode = false;
92  }
bool recursive_mode
Definition: techmap.cc:82
bool flatten_mode
Definition: techmap.cc:81
bool assert_mode
Definition: techmap.cc:80
bool extern_mode
Definition: techmap.cc:79
bool autoproc_mode
Definition: techmap.cc:83

Member Function Documentation

std::string TechmapWorker::constmap_tpl_name ( SigMap sigmap,
RTLIL::Module tpl,
RTLIL::Cell cell,
bool  verbose 
)
inline

Definition at line 94 of file techmap.cc.

95  {
96  std::string constmap_info;
97  std::map<RTLIL::SigBit, std::pair<RTLIL::IdString, int>> connbits_map;
98 
99  for (auto conn : cell->connections())
100  for (int i = 0; i < GetSize(conn.second); i++) {
101  RTLIL::SigBit bit = sigmap(conn.second[i]);
102  if (bit.wire == nullptr) {
103  if (verbose)
104  log(" Constant input on bit %d of port %s: %s\n", i, log_id(conn.first), log_signal(bit));
105  constmap_info += stringf("|%s %d %d", log_id(conn.first), i, bit.data);
106  } else if (connbits_map.count(bit)) {
107  if (verbose)
108  log(" Bit %d of port %s and bit %d of port %s are connected.\n", i, log_id(conn.first),
109  connbits_map.at(bit).second, log_id(connbits_map.at(bit).first));
110  constmap_info += stringf("|%s %d %s %d", log_id(conn.first), i,
111  log_id(connbits_map.at(bit).first), connbits_map.at(bit).second);
112  } else {
113  connbits_map[bit] = std::pair<RTLIL::IdString, int>(conn.first, i);
114  constmap_info += stringf("|%s %d", log_id(conn.first), i);
115  }
116  }
117 
118  return stringf("$paramod$constmap:%s%s", sha1(constmap_info).c_str(), tpl->name.c_str());
119  }
const char * c_str() const
Definition: rtlil.h:178
RTLIL::Wire * wire
Definition: rtlil.h:907
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::State data
Definition: rtlil.h:909
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
Definition: log.cc:269
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
RTLIL::IdString name
Definition: rtlil.h:599
void log(const char *format,...)
Definition: log.cc:180
std::string sha1(const std::string &string)
Definition: sha1.cpp:270
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
Definition: rtlil.cc:1814
const char * log_id(RTLIL::IdString str)
Definition: log.cc:283

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TechmapWires TechmapWorker::techmap_find_special_wires ( RTLIL::Module module)
inline

Definition at line 121 of file techmap.cc.

122  {
123  TechmapWires result;
124 
125  if (module == NULL)
126  return result;
127 
128  for (auto &it : module->wires_) {
129  const char *p = it.first.c_str();
130  if (*p == '$')
131  continue;
132 
133  const char *q = strrchr(p+1, '.');
134  p = q ? q : p+1;
135 
136  if (!strncmp(p, "_TECHMAP_", 9)) {
137  TechmapWireData record;
138  record.wire = it.second;
139  record.value = it.second;
140  result[p].push_back(record);
141  it.second->attributes["\\keep"] = RTLIL::Const(1);
142  it.second->attributes["\\_techmap_special_"] = RTLIL::Const(1);
143  }
144  }
145 
146  if (!result.empty()) {
147  SigMap sigmap(module);
148  for (auto &it1 : result)
149  for (auto &it2 : it1.second)
150  sigmap.apply(it2.value);
151  }
152 
153  return result;
154  }
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
std::map< std::string, std::vector< TechmapWireData > > TechmapWires
Definition: techmap.cc:77
#define NULL

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool TechmapWorker::techmap_module ( RTLIL::Design design,
RTLIL::Module module,
RTLIL::Design map,
std::set< RTLIL::Cell * > &  handled_cells,
const std::map< RTLIL::IdString, std::set< RTLIL::IdString, RTLIL::sort_by_id_str >> &  celltypeMap,
bool  in_recursion 
)
inline

Definition at line 271 of file techmap.cc.

273  {
274  std::string mapmsg_prefix = in_recursion ? "Recursively mapping" : "Mapping";
275 
276  if (!design->selected(module))
277  return false;
278 
279  bool log_continue = false;
280  bool did_something = false;
281 
282  SigMap sigmap(module);
283 
285  std::map<RTLIL::Cell*, std::set<RTLIL::SigBit>> cell_to_inbit;
286  std::map<RTLIL::SigBit, std::set<RTLIL::Cell*>> outbit_to_cell;
287 
288  for (auto cell : module->cells())
289  {
290  if (!design->selected(module, cell) || handled_cells.count(cell) > 0)
291  continue;
292 
293  std::string cell_type = cell->type.str();
294  if (in_recursion && cell_type.substr(0, 2) == "\\$")
295  cell_type = cell_type.substr(1);
296 
297  if (celltypeMap.count(cell_type) == 0) {
298  if (assert_mode && cell_type.back() != '_')
299  log_error("(ASSERT MODE) No matching template cell for type %s found.\n", log_id(cell_type));
300  continue;
301  }
302 
303  for (auto &conn : cell->connections())
304  {
305  RTLIL::SigSpec sig = sigmap(conn.second);
306  sig.remove_const();
307 
308  if (GetSize(sig) == 0)
309  continue;
310 
311  for (auto &tpl_name : celltypeMap.at(cell_type)) {
312  RTLIL::Module *tpl = map->modules_[tpl_name];
313  RTLIL::Wire *port = tpl->wire(conn.first);
314  if (port && port->port_input)
315  cell_to_inbit[cell].insert(sig.begin(), sig.end());
316  if (port && port->port_output)
317  for (auto &bit : sig)
318  outbit_to_cell[bit].insert(cell);
319  }
320  }
321 
322  cells.node(cell);
323  }
324 
325  for (auto &it_right : cell_to_inbit)
326  for (auto &it_sigbit : it_right.second)
327  for (auto &it_left : outbit_to_cell[it_sigbit])
328  cells.edge(it_left, it_right.first);
329 
330  cells.sort();
331 
332  for (auto cell : cells.sorted)
333  {
334  log_assert(handled_cells.count(cell) == 0);
335  log_assert(cell == module->cell(cell->name));
336  bool mapped_cell = false;
337 
338  std::string cell_type = cell->type.str();
339  if (in_recursion && cell_type.substr(0, 2) == "\\$")
340  cell_type = cell_type.substr(1);
341 
342  for (auto &tpl_name : celltypeMap.at(cell_type))
343  {
344  RTLIL::IdString derived_name = tpl_name;
345  RTLIL::Module *tpl = map->modules_[tpl_name];
346  std::map<RTLIL::IdString, RTLIL::Const> parameters = cell->parameters;
347 
348  if (tpl->get_bool_attribute("\\blackbox"))
349  continue;
350 
351  if (!flatten_mode)
352  {
353  std::string extmapper_name;
354 
355  if (tpl->get_bool_attribute("\\techmap_simplemap"))
356  extmapper_name = "simplemap";
357 
358  if (tpl->get_bool_attribute("\\techmap_maccmap"))
359  extmapper_name = "maccmap";
360 
361  if (tpl->attributes.count("\\techmap_wrap"))
362  extmapper_name = "wrap";
363 
364  if (!extmapper_name.empty())
365  {
366  cell->type = cell_type;
367 
368  if ((extern_mode && !in_recursion) || extmapper_name == "wrap")
369  {
370  std::string m_name = stringf("$extern:%s:%s", extmapper_name.c_str(), log_id(cell->type));
371 
372  for (auto &c : cell->parameters)
373  m_name += stringf(":%s=%s", log_id(c.first), log_signal(c.second));
374 
375  if (extmapper_name == "wrap")
376  m_name += ":" + sha1(tpl->attributes.at("\\techmap_wrap").decode_string());
377 
378  RTLIL::Design *extmapper_design = extern_mode && !in_recursion ? design : tpl->design;
379  RTLIL::Module *extmapper_module = extmapper_design->module(m_name);
380 
381  if (extmapper_module == nullptr)
382  {
383  extmapper_module = extmapper_design->addModule(m_name);
384  RTLIL::Cell *extmapper_cell = extmapper_module->addCell(cell->type, cell);
385 
386  int port_counter = 1;
387  for (auto &c : extmapper_cell->connections_) {
388  RTLIL::Wire *w = extmapper_module->addWire(c.first, GetSize(c.second));
389  if (w->name == "\\Y" || w->name == "\\Q")
390  w->port_output = true;
391  else
392  w->port_input = true;
393  w->port_id = port_counter++;
394  c.second = w;
395  }
396 
397  extmapper_module->fixup_ports();
398  extmapper_module->check();
399 
400  if (extmapper_name == "simplemap") {
401  log("Creating %s with simplemap.\n", log_id(extmapper_module));
402  if (simplemap_mappers.count(extmapper_cell->type) == 0)
403  log_error("No simplemap mapper for cell type %s found!\n", log_id(extmapper_cell->type));
404  simplemap_mappers.at(extmapper_cell->type)(extmapper_module, extmapper_cell);
405  extmapper_module->remove(extmapper_cell);
406  }
407 
408  if (extmapper_name == "maccmap") {
409  log("Creating %s with maccmap.\n", log_id(extmapper_module));
410  if (extmapper_cell->type != "$macc")
411  log_error("The maccmap mapper can only map $macc (not %s) cells!\n", log_id(extmapper_cell->type));
412  maccmap(extmapper_module, extmapper_cell);
413  extmapper_module->remove(extmapper_cell);
414  }
415 
416  if (extmapper_name == "wrap") {
417  std::string cmd_string = tpl->attributes.at("\\techmap_wrap").decode_string();
418  log("Running \"%s\" on wrapper %s.\n", cmd_string.c_str(), log_id(extmapper_module));
419  Pass::call_on_module(extmapper_design, extmapper_module, cmd_string);
420  log_continue = true;
421  }
422  }
423 
424  cell->type = extmapper_module->name;
425  cell->parameters.clear();
426 
427  if (!extern_mode || in_recursion) {
428  tpl = extmapper_module;
429  goto use_wrapper_tpl;
430  }
431 
432  log("%s %s.%s (%s) to %s.\n", mapmsg_prefix.c_str(), log_id(module), log_id(cell), log_id(cell->type), log_id(extmapper_module));
433  }
434  else
435  {
436  log("%s %s.%s (%s) with %s.\n", mapmsg_prefix.c_str(), log_id(module), log_id(cell), log_id(cell->type), extmapper_name.c_str());
437 
438  if (extmapper_name == "simplemap") {
439  if (simplemap_mappers.count(cell->type) == 0)
440  log_error("No simplemap mapper for cell type %s found!\n", RTLIL::id2cstr(cell->type));
441  simplemap_mappers.at(cell->type)(module, cell);
442  }
443 
444  if (extmapper_name == "maccmap") {
445  if (cell->type != "$macc")
446  log_error("The maccmap mapper can only map $macc (not %s) cells!\n", log_id(cell->type));
447  maccmap(module, cell);
448  }
449 
450  module->remove(cell);
451  cell = NULL;
452  }
453 
454  did_something = true;
455  mapped_cell = true;
456  break;
457  }
458 
459  for (auto conn : cell->connections()) {
460  if (conn.first.substr(0, 1) == "$")
461  continue;
462  if (tpl->wires_.count(conn.first) > 0 && tpl->wires_.at(conn.first)->port_id > 0)
463  continue;
464  if (!conn.second.is_fully_const() || parameters.count(conn.first) > 0 || tpl->avail_parameters.count(conn.first) == 0)
465  goto next_tpl;
466  parameters[conn.first] = conn.second.as_const();
467  }
468 
469  if (0) {
470  next_tpl:
471  continue;
472  }
473 
474  if (tpl->avail_parameters.count("\\_TECHMAP_CELLTYPE_") != 0)
475  parameters["\\_TECHMAP_CELLTYPE_"] = RTLIL::unescape_id(cell->type);
476 
477  for (auto conn : cell->connections()) {
478  if (tpl->avail_parameters.count(stringf("\\_TECHMAP_CONSTMSK_%s_", RTLIL::id2cstr(conn.first))) != 0) {
479  std::vector<RTLIL::SigBit> v = sigmap(conn.second).to_sigbit_vector();
480  for (auto &bit : v)
481  bit = RTLIL::SigBit(bit.wire == NULL ? RTLIL::State::S1 : RTLIL::State::S0);
482  parameters[stringf("\\_TECHMAP_CONSTMSK_%s_", RTLIL::id2cstr(conn.first))] = RTLIL::SigSpec(v).as_const();
483  }
484  if (tpl->avail_parameters.count(stringf("\\_TECHMAP_CONSTVAL_%s_", RTLIL::id2cstr(conn.first))) != 0) {
485  std::vector<RTLIL::SigBit> v = sigmap(conn.second).to_sigbit_vector();
486  for (auto &bit : v)
487  if (bit.wire != NULL)
489  parameters[stringf("\\_TECHMAP_CONSTVAL_%s_", RTLIL::id2cstr(conn.first))] = RTLIL::SigSpec(v).as_const();
490  }
491  }
492 
493  int unique_bit_id_counter = 0;
494  std::map<RTLIL::SigBit, int> unique_bit_id;
495  unique_bit_id[RTLIL::State::S0] = unique_bit_id_counter++;
496  unique_bit_id[RTLIL::State::S1] = unique_bit_id_counter++;
497  unique_bit_id[RTLIL::State::Sx] = unique_bit_id_counter++;
498  unique_bit_id[RTLIL::State::Sz] = unique_bit_id_counter++;
499 
500  for (auto conn : cell->connections())
501  if (tpl->avail_parameters.count(stringf("\\_TECHMAP_CONNMAP_%s_", RTLIL::id2cstr(conn.first))) != 0) {
502  for (auto &bit : sigmap(conn.second).to_sigbit_vector())
503  if (unique_bit_id.count(bit) == 0)
504  unique_bit_id[bit] = unique_bit_id_counter++;
505  }
506 
507  int bits = 0;
508  for (int i = 0; i < 32; i++)
509  if (((unique_bit_id_counter-1) & (1 << i)) != 0)
510  bits = i;
511  if (tpl->avail_parameters.count("\\_TECHMAP_BITS_CONNMAP_"))
512  parameters["\\_TECHMAP_BITS_CONNMAP_"] = bits;
513 
514  for (auto conn : cell->connections())
515  if (tpl->avail_parameters.count(stringf("\\_TECHMAP_CONNMAP_%s_", RTLIL::id2cstr(conn.first))) != 0) {
516  RTLIL::Const value;
517  for (auto &bit : sigmap(conn.second).to_sigbit_vector()) {
518  RTLIL::Const chunk(unique_bit_id.at(bit), bits);
519  value.bits.insert(value.bits.end(), chunk.bits.begin(), chunk.bits.end());
520  }
521  parameters[stringf("\\_TECHMAP_CONNMAP_%s_", RTLIL::id2cstr(conn.first))] = value;
522  }
523  }
524 
525  if (0) {
526  use_wrapper_tpl:;
527  // do not register techmap_wrap modules with techmap_cache
528  } else {
529  std::pair<RTLIL::IdString, std::map<RTLIL::IdString, RTLIL::Const>> key(tpl_name, parameters);
530  if (techmap_cache.count(key) > 0) {
531  tpl = techmap_cache[key];
532  } else {
533  if (cell->parameters.size() != 0) {
534  derived_name = tpl->derive(map, parameters);
535  tpl = map->module(derived_name);
536  log_continue = true;
537  }
538  techmap_cache[key] = tpl;
539  }
540  }
541 
542  if (flatten_mode) {
543  techmap_do_cache[tpl] = true;
544  } else {
545  RTLIL::Module *constmapped_tpl = map->module(constmap_tpl_name(sigmap, tpl, cell, false));
546  if (constmapped_tpl != nullptr)
547  tpl = constmapped_tpl;
548  }
549 
550  if (techmap_do_cache.count(tpl) == 0)
551  {
552  bool keep_running = true;
553  techmap_do_cache[tpl] = true;
554 
555  std::set<std::string> techmap_wire_names;
556 
557  while (keep_running)
558  {
560  keep_running = false;
561 
562  for (auto &it : twd)
563  techmap_wire_names.insert(it.first);
564 
565  for (auto &it : twd["_TECHMAP_FAIL_"]) {
566  RTLIL::SigSpec value = it.value;
567  if (value.is_fully_const() && value.as_bool()) {
568  log("Not using module `%s' from techmap as it contains a %s marker wire with non-zero value %s.\n",
569  derived_name.c_str(), RTLIL::id2cstr(it.wire->name), log_signal(value));
570  techmap_do_cache[tpl] = false;
571  }
572  }
573 
574  if (!techmap_do_cache[tpl])
575  break;
576 
577  for (auto &it : twd)
578  {
579  if (it.first.substr(0, 12) != "_TECHMAP_DO_" || it.second.empty())
580  continue;
581 
582  auto &data = it.second.front();
583 
584  if (!data.value.is_fully_const())
585  log_error("Techmap yielded config wire %s with non-const value %s.\n", RTLIL::id2cstr(data.wire->name), log_signal(data.value));
586 
587  techmap_wire_names.erase(it.first);
588 
589  const char *p = data.wire->name.c_str();
590  const char *q = strrchr(p+1, '.');
591  q = q ? q : p+1;
592 
593  std::string cmd_string = data.value.as_const().decode_string();
594 
595  restart_eval_cmd_string:
596  if (cmd_string.rfind("CONSTMAP; ", 0) == 0)
597  {
598  cmd_string = cmd_string.substr(strlen("CONSTMAP; "));
599 
600  log("Analyzing pattern of constant bits for this cell:\n");
601  RTLIL::IdString new_tpl_name = constmap_tpl_name(sigmap, tpl, cell, true);
602  log("Creating constmapped module `%s'.\n", log_id(new_tpl_name));
603  log_assert(map->module(new_tpl_name) == nullptr);
604 
605  RTLIL::Module *new_tpl = map->addModule(new_tpl_name);
606  tpl->cloneInto(new_tpl);
607 
608  techmap_do_cache.erase(tpl);
609  techmap_do_cache[new_tpl] = true;
610  tpl = new_tpl;
611 
612  std::map<RTLIL::SigBit, RTLIL::SigBit> port_new2old_map;
613  std::map<RTLIL::SigBit, RTLIL::SigBit> port_connmap;
614  std::map<RTLIL::SigBit, RTLIL::SigBit> cellbits_to_tplbits;
615 
616  for (auto wire : tpl->wires().to_vector())
617  {
618  if (!wire->port_input || wire->port_output)
619  continue;
620 
621  RTLIL::IdString port_name = wire->name;
622  tpl->rename(wire, NEW_ID);
623 
624  RTLIL::Wire *new_wire = tpl->addWire(port_name, wire);
625  wire->port_input = false;
626  wire->port_id = 0;
627 
628  for (int i = 0; i < wire->width; i++) {
629  port_new2old_map[RTLIL::SigBit(new_wire, i)] = RTLIL::SigBit(wire, i);
630  port_connmap[RTLIL::SigBit(wire, i)] = RTLIL::SigBit(new_wire, i);
631  }
632  }
633 
634  for (auto conn : cell->connections())
635  for (int i = 0; i < GetSize(conn.second); i++)
636  {
637  RTLIL::SigBit bit = sigmap(conn.second[i]);
638  RTLIL::SigBit tplbit(tpl->wire(conn.first), i);
639 
640  if (bit.wire == nullptr)
641  {
642  RTLIL::SigBit oldbit = port_new2old_map.at(tplbit);
643  port_connmap.at(oldbit) = bit;
644  }
645  else if (cellbits_to_tplbits.count(bit))
646  {
647  RTLIL::SigBit oldbit = port_new2old_map.at(tplbit);
648  port_connmap.at(oldbit) = cellbits_to_tplbits[bit];
649  }
650  else
651  cellbits_to_tplbits[bit] = tplbit;
652  }
653 
654  RTLIL::SigSig port_conn;
655  for (auto &it : port_connmap) {
656  port_conn.first.append_bit(it.first);
657  port_conn.second.append_bit(it.second);
658  }
659  tpl->connect(port_conn);
660 
661  tpl->check();
662  goto restart_eval_cmd_string;
663  }
664 
665  if (cmd_string.rfind("RECURSION; ", 0) == 0)
666  {
667  cmd_string = cmd_string.substr(strlen("RECURSION; "));
668  while (techmap_module(map, tpl, map, handled_cells, celltypeMap, true)) { }
669  goto restart_eval_cmd_string;
670  }
671 
672  Pass::call_on_module(map, tpl, cmd_string);
673 
674  log_assert(!strncmp(q, "_TECHMAP_DO_", 12));
675  std::string new_name = data.wire->name.substr(0, q-p) + "_TECHMAP_DONE_" + data.wire->name.substr(q-p+12);
676  while (tpl->wires_.count(new_name))
677  new_name += "_";
678  tpl->rename(data.wire->name, new_name);
679 
680  keep_running = true;
681  break;
682  }
683  }
684 
686  for (auto &it : twd) {
687  if (it.first != "_TECHMAP_FAIL_" && it.first.substr(0, 12) != "_TECHMAP_DO_" && it.first.substr(0, 14) != "_TECHMAP_DONE_")
688  log_error("Techmap yielded unknown config wire %s.\n", it.first.c_str());
689  if (techmap_do_cache[tpl])
690  for (auto &it2 : it.second)
691  if (!it2.value.is_fully_const())
692  log_error("Techmap yielded config wire %s with non-const value %s.\n", RTLIL::id2cstr(it2.wire->name), log_signal(it2.value));
693  techmap_wire_names.erase(it.first);
694  }
695 
696  for (auto &it : techmap_wire_names)
697  log_error("Techmap special wire %s disappeared. This is considered a fatal error.\n", RTLIL::id2cstr(it));
698 
699  if (recursive_mode) {
700  if (log_continue) {
701  log_header("Continuing TECHMAP pass.\n");
702  log_continue = false;
703  }
704  while (techmap_module(map, tpl, map, handled_cells, celltypeMap, true)) { }
705  }
706  }
707 
708  if (techmap_do_cache.at(tpl) == false)
709  continue;
710 
711  if (log_continue) {
712  log_header("Continuing TECHMAP pass.\n");
713  log_continue = false;
714  }
715 
716  if (extern_mode && !in_recursion)
717  {
718  std::string m_name = stringf("$extern:%s", log_id(tpl));
719 
720  if (!design->module(m_name))
721  {
722  RTLIL::Module *m = design->addModule(m_name);
723  tpl->cloneInto(m);
724 
725  for (auto cell : m->cells()) {
726  if (cell->type.substr(0, 2) == "\\$")
727  cell->type = cell->type.substr(1);
728  }
729 
730  module_queue.insert(m);
731  }
732 
733  log("%s %s.%s to imported %s.\n", mapmsg_prefix.c_str(), log_id(module), log_id(cell), log_id(m_name));
734  cell->type = m_name;
735  cell->parameters.clear();
736  }
737  else
738  {
739  log("%s %s.%s using %s.\n", mapmsg_prefix.c_str(), log_id(module), log_id(cell), log_id(tpl));
740  techmap_module_worker(design, module, cell, tpl);
741  cell = NULL;
742  }
743  did_something = true;
744  mapped_cell = true;
745  break;
746  }
747 
748  if (assert_mode && !mapped_cell)
749  log_error("(ASSERT MODE) Failed to map cell %s.%s (%s).\n", log_id(module), log_id(cell), log_id(cell->type));
750 
751  handled_cells.insert(cell);
752  }
753 
754  if (log_continue) {
755  log_header("Continuing TECHMAP pass.\n");
756  log_continue = false;
757  }
758 
759  return did_something;
760  }
const char * c_str() const
Definition: rtlil.h:178
bool selected(T1 *module) const
Definition: rtlil.h:551
RTLIL::Wire * wire
Definition: rtlil.h:907
void cloneInto(RTLIL::Module *new_mod) const
Definition: rtlil.cc:1022
bool recursive_mode
Definition: techmap.cc:82
RTLIL::Wire * wire(RTLIL::IdString id)
Definition: rtlil.h:637
std::set< RTLIL::Module *, RTLIL::IdString::compare_ptr_by_name< RTLIL::Module > > module_queue
Definition: techmap.cc:70
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
bool sort()
Definition: utils.h:194
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void node(T n)
Definition: utils.h:145
void log_header(const char *format,...)
Definition: log.cc:188
void clear()
Definition: rtlil.h:223
RTLIL::Const as_const() const
Definition: rtlil.cc:2857
std::map< RTLIL::Module *, bool > techmap_do_cache
Definition: techmap.cc:69
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
bool as_bool() const
Definition: rtlil.cc:2818
static std::string unescape_id(std::string str)
Definition: rtlil.h:257
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
Definition: log.cc:269
std::map< std::pair< RTLIL::IdString, std::map< RTLIL::IdString, RTLIL::Const > >, RTLIL::Module * > techmap_cache
Definition: techmap.cc:68
bool port_input
Definition: rtlil.h:827
std::map< RTLIL::IdString, void(*)(RTLIL::Module *, RTLIL::Cell *)> simplemap_mappers
Definition: techmap.cc:67
void log_error(const char *format,...)
Definition: log.cc:204
RTLIL::Module * module
Definition: abc.cc:94
std::set< RTLIL::IdString > avail_parameters
Definition: rtlil.h:600
int port_id
Definition: rtlil.h:826
RTLIL::IdString type
Definition: rtlil.h:854
virtual void check()
Definition: rtlil.cc:948
virtual RTLIL::IdString derive(RTLIL::Design *design, std::map< RTLIL::IdString, RTLIL::Const > parameters)
Definition: rtlil.cc:467
bool port_output
Definition: rtlil.h:827
bool flatten_mode
Definition: techmap.cc:81
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool did_something
Definition: opt_const.cc:32
std::map< std::string, std::vector< TechmapWireData > > TechmapWires
Definition: techmap.cc:77
bool techmap_module(RTLIL::Design *design, RTLIL::Module *module, RTLIL::Design *map, std::set< RTLIL::Cell * > &handled_cells, const std::map< RTLIL::IdString, std::set< RTLIL::IdString, RTLIL::sort_by_id_str >> &celltypeMap, bool in_recursion)
Definition: techmap.cc:271
void edge(T left, T right)
Definition: utils.h:151
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
RTLIL::SigSpecIterator begin()
Definition: rtlil.h:1024
void fixup_ports()
Definition: rtlil.cc:1312
#define log_assert(_assert_expr_)
Definition: log.h:85
bool is_fully_const() const
Definition: rtlil.cc:2763
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
RTLIL::IdString name
Definition: rtlil.h:599
#define NEW_ID
Definition: yosys.h:166
bool assert_mode
Definition: techmap.cc:80
RTLIL::IdString name
Definition: rtlil.h:825
static const char * id2cstr(const RTLIL::IdString &str)
Definition: rtlil.h:267
void remove_const()
Definition: rtlil.cc:2464
RTLIL::Module * addModule(RTLIL::IdString name)
Definition: rtlil.cc:270
RTLIL::Module * module(RTLIL::IdString name)
Definition: rtlil.cc:254
RTLIL::ObjRange< RTLIL::Cell * > cells()
Definition: rtlil.h:641
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
RTLIL::Cell * cell(RTLIL::IdString id)
Definition: rtlil.h:638
#define NULL
static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::string command)
Definition: register.cc:240
void remove(const std::set< RTLIL::Wire * > &wires)
Definition: rtlil.cc:1158
void log(const char *format,...)
Definition: log.cc:180
std::vector< T > sorted
Definition: utils.h:137
std::string sha1(const std::string &string)
Definition: sha1.cpp:270
bool extern_mode
Definition: techmap.cc:79
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
void maccmap(RTLIL::Module *module, RTLIL::Cell *cell, bool unmap=false)
Definition: maccmap.cc:265
std::map< RTLIL::IdString, RTLIL::SigSpec > connections_
Definition: rtlil.h:855
RTLIL::Design * design
Definition: rtlil.h:589
std::string constmap_tpl_name(SigMap &sigmap, RTLIL::Module *tpl, RTLIL::Cell *cell, bool verbose)
Definition: techmap.cc:94
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71
void techmap_module_worker(RTLIL::Design *design, RTLIL::Module *module, RTLIL::Cell *cell, RTLIL::Module *tpl)
Definition: techmap.cc:156
const char * log_id(RTLIL::IdString str)
Definition: log.cc:283
RTLIL::SigSpecIterator end()
Definition: rtlil.h:1025
TechmapWires techmap_find_special_wires(RTLIL::Module *module)
Definition: techmap.cc:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TechmapWorker::techmap_module_worker ( RTLIL::Design design,
RTLIL::Module module,
RTLIL::Cell cell,
RTLIL::Module tpl 
)
inline

Definition at line 156 of file techmap.cc.

157  {
158  if (tpl->memories.size() != 0)
159  log_error("Technology map yielded memories -> this is not supported.\n");
160 
161  if (tpl->processes.size() != 0) {
162  log("Technology map yielded processes:\n");
163  for (auto &it : tpl->processes)
164  log(" %s",RTLIL::id2cstr(it.first));
165  if (autoproc_mode) {
166  Pass::call_on_module(tpl->design, tpl, "proc");
167  log_assert(GetSize(tpl->processes) == 0);
168  } else
169  log_error("Technology map yielded processes -> this is not supported (use -autoproc to run 'proc' automatically).\n");
170  }
171 
172  std::string orig_cell_name;
173  if (!flatten_mode)
174  for (auto &it : tpl->cells_)
175  if (it.first == "\\_TECHMAP_REPLACE_") {
176  orig_cell_name = cell->name.str();
177  module->rename(cell, stringf("$techmap%d", autoidx++) + cell->name.str());
178  break;
179  }
180 
181  std::map<RTLIL::IdString, RTLIL::IdString> positional_ports;
182 
183  for (auto &it : tpl->wires_) {
184  if (it.second->port_id > 0)
185  positional_ports[stringf("$%d", it.second->port_id)] = it.first;
186  std::string w_name = it.second->name.str();
187  apply_prefix(cell->name.str(), w_name);
188  RTLIL::Wire *w = module->addWire(w_name, it.second);
189  w->port_input = false;
190  w->port_output = false;
191  w->port_id = 0;
192  if (it.second->get_bool_attribute("\\_techmap_special_"))
193  w->attributes.clear();
194  design->select(module, w);
195  }
196 
197  SigMap port_signal_map;
198 
199  for (auto &it : cell->connections()) {
200  RTLIL::IdString portname = it.first;
201  if (positional_ports.count(portname) > 0)
202  portname = positional_ports.at(portname);
203  if (tpl->wires_.count(portname) == 0 || tpl->wires_.at(portname)->port_id == 0) {
204  if (portname.substr(0, 1) == "$")
205  log_error("Can't map port `%s' of cell `%s' to template `%s'!\n", portname.c_str(), cell->name.c_str(), tpl->name.c_str());
206  continue;
207  }
208  RTLIL::Wire *w = tpl->wires_.at(portname);
209  RTLIL::SigSig c;
210  if (w->port_output) {
211  c.first = it.second;
212  c.second = RTLIL::SigSpec(w);
213  apply_prefix(cell->name.str(), c.second, module);
214  } else {
215  c.first = RTLIL::SigSpec(w);
216  c.second = it.second;
217  apply_prefix(cell->name.str(), c.first, module);
218  }
219  if (c.second.size() > c.first.size())
220  c.second.remove(c.first.size(), c.second.size() - c.first.size());
221  if (c.second.size() < c.first.size())
222  c.second.append(RTLIL::SigSpec(RTLIL::State::S0, c.first.size() - c.second.size()));
223  log_assert(c.first.size() == c.second.size());
224  if (flatten_mode) {
225  // more conservative approach:
226  // connect internal and external wires
227  module->connect(c);
228  } else {
229  // approach that yields nicer outputs:
230  // replace internal wires that are connected to external wires
231  if (w->port_output)
232  port_signal_map.add(c.second, c.first);
233  else
234  port_signal_map.add(c.first, c.second);
235  }
236  }
237 
238  for (auto &it : tpl->cells_)
239  {
240  std::string c_name = it.second->name.str();
241 
242  if (!flatten_mode && c_name == "\\_TECHMAP_REPLACE_")
243  c_name = orig_cell_name;
244  else
245  apply_prefix(cell->name.str(), c_name);
246 
247  RTLIL::Cell *c = module->addCell(c_name, it.second);
248  design->select(module, c);
249 
250  if (!flatten_mode && c->type.substr(0, 2) == "\\$")
251  c->type = c->type.substr(1);
252 
253  for (auto &it2 : c->connections_) {
254  apply_prefix(cell->name.str(), it2.second, module);
255  port_signal_map.apply(it2.second);
256  }
257  }
258 
259  for (auto &it : tpl->connections()) {
260  RTLIL::SigSig c = it;
261  apply_prefix(cell->name.str(), c.first, module);
262  apply_prefix(cell->name.str(), c.second, module);
263  port_signal_map.apply(c.first);
264  port_signal_map.apply(c.second);
265  module->connect(c);
266  }
267 
268  module->remove(cell);
269  }
const char * c_str() const
Definition: rtlil.h:178
std::string str() const
Definition: rtlil.h:182
YOSYS_NAMESPACE_END USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN void apply_prefix(std::string prefix, std::string &id)
Definition: techmap.cc:44
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
const std::vector< RTLIL::SigSig > & connections() const
Definition: rtlil.cc:1307
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
RTLIL::IdString name
Definition: rtlil.h:853
bool port_input
Definition: rtlil.h:827
std::map< RTLIL::IdString, RTLIL::Memory * > memories
Definition: rtlil.h:601
void log_error(const char *format,...)
Definition: log.cc:204
RTLIL::Module * module
Definition: abc.cc:94
void select(T1 *module, T2 *member)
Definition: rtlil.h:559
void apply(RTLIL::SigBit &bit) const
Definition: sigtools.h:383
bool port_output
Definition: rtlil.h:827
bool flatten_mode
Definition: techmap.cc:81
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
#define log_assert(_assert_expr_)
Definition: log.h:85
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
RTLIL::IdString name
Definition: rtlil.h:599
static const char * id2cstr(const RTLIL::IdString &str)
Definition: rtlil.h:267
std::map< RTLIL::IdString, RTLIL::Process * > processes
Definition: rtlil.h:602
std::string substr(size_t pos=0, size_t len=std::string::npos) const
Definition: rtlil.h:208
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596
static void call_on_module(RTLIL::Design *design, RTLIL::Module *module, std::string command)
Definition: register.cc:240
void remove(const std::set< RTLIL::Wire * > &wires)
Definition: rtlil.cc:1158
void log(const char *format,...)
Definition: log.cc:180
void add(RTLIL::SigSpec from, RTLIL::SigSpec to)
Definition: sigtools.h:347
RTLIL::Design * design
Definition: rtlil.h:589
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
Definition: rtlil.cc:1814
YOSYS_NAMESPACE_BEGIN int autoidx
Definition: yosys.cc:51
void rename(RTLIL::Wire *wire, RTLIL::IdString new_name)
Definition: rtlil.cc:1185
bool autoproc_mode
Definition: techmap.cc:83

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

bool TechmapWorker::assert_mode

Definition at line 80 of file techmap.cc.

bool TechmapWorker::autoproc_mode

Definition at line 83 of file techmap.cc.

bool TechmapWorker::extern_mode

Definition at line 79 of file techmap.cc.

bool TechmapWorker::flatten_mode

Definition at line 81 of file techmap.cc.

std::set<RTLIL::Module*, RTLIL::IdString::compare_ptr_by_name<RTLIL::Module> > TechmapWorker::module_queue

Definition at line 70 of file techmap.cc.

bool TechmapWorker::recursive_mode

Definition at line 82 of file techmap.cc.

std::map<RTLIL::IdString, void(*)(RTLIL::Module*, RTLIL::Cell*)> TechmapWorker::simplemap_mappers

Definition at line 67 of file techmap.cc.

std::map<std::pair<RTLIL::IdString, std::map<RTLIL::IdString, RTLIL::Const> >, RTLIL::Module*> TechmapWorker::techmap_cache

Definition at line 68 of file techmap.cc.

std::map<RTLIL::Module*, bool> TechmapWorker::techmap_do_cache

Definition at line 69 of file techmap.cc.


The documentation for this struct was generated from the following file: