@@ -99,7 +99,7 @@ void PinModuleConnection::operator()(const Pin* pin)
9999 }
100100}
101101
102- bool dbEditHierarchy::ConnectionToModuleExists (dbITerm* source_pin,
102+ bool dbEditHierarchy::connectionToModuleExists (dbITerm* source_pin,
103103 dbModule* dest_module,
104104 dbModBTerm*& dest_modbterm,
105105 dbModITerm*& dest_moditerm) const
@@ -145,18 +145,17 @@ void dbEditHierarchy::createHierarchyBottomUp(dbITerm* pin,
145145 dbModNet* db_mod_net = nullptr ;
146146 const char * io_type_str = (io_type == dbIoType::OUTPUT) ? " o" : " i" ;
147147
148- while (cur_module != highest_common_module) {
149- // Decide a new unique pin/net name
150- std::string unique_name
151- = fmt::format (" {}_{}" , connection_name, io_type_str);
152- int id = 0 ;
153- while (cur_module->findModBTerm (unique_name.c_str ())
154- || cur_module->getModNet (unique_name.c_str ())) {
155- id++;
156- unique_name = fmt::format (" {}_{}_{}" , connection_name, io_type_str, id);
157- }
158- const char * new_term_net_name = unique_name.c_str ();
148+ // Decide a new unique pin/net name
149+ std::string unique_name = fmt::format (" {}_{}" , connection_name, io_type_str);
150+ int id = 0 ;
151+ while (cur_module->findModBTerm (unique_name.c_str ())
152+ || cur_module->getModNet (unique_name.c_str ())) {
153+ id++;
154+ unique_name = fmt::format (" {}_{}_{}" , connection_name, io_type_str, id);
155+ }
156+ const char * new_term_net_name = unique_name.c_str ();
159157
158+ while (cur_module != highest_common_module) {
160159 // Create BTerm & ModNet and connect them
161160 dlogCreateHierBTermAndModNet (level, cur_module, new_term_net_name);
162161 dbModBTerm* mod_bterm = dbModBTerm::create (cur_module, new_term_net_name);
@@ -190,6 +189,14 @@ void dbEditHierarchy::createHierarchyBottomUp(dbITerm* pin,
190189 dbModITerm* mod_iterm
191190 = dbModITerm::create (parent_inst, new_term_net_name, mod_bterm);
192191
192+ // Retry to get a new unique pin/net name in the new hierarchy
193+ while (cur_module->findModBTerm (unique_name.c_str ())
194+ || cur_module->getModNet (unique_name.c_str ())) {
195+ id++;
196+ unique_name = fmt::format (" {}_{}_{}" , connection_name, io_type_str, id);
197+ }
198+ new_term_net_name = unique_name.c_str ();
199+
193200 // Create ModNet for the ITerm
194201 if (io_type == dbIoType::OUTPUT
195202 || (io_type == dbIoType::INPUT
@@ -220,7 +227,7 @@ connection_name should be a base name, not a full name.
220227*/
221228void dbEditHierarchy::hierarchicalConnect (dbITerm* source_pin,
222229 dbITerm* dest_pin,
223- const char * connection_name) const
230+ const char * connection_name)
224231{
225232 assert (source_pin != nullptr );
226233 assert (dest_pin != nullptr );
@@ -308,7 +315,7 @@ void dbEditHierarchy::hierarchicalConnect(dbITerm* source_pin,
308315 dbModITerm* dest_moditerm = nullptr ;
309316 // Check do we already have a connection between the source and destination
310317 // pins? If so, reuse it.
311- if (ConnectionToModuleExists (
318+ if (connectionToModuleExists (
312319 source_pin, dest_db_module, dest_modbterm, dest_moditerm)) {
313320 dbModNet* dest_mod_net = nullptr ;
314321 if (dest_modbterm) {
@@ -381,11 +388,21 @@ void dbEditHierarchy::hierarchicalConnect(dbITerm* source_pin,
381388 // Get base name of source_pin_flat_net
382389 Pin* sta_source_pin = db_network_->dbToSta (source_pin);
383390 dbNet* source_pin_flat_net = db_network_->flatNet (sta_source_pin);
384- const char * base_name
385- = db_network_->name (db_network_->dbToSta (source_pin_flat_net));
391+ std::string base_name = fmt::format (
392+ " {}" , db_network_->name (db_network_->dbToSta (source_pin_flat_net)));
393+
394+ // Decide a new unique net name to avoid collisions.
395+ std::string unique_name = base_name;
396+ int id = 0 ;
397+ while (highest_common_module->findModBTerm (unique_name.c_str ())
398+ || highest_common_module->getModNet (unique_name.c_str ())) {
399+ id++;
400+ unique_name = fmt::format (" {}_{}" , base_name, id);
401+ }
386402
387403 // Create and connect dbModNet
388- source_db_mod_net = dbModNet::create (highest_common_module, base_name);
404+ source_db_mod_net
405+ = dbModNet::create (highest_common_module, unique_name.c_str ());
389406 top_mod_dest->connect (source_db_mod_net);
390407 db_network_->disconnectPin (sta_source_pin);
391408 db_network_->connectPin (sta_source_pin,
0 commit comments