Skip to content

Commit d4a4962

Browse files
authored
Merge pull request #8241 from The-OpenROAD-Project-staging/secure-fix-cts-del-modnet
cts: Deleted dangling dbModNet for top-level clock port.
2 parents c3d80e7 + 658a560 commit d4a4962

File tree

12 files changed

+76
-17
lines changed

12 files changed

+76
-17
lines changed

src/cts/include/cts/TritonCTS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Unit;
3434
class LibertyCell;
3535
class Vertex;
3636
class Graph;
37+
class Pin;
3738
} // namespace sta
3839

3940
namespace stt {
@@ -114,6 +115,7 @@ class TritonCTS
114115
// db functions
115116
bool masterExists(const std::string& master) const;
116117
void populateTritonCTS();
118+
void destroyClockModNet(sta::Pin* pin_driver);
117119
void writeClockNetsToDb(TreeBuilder* builder,
118120
std::set<odb::dbNet*>& clkLeafNets);
119121
void writeClockNDRsToDb(TreeBuilder* builder);

src/cts/src/TritonCTS.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,18 @@ void TritonCTS::computeITermPosition(odb::dbITerm* term, int& x, int& y) const
13921392
}
13931393
};
13941394

1395+
void TritonCTS::destroyClockModNet(sta::Pin* pin_driver)
1396+
{
1397+
if (pin_driver == nullptr || network_->hasHierarchy() == false) {
1398+
return;
1399+
}
1400+
1401+
odb::dbModNet* mod_net = network_->hierNet(pin_driver);
1402+
if (mod_net) {
1403+
odb::dbModNet::destroy(mod_net);
1404+
}
1405+
}
1406+
13951407
void TritonCTS::writeClockNetsToDb(TreeBuilder* builder,
13961408
std::set<odb::dbNet*>& clkLeafNets)
13971409
{
@@ -1405,6 +1417,12 @@ void TritonCTS::writeClockNetsToDb(TreeBuilder* builder,
14051417

14061418
disconnectAllSinksFromNet(topClockNet);
14071419

1420+
// If exists, remove the dangling dbModNet related to the topClockNet because
1421+
// topClockNet has no load pin now.
1422+
// After CTS, the driver pin will drive only a few of root clock buffers.
1423+
// So the hierarchical net (dbModNet) is not needed any more.
1424+
destroyClockModNet(pin_driver);
1425+
14081426
// re-connect top buffer that separates macros from registers
14091427
if (builder->getTreeType() == TreeType::RegisterTree) {
14101428
odb::dbInst* topRegBuffer

src/dbSta/src/dbNetwork.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ void dbNetwork::disconnectPin(Pin* pin, Net* net)
25922592
iterm->disconnectDbNet();
25932593
}
25942594
if (mod_net) {
2595-
iterm->disconnectModNet();
2595+
iterm->disconnectDbModNet();
25962596
}
25972597
} else if (bterm) {
25982598
if (db_net) {

src/odb/include/odb/db.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ class dbBlock : public dbObject
617617
///
618618
/// Returns the top module of this block.
619619
///
620-
dbModule* getTopModule();
620+
dbModule* getTopModule() const;
621621

622622
///
623623
/// Get the child blocks of this block.
@@ -2947,8 +2947,8 @@ class dbInst : public dbObject
29472947

29482948
///
29492949
/// Create a new instance.
2950-
/// If physical_only is true the instance can't bee added to a dbModule.
2951-
/// If false, it will be added to the top module.
2950+
/// If physical_only is true, the instance can only be added to a top module.
2951+
/// If false, it will be added to the parent module.
29522952
/// Returns nullptr if an instance with this name already exists.
29532953
/// Returns nullptr if the master is not FROZEN.
29542954
/// If dbmodule is non null the dbInst is added to that module.
@@ -3202,7 +3202,7 @@ class dbITerm : public dbObject
32023202
/// Disconnect just the mod net
32033203
///
32043204

3205-
void disconnectModNet();
3205+
void disconnectDbModNet();
32063206

32073207
///
32083208
/// Get the average of the centers for the iterm shapes
@@ -8293,6 +8293,7 @@ class dbModNet : public dbObject
82938293
unsigned connectionCount();
82948294
const char* getName() const;
82958295
void rename(const char* new_name);
8296+
void disconnectAllTerms();
82968297

82978298
static dbModNet* getModNet(dbBlock* block, uint id);
82988299
static dbModNet* create(dbModule* parentModule, const char* base_name);
@@ -8343,6 +8344,7 @@ class dbModule : public dbObject
83438344

83448345
const dbModBTerm* getHeadDbModBTerm() const;
83458346
bool canSwapWith(dbModule* new_module) const;
8347+
bool isTop() const;
83468348

83478349
static dbModule* create(dbBlock* block, const char* name);
83488350

src/odb/src/db/dbBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ dbInst* dbBlock::getParentInst()
15811581
return (dbInst*) parent_inst;
15821582
}
15831583

1584-
dbModule* dbBlock::getTopModule()
1584+
dbModule* dbBlock::getTopModule() const
15851585
{
15861586
_dbBlock* block = (_dbBlock*) this;
15871587
return (dbModule*) block->_module_tbl->getPtr(block->_top_module);

src/odb/src/db/dbITerm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void dbITerm::connect(dbModNet* mod_net)
405405
// accidentally blow away prior flat net connections)
406406

407407
if (iterm->_mnet != 0) {
408-
disconnectModNet();
408+
disconnectDbModNet();
409409
}
410410

411411
iterm->_mnet = _mod_net->getId();
@@ -625,7 +625,7 @@ void dbITerm::disconnectDbNet()
625625
//
626626
// Disconnect the mod net and allow journaling
627627
//
628-
void dbITerm::disconnectModNet()
628+
void dbITerm::disconnectDbModNet()
629629
{
630630
_dbITerm* iterm = (_dbITerm*) this;
631631
_dbBlock* block = (_dbBlock*) iterm->getOwner();

src/odb/src/db/dbInst.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,10 @@ dbInst* dbInst::create(dbBlock* block_,
13221322
block->add_rect(box->_shape._rect);
13231323

13241324
inst->_flags._physical_only = physical_only;
1325-
if (!physical_only) {
1325+
1326+
// Add the new instance to the parent module.
1327+
bool parent_is_top = parent_module == nullptr || parent_module->isTop();
1328+
if (physical_only == false || parent_is_top) {
13261329
if (parent_module) {
13271330
parent_module->addInst((dbInst*) inst);
13281331
} else {

src/odb/src/db/dbJournal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void dbJournal::redo_disconnectObject()
784784
} else if (net_id != 0) {
785785
iterm->disconnectDbNet();
786786
} else if (mnet_id != 0) {
787-
iterm->disconnectModNet();
787+
iterm->disconnectDbModNet();
788788
}
789789
break;
790790
}
@@ -2082,7 +2082,7 @@ void dbJournal::undo_connectObject()
20822082
iterm->disconnectDbNet();
20832083
}
20842084
if (mnet_id != 0) {
2085-
iterm->disconnectModNet();
2085+
iterm->disconnectDbModNet();
20862086
}
20872087
break;
20882088
}

src/odb/src/db/dbModInst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ dbModInst* dbModInst::swapMaster(dbModule* new_module)
587587
// iterm may be connected to another hierarchical instance
588588
dbModNet* other_mod_net = old_iterm->getModNet();
589589
if (other_mod_net != old_mod_net) {
590-
old_iterm->disconnectModNet();
590+
old_iterm->disconnectDbModNet();
591591
old_iterm->connect(old_mod_net); // Reconnect old mod net for later use
592592
debugRDPrint1(" disconnected old iterm {} from other mod net {}",
593593
old_iterm->getName(),

src/odb/src/db/dbModNet.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ void dbModNet::rename(const char* new_name)
178178
parent->_modnet_hash[new_name] = obj->getOID();
179179
}
180180

181+
void dbModNet::disconnectAllTerms()
182+
{
183+
// Disconnect all terminals.
184+
// - The loops are structured this way to handle the modification of the dbSet
185+
// during iteration.
186+
while (!getITerms().empty()) {
187+
getITerms().begin()->disconnectDbModNet();
188+
}
189+
190+
while (!getBTerms().empty()) {
191+
getBTerms().begin()->disconnectDbModNet();
192+
}
193+
194+
while (!getModITerms().empty()) {
195+
getModITerms().begin()->disconnect();
196+
}
197+
198+
while (!getModBTerms().empty()) {
199+
getModBTerms().begin()->disconnect();
200+
}
201+
}
202+
181203
dbModNet* dbModNet::getModNet(dbBlock* block, uint id)
182204
{
183205
_dbBlock* block_ = (_dbBlock*) block;
@@ -225,6 +247,8 @@ void dbModNet::destroy(dbModNet* mod_net)
225247
_dbBlock* block = (_dbBlock*) _modnet->getOwner();
226248
_dbModule* module = block->_module_tbl->getPtr(_modnet->_parent);
227249

250+
mod_net->disconnectAllTerms();
251+
228252
// journalling
229253
if (block->_journal) {
230254
block->_journal->beginAction(dbJournal::DELETE_OBJECT);

0 commit comments

Comments
 (0)