Skip to content

Commit df31ade

Browse files
authored
Revert "write_xaiger: only instantiate each whitebox cell type once"
1 parent 3e14ff1 commit df31ade

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

backends/aiger/xaiger.cc

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -605,25 +605,15 @@ struct XAigerWriter
605605
RTLIL::Module *holes_module = module->design->addModule("$__holes__");
606606
log_assert(holes_module);
607607

608-
dict<IdString, Cell*> cell_cache;
609-
610608
int port_id = 1;
611609
int box_count = 0;
612610
for (auto cell : box_list) {
613611
RTLIL::Module* box_module = module->design->module(cell->type);
614-
log_assert(box_module);
615-
IdString derived_name = box_module->derive(module->design, cell->parameters);
616-
box_module = module->design->module(derived_name);
617-
if (box_module->has_processes())
618-
log_error("ABC9 box '%s' contains processes!\n", box_module->name.c_str());
619-
620612
int box_inputs = 0, box_outputs = 0;
621-
auto r = cell_cache.insert(std::make_pair(derived_name, nullptr));
622-
Cell *holes_cell = r.first->second;
623-
if (r.second && !holes_cell && box_module->get_bool_attribute("\\whitebox")) {
613+
Cell *holes_cell = nullptr;
614+
if (box_module->get_bool_attribute("\\whitebox")) {
624615
holes_cell = holes_module->addCell(cell->name, cell->type);
625616
holes_cell->parameters = cell->parameters;
626-
r.first->second = holes_cell;
627617
}
628618

629619
// NB: Assume box_module->ports are sorted alphabetically
@@ -632,8 +622,8 @@ struct XAigerWriter
632622
RTLIL::Wire *w = box_module->wire(port_name);
633623
log_assert(w);
634624
RTLIL::Wire *holes_wire;
635-
RTLIL::SigSpec port_sig;
636-
if (w->port_input)
625+
RTLIL::SigSpec port_wire;
626+
if (w->port_input) {
637627
for (int i = 0; i < GetSize(w); i++) {
638628
box_inputs++;
639629
holes_wire = holes_module->wire(stringf("\\i%d", box_inputs));
@@ -644,29 +634,28 @@ struct XAigerWriter
644634
holes_module->ports.push_back(holes_wire->name);
645635
}
646636
if (holes_cell)
647-
port_sig.append(holes_wire);
637+
port_wire.append(holes_wire);
648638
}
639+
if (!port_wire.empty())
640+
holes_cell->setPort(w->name, port_wire);
641+
}
649642
if (w->port_output) {
650643
box_outputs += GetSize(w);
651644
for (int i = 0; i < GetSize(w); i++) {
652645
if (GetSize(w) == 1)
653-
holes_wire = holes_module->addWire(stringf("%s.%s", cell->name.c_str(), log_id(w->name)));
646+
holes_wire = holes_module->addWire(stringf("%s.%s", cell->name.c_str(), w->name.c_str()));
654647
else
655-
holes_wire = holes_module->addWire(stringf("%s.%s[%d]", cell->name.c_str(), log_id(w->name), i));
648+
holes_wire = holes_module->addWire(stringf("%s.%s[%d]", cell->name.c_str(), w->name.c_str(), i));
656649
holes_wire->port_output = true;
657650
holes_wire->port_id = port_id++;
658651
holes_module->ports.push_back(holes_wire->name);
659652
if (holes_cell)
660-
port_sig.append(holes_wire);
653+
port_wire.append(holes_wire);
661654
else
662655
holes_module->connect(holes_wire, State::S0);
663656
}
664-
}
665-
if (!port_sig.empty()) {
666-
if (r.second)
667-
holes_cell->setPort(w->name, port_sig);
668-
else
669-
holes_module->connect(holes_cell->getPort(w->name), port_sig);
657+
if (!port_wire.empty())
658+
holes_cell->setPort(w->name, port_wire);
670659
}
671660
}
672661

@@ -696,11 +685,14 @@ struct XAigerWriter
696685
RTLIL::Selection& sel = holes_module->design->selection_stack.back();
697686
sel.select(holes_module);
698687

688+
// TODO: Should not need to opt_merge if we only instantiate
689+
// each box type once...
690+
Pass::call(holes_module->design, "opt_merge -share_all");
691+
699692
Pass::call(holes_module->design, "flatten -wb");
700693

701-
// Cannot techmap/aigmap/check all lib_whitebox-es outside of write_xaiger
702-
// since boxes may contain parameters in which case `flatten` would have
703-
// created a new $paramod ...
694+
// TODO: Should techmap/aigmap/check all lib_whitebox-es just once,
695+
// instead of per write_xaiger call
704696
Pass::call(holes_module->design, "techmap");
705697
Pass::call(holes_module->design, "aigmap");
706698
for (auto cell : holes_module->cells())

0 commit comments

Comments
 (0)