@@ -519,7 +519,7 @@ std::vector<dbInst*> dbModule::getLeafInsts()
519519dbModBTerm* dbModule::findModBTerm (const char * name)
520520{
521521 std::string modbterm_name (name);
522- char hier_delimiter = getOwner ()->getHierarchyDelimiter ();
522+ const char hier_delimiter = getOwner ()->getHierarchyDelimiter ();
523523 size_t last_idx = modbterm_name.find_last_of (hier_delimiter);
524524 if (last_idx != std::string::npos) {
525525 modbterm_name = modbterm_name.substr (last_idx + 1 );
@@ -790,6 +790,7 @@ void _dbModule::copyModuleInsts(dbModule* old_module,
790790 ITMap& it_map)
791791{
792792 dbBlock* block = new_module->getOwner ();
793+ const char hier_delimiter = block->getHierarchyDelimiter ();
793794 utl::Logger* logger = old_module->getImpl ()->getLogger ();
794795
795796 // Create a net name map (key: new net name, value: new dbNet*).
@@ -803,7 +804,7 @@ void _dbModule::copyModuleInsts(dbModule* old_module,
803804 std::string new_inst_name;
804805 if (new_mod_inst) {
805806 new_inst_name = new_mod_inst->getHierarchicalName ();
806- new_inst_name += block-> getHierarchyDelimiter () ;
807+ new_inst_name += hier_delimiter ;
807808 }
808809
809810 new_inst_name += block->getBaseName (old_inst->getConstName ());
@@ -851,45 +852,74 @@ void _dbModule::copyModuleInsts(dbModule* old_module,
851852 old_iterm->getName (),
852853 new_iterm->getName ());
853854 dbNet* old_net = old_iterm->getNet ();
854- if (old_net) {
855- // Create a local net only if it connects to iterms inside this module
856- std::string new_net_name;
857- if (new_mod_inst) {
858- new_net_name = new_mod_inst->getHierarchicalName ();
859- new_net_name += block->getHierarchyDelimiter ();
860- }
861- std::string old_net_name = old_net->getName ();
862- new_net_name += block->getBaseName (old_net_name.c_str ());
863-
864- auto it = new_net_name_map.find (new_net_name);
865- if (it != new_net_name_map.end ()) {
866- // Connect to an existing local net
867- dbNet* new_net = (*it).second ;
868- new_iterm->connect (new_net);
869- debugPrint (logger,
870- utl::ODB,
871- " replace_design" ,
872- 1 ,
873- " connected iterm '{}' to existing local net '{}'" ,
874- new_iterm->getName (),
875- new_net->getName ());
876- } else {
877- // Create and connect to a new local net
878- assert (block->findNet (new_net_name.c_str ()) == nullptr );
879- dbNet* new_net
880- = dbNet::create (new_module->getOwner (), new_net_name.c_str ());
881- new_iterm->connect (new_net);
882- debugPrint (logger,
883- utl::ODB,
884- " replace_design" ,
885- 1 ,
886- " Connected iterm '{}' to new local net '{}'" ,
887- new_iterm->getName (),
888- new_net->getName ());
855+ if (old_net == nullptr ) {
856+ continue ;
857+ }
889858
890- // Insert it to the map
891- new_net_name_map[new_net_name] = new_net;
892- }
859+ //
860+ // Create a local net only if it connects to iterms inside this module
861+ //
862+ std::string new_net_name;
863+ if (new_mod_inst) {
864+ new_net_name = new_mod_inst->getHierarchicalName ();
865+ new_net_name += hier_delimiter;
866+ }
867+
868+ // Check if the flat net is an internal net within old_module
869+ // - If old_module is uninstantiated module, every net in the module is
870+ // an internal net.
871+ // e.g., No module instance.
872+ // net_name = "_001_" <-- Internal net.
873+ //
874+ // - Otherwise, an internal net should have the hierarchy prefix
875+ // (= module instance hierarchical name).
876+ // e.g., modinst_name = "u0/alu0"
877+ // net_name = u0/alu0/_001_ <-- Internal net.
878+ // net_name = u0/_001_ <-- External net crossing module
879+ // boundary.
880+ std::string old_net_name = old_net->getName ();
881+ if (old_net->isInternalTo (old_module) == false ) {
882+ // Skip external net crossing module boundary.
883+ // It will be connected later.
884+ debugPrint (logger,
885+ utl::ODB,
886+ " replace_design" ,
887+ 3 ,
888+ " Skip: non-internal dbNet '{}' of old_module '{}'.\n " ,
889+ old_net_name,
890+ old_module->getHierarchicalName ());
891+ continue ;
892+ }
893+
894+ new_net_name += block->getBaseName (old_net_name.c_str ());
895+ auto it = new_net_name_map.find (new_net_name);
896+ if (it != new_net_name_map.end ()) {
897+ // Connect to an existing local net
898+ dbNet* new_net = (*it).second ;
899+ new_iterm->connect (new_net);
900+ debugPrint (logger,
901+ utl::ODB,
902+ " replace_design" ,
903+ 1 ,
904+ " connected iterm '{}' to existing local net '{}'" ,
905+ new_iterm->getName (),
906+ new_net->getName ());
907+ } else {
908+ // Create and connect to a new local net
909+ assert (block->findNet (new_net_name.c_str ()) == nullptr );
910+ dbNet* new_net
911+ = dbNet::create (new_module->getOwner (), new_net_name.c_str ());
912+ new_iterm->connect (new_net);
913+ debugPrint (logger,
914+ utl::ODB,
915+ " replace_design" ,
916+ 1 ,
917+ " Connected iterm '{}' to new local net '{}'" ,
918+ new_iterm->getName (),
919+ new_net->getName ());
920+
921+ // Insert it to the map
922+ new_net_name_map[new_net_name] = new_net;
893923 }
894924 }
895925 }
0 commit comments