@@ -605,25 +605,15 @@ struct XAigerWriter
605
605
RTLIL::Module *holes_module = module ->design ->addModule (" $__holes__" );
606
606
log_assert (holes_module);
607
607
608
- dict<IdString, Cell*> cell_cache;
609
-
610
608
int port_id = 1 ;
611
609
int box_count = 0 ;
612
610
for (auto cell : box_list) {
613
611
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
-
620
612
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" )) {
624
615
holes_cell = holes_module->addCell (cell->name , cell->type );
625
616
holes_cell->parameters = cell->parameters ;
626
- r.first ->second = holes_cell;
627
617
}
628
618
629
619
// NB: Assume box_module->ports are sorted alphabetically
@@ -632,8 +622,8 @@ struct XAigerWriter
632
622
RTLIL::Wire *w = box_module->wire (port_name);
633
623
log_assert (w);
634
624
RTLIL::Wire *holes_wire;
635
- RTLIL::SigSpec port_sig ;
636
- if (w->port_input )
625
+ RTLIL::SigSpec port_wire ;
626
+ if (w->port_input ) {
637
627
for (int i = 0 ; i < GetSize (w); i++) {
638
628
box_inputs++;
639
629
holes_wire = holes_module->wire (stringf (" \\ i%d" , box_inputs));
@@ -644,29 +634,28 @@ struct XAigerWriter
644
634
holes_module->ports .push_back (holes_wire->name );
645
635
}
646
636
if (holes_cell)
647
- port_sig .append (holes_wire);
637
+ port_wire .append (holes_wire);
648
638
}
639
+ if (!port_wire.empty ())
640
+ holes_cell->setPort (w->name , port_wire);
641
+ }
649
642
if (w->port_output ) {
650
643
box_outputs += GetSize (w);
651
644
for (int i = 0 ; i < GetSize (w); i++) {
652
645
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 ( )));
654
647
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));
656
649
holes_wire->port_output = true ;
657
650
holes_wire->port_id = port_id++;
658
651
holes_module->ports .push_back (holes_wire->name );
659
652
if (holes_cell)
660
- port_sig .append (holes_wire);
653
+ port_wire .append (holes_wire);
661
654
else
662
655
holes_module->connect (holes_wire, State::S0);
663
656
}
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);
670
659
}
671
660
}
672
661
@@ -696,11 +685,14 @@ struct XAigerWriter
696
685
RTLIL::Selection& sel = holes_module->design ->selection_stack .back ();
697
686
sel.select (holes_module);
698
687
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
+
699
692
Pass::call (holes_module->design , " flatten -wb" );
700
693
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
704
696
Pass::call (holes_module->design , " techmap" );
705
697
Pass::call (holes_module->design , " aigmap" );
706
698
for (auto cell : holes_module->cells ())
0 commit comments