Skip to content

Commit 6ff4ea2

Browse files
authored
Merge pull request #8021 from The-OpenROAD-Project-staging/secure-integrate-hier-fixes3
Hier: Added getOrFindFlatNet() APIs and fixed assert fails.
2 parents 764f102 + 0fe8597 commit 6ff4ea2

File tree

14 files changed

+243
-191
lines changed

14 files changed

+243
-191
lines changed

src/dbSta/include/db_sta/dbNetwork.hh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class dbNetwork : public ConcreteNetwork
231231
dbNet* findRelatedDbNet(const dbModNet*) const;
232232
dbModNet* findModNetForPin(const Pin*);
233233
dbModNet* findRelatedModNet(const dbNet*) const;
234+
dbModInst* getModInst(Instance* inst) const;
234235

235236
////////////////////////////////////////////////////////////////
236237
// Pin functions
@@ -304,8 +305,11 @@ class dbNetwork : public ConcreteNetwork
304305
const Net* highestConnectedNet(Net* net) const override;
305306
bool isSpecial(Net* net);
306307
dbNet* flatNet(const Net* net) const;
307-
Net* getFlatNet(Net* net) const;
308-
dbModInst* getModInst(Instance* inst) const;
308+
Net* getOrFindFlatNet(const Net* net) const;
309+
dbNet* getOrFindFlatDbNet(const Net* net) const;
310+
Net* getOrFindFlatNet(const Pin* pin) const;
311+
dbNet* getOrFindFlatDbNet(const Pin* pin) const;
312+
bool hasPort(const Net* net) const;
309313

310314
////////////////////////////////////////////////////////////////
311315
// Edit functions

src/dbSta/src/dbNetwork.cc

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,8 +2621,8 @@ Net* dbNetwork::mergedInto(Net*)
26212621

26222622
bool dbNetwork::isSpecial(Net* net)
26232623
{
2624-
dbNet* db_net = staToDb(net);
2625-
return db_net->isSpecial();
2624+
dbNet* db_net = getOrFindFlatDbNet(net);
2625+
return (db_net && db_net->isSpecial());
26262626
}
26272627

26282628
////////////////////////////////////////////////////////////////
@@ -3717,15 +3717,15 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
37173717
for (auto module_to_clean_up : source_parent_tree) {
37183718
dbModInst* mi = module_to_clean_up->getModInst();
37193719
if (mi) {
3720-
mi->RemoveUnusedPortsAndPins();
3720+
mi->removeUnusedPortsAndPins();
37213721
cleaned_up.insert(mi);
37223722
}
37233723
}
37243724
for (auto module_to_clean_up : dest_parent_tree) {
37253725
dbModInst* mi = module_to_clean_up->getModInst();
37263726
if (mi) {
37273727
if (cleaned_up.find(mi) == cleaned_up.end()) {
3728-
mi->RemoveUnusedPortsAndPins();
3728+
mi->removeUnusedPortsAndPins();
37293729
cleaned_up.insert(mi);
37303730
}
37313731
}
@@ -3736,7 +3736,7 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
37363736
void dbNetwork::removeUnusedPortsAndPinsOnModuleInstances()
37373737
{
37383738
for (auto mi : block()->getModInsts()) {
3739-
mi->RemoveUnusedPortsAndPins();
3739+
mi->removeUnusedPortsAndPins();
37403740
}
37413741
}
37423742

@@ -4228,19 +4228,60 @@ void dbNetwork::checkAxioms()
42284228
checkSanityNetNames();
42294229
}
42304230

4231-
Net* dbNetwork::getFlatNet(Net* net) const
4231+
// Given a net that may be hierarchical, find the corresponding flat net.
4232+
// If the net is already a flat net, it is returned as is.
4233+
// If the net is a hierarchical net (dbModNet), find the associated dbNet and
4234+
// return it as Net*.
4235+
Net* dbNetwork::getOrFindFlatNet(const Net* net) const
4236+
{
4237+
return dbToSta(getOrFindFlatDbNet(net));
4238+
}
4239+
4240+
// Given a net that may be hierarchical, find the corresponding flat dbNet.
4241+
// If the net is already a flat net (dbNet), it is returned as is.
4242+
// If the net is a hierarchical net (dbModNet), find the associated dbNet.
4243+
dbNet* dbNetwork::getOrFindFlatDbNet(const Net* net) const
42324244
{
42334245
if (!net) {
42344246
return nullptr;
42354247
}
42364248
// Convert net to a flat net, if not already
4237-
dbNet* db_net;
4238-
dbModNet* db_mod_net;
4249+
dbNet* db_net = nullptr;
4250+
dbModNet* db_mod_net = nullptr;
42394251
staToDb(net, db_net, db_mod_net);
4252+
4253+
if (db_net) {
4254+
// If it's already a flat net, return it
4255+
return db_net;
4256+
}
4257+
42404258
if (db_mod_net) {
4259+
// If it's a hierarchical net, find the associated dbNet
4260+
// by traversing the hierarchy.
42414261
db_net = findRelatedDbNet(db_mod_net);
42424262
}
4243-
return dbToSta(db_net);
4263+
return db_net;
4264+
}
4265+
4266+
// Find the flat net connected to the pin.
4267+
// This function handles both internal instance pins and top-level port pins.
4268+
Net* dbNetwork::getOrFindFlatNet(const Pin* pin) const
4269+
{
4270+
return dbToSta(getOrFindFlatDbNet(pin));
4271+
}
4272+
4273+
// Find the flat net (dbNet) connected to the pin in the OpenDB database.
4274+
// This function handles both internal instance pins and top-level port pins.
4275+
dbNet* dbNetwork::getOrFindFlatDbNet(const Pin* pin) const
4276+
{
4277+
dbNet* db_net = nullptr;
4278+
if (isTopLevelPort(pin)) {
4279+
Net* net = this->net(term(pin));
4280+
db_net = flatNet(net);
4281+
} else {
4282+
db_net = flatNet(pin);
4283+
}
4284+
return db_net;
42444285
}
42454286

42464287
dbModInst* dbNetwork::getModInst(Instance* inst) const
@@ -4255,6 +4296,24 @@ dbModInst* dbNetwork::getModInst(Instance* inst) const
42554296
return db_mod_inst;
42564297
}
42574298

4299+
bool dbNetwork::hasPort(const Net* net) const
4300+
{
4301+
if (!net) {
4302+
return false;
4303+
}
4304+
4305+
dbNet* db_net = nullptr;
4306+
dbModNet* db_mod_net = nullptr;
4307+
staToDb(net, db_net, db_mod_net);
4308+
if (db_net) {
4309+
return !db_net->getBTerms().empty();
4310+
}
4311+
if (db_mod_net) {
4312+
return !db_mod_net->getBTerms().empty();
4313+
}
4314+
return false;
4315+
}
4316+
42584317
void dbNetwork::checkSanityModBTerms()
42594318
{
42604319
if (block_ == nullptr) {

src/dbSta/test/cpp/TestHconn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void DbStrDebugHierarchy(dbBlock* block, std::stringstream& str_db)
107107
sprintf(tmp_str,
108108
"\tModule %s %s\n",
109109
(cur_obj == block->getTopModule()) ? "(Top Module)" : "",
110-
((dbModule*) cur_obj)->getName());
110+
cur_obj->getName());
111111
str_db << tmp_str;
112112
// in case of top level, care as the bterms double up as pins
113113
if (cur_obj == block->getTopModule()) {

src/est/src/EstimateParasitics.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -993,13 +993,8 @@ SteinerTree* EstimateParasitics::makeSteinerTree(const Pin* drvr_pin)
993993
/*
994994
Handle hierarchy. Make sure all traversal on dbNets.
995995
*/
996-
odb::dbNet* db_net = db_network_->flatNet(drvr_pin);
997-
998-
Net* net
999-
= network_->isTopLevelPort(drvr_pin)
1000-
? network_->net(network_->term(drvr_pin))
1001-
// original code, could retrun a mod net : network_->net(drvr_pin);
1002-
: db_network_->dbToSta(db_net);
996+
odb::dbNet* db_net = db_network_->getOrFindFlatDbNet(drvr_pin);
997+
Net* net = db_network_->dbToSta(db_net);
1003998

1004999
debugPrint(logger_, EST, "steiner", 1, "Net {}", sdc_network->pathName(net));
10051000
SteinerTree* tree = new SteinerTree(drvr_pin, db_network_, logger_);
@@ -1042,8 +1037,7 @@ SteinerTree* EstimateParasitics::makeSteinerTree(const Pin* drvr_pin)
10421037
tree->locAddPin(pinloc.loc, pinloc.pin);
10431038
}
10441039
if (is_placed) {
1045-
stt::Tree ftree = stt_builder_->makeSteinerTree(
1046-
db_network_->staToDb(net), x, y, drvr_idx);
1040+
stt::Tree ftree = stt_builder_->makeSteinerTree(db_net, x, y, drvr_idx);
10471041

10481042
tree->setTree(ftree);
10491043
tree->createSteinerPtToPinMap();

src/gui/src/staGuiInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ sta::Net* ClockTree::getNet(const sta::Pin* pin) const
724724
{
725725
sta::Term* term = network_->term(pin);
726726
sta::Net* net = term ? network_->net(term) : network_->net(pin);
727-
return network_->getFlatNet(net);
727+
return network_->getOrFindFlatNet(net);
728728
}
729729

730730
bool ClockTree::isLeaf(const sta::Pin* pin) const

src/odb/include/odb/db.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8025,7 +8025,7 @@ class dbModInst : public dbObject
80258025

80268026
dbSet<dbModITerm> getModITerms();
80278027

8028-
void RemoveUnusedPortsAndPins();
8028+
void removeUnusedPortsAndPins();
80298029

80308030
/// Swap the module of this instance.
80318031
/// Returns new mod inst if the operations succeeds.
@@ -8116,7 +8116,7 @@ class dbModule : public dbObject
81168116
// Get the ports of a module (STA world uses ports, which contain members).
81178117
dbSet<dbModBTerm> getPorts();
81188118
// Get the leaf level connections on a module (flat connected view).
8119-
dbSet<dbModBTerm> getModBTerms();
8119+
dbSet<dbModBTerm> getModBTerms() const;
81208120
dbModBTerm* getModBTerm(uint id);
81218121
dbSet<dbInst> getInsts();
81228122

@@ -8130,6 +8130,7 @@ class dbModule : public dbObject
81308130
int getDbInstCount();
81318131

81328132
const dbModBTerm* getHeadDbModBTerm() const;
8133+
bool canSwapWith(dbModule* new_module) const;
81338134

81348135
static dbModule* create(dbBlock* block, const char* name);
81358136

0 commit comments

Comments
 (0)