Skip to content

Commit e04628b

Browse files
committed
Fixed a bug that connects to an external net
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
1 parent 2fea464 commit e04628b

1 file changed

Lines changed: 74 additions & 39 deletions

File tree

src/odb/src/db/dbModule.cpp

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ void _dbModule::copyModuleInsts(dbModule* old_module,
790790
ITMap& it_map)
791791
{
792792
dbBlock* block = new_module->getOwner();
793+
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,79 @@ 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 in a top level (uninstantiated module),
870+
// every net in the module is an internal net.
871+
// e.g., modinst_name = "<top>" because there is no modinst.
872+
// net_name = "_001_" <-- Internal net.
873+
// There can be no external net crossing module boundary because
874+
// the module is not instantiated.
875+
//
876+
// - Otherwise, an internal net should have the hierarchy prefix
877+
// (= module instance hierarchical name).
878+
// e.g., modinst_name = "u0/alu0"
879+
// net_name = u0/alu0/_001_ <-- Internal net.
880+
// net_name = u0/_001_ <-- External net crossing module
881+
// boundary.
882+
std::string old_net_name = old_net->getName();
883+
std::string modinst_name = old_module->getHierarchicalName();
884+
if (modinst_name != "<top>"
885+
&& old_net_name.compare(0, modinst_name.length(), modinst_name)
886+
!= 0) {
887+
// Skip external net crossing module boundary.
888+
// It will be connected later.
889+
debugPrint(logger,
890+
utl::ODB,
891+
"replace_design",
892+
3,
893+
"Skip: dbNet '{}'. Hierarchy_prefix='{}'\n",
894+
old_net_name,
895+
modinst_name);
896+
continue;
897+
}
898+
new_net_name += block->getBaseName(old_net_name.c_str());
899+
900+
auto it = new_net_name_map.find(new_net_name);
901+
if (it != new_net_name_map.end()) {
902+
// Connect to an existing local net
903+
dbNet* new_net = (*it).second;
904+
new_iterm->connect(new_net);
905+
debugPrint(logger,
906+
utl::ODB,
907+
"replace_design",
908+
1,
909+
" connected iterm '{}' to existing local net '{}'",
910+
new_iterm->getName(),
911+
new_net->getName());
912+
} else {
913+
// Create and connect to a new local net
914+
assert(block->findNet(new_net_name.c_str()) == nullptr);
915+
dbNet* new_net
916+
= dbNet::create(new_module->getOwner(), new_net_name.c_str());
917+
new_iterm->connect(new_net);
918+
debugPrint(logger,
919+
utl::ODB,
920+
"replace_design",
921+
1,
922+
" Connected iterm '{}' to new local net '{}'",
923+
new_iterm->getName(),
924+
new_net->getName());
925+
926+
// Insert it to the map
927+
new_net_name_map[new_net_name] = new_net;
893928
}
894929
}
895930
}

0 commit comments

Comments
 (0)