From ecf5c83efaddc300b11c641c54559b0b0cada1c3 Mon Sep 17 00:00:00 2001 From: andyfox-rushc Date: Mon, 20 May 2024 06:33:13 -0700 Subject: [PATCH] Initial version of dbNetwork commit part 2, wip. Signed-off-by: Andy Fox Signed-off-by: andyfox-rushc --- src/Timing.cc | 4 +- src/cts/src/TritonCTS.cpp | 4 +- src/dbSta/include/db_sta/dbNetwork.hh | 35 +- src/dbSta/src/dbNetwork.cc | 542 +++++++++++++++++++++----- src/dbSta/src/dbSta.i | 8 +- src/dbSta/test/hier2.ok | 5 +- src/dbSta/test/regression_tests.tcl | 1 + src/gui/src/chartsWidget.h | 5 +- src/gui/src/clockWidget.cpp | 19 +- src/gui/src/dbDescriptors.cpp | 50 +-- src/gui/src/staGui.cpp | 8 +- src/gui/src/staGuiInterface.cpp | 8 +- src/rmp/src/Restructure.cpp | 4 +- src/rsz/src/Resizer.cc | 4 +- 14 files changed, 555 insertions(+), 142 deletions(-) diff --git a/src/Timing.cc b/src/Timing.cc index 0ca7a7a56d6..0d5e6579362 100644 --- a/src/Timing.cc +++ b/src/Timing.cc @@ -69,7 +69,9 @@ std::pair Timing::staToDBPin(const sta::Pin* pin) sta::dbNetwork* db_network = openroad->getDbNetwork(); odb::dbITerm* iterm; odb::dbBTerm* bterm; - db_network->staToDb(pin, iterm, bterm); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + db_network->staToDb(pin, iterm, bterm, moditerm, modbterm); return std::make_pair(iterm, bterm); } diff --git a/src/cts/src/TritonCTS.cpp b/src/cts/src/TritonCTS.cpp index 7da74f843ee..e92f0c0862b 100644 --- a/src/cts/src/TritonCTS.cpp +++ b/src/cts/src/TritonCTS.cpp @@ -1522,7 +1522,9 @@ void TritonCTS::findClockRoots(sta::Clock* clk, for (const sta::Pin* pin : clk->leafPins()) { odb::dbITerm* instTerm; odb::dbBTerm* port; - network_->staToDb(pin, instTerm, port); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + network_->staToDb(pin, instTerm, port, moditerm, modbterm); odb::dbNet* net = instTerm ? instTerm->getNet() : port->getNet(); clockNets.insert(net); } diff --git a/src/dbSta/include/db_sta/dbNetwork.hh b/src/dbSta/include/db_sta/dbNetwork.hh index ca357fc4fb5..69a7cc0b55e 100644 --- a/src/dbSta/include/db_sta/dbNetwork.hh +++ b/src/dbSta/include/db_sta/dbNetwork.hh @@ -57,7 +57,10 @@ using odb::dbIoType; using odb::dbITerm; using odb::dbLib; using odb::dbMaster; +using odb::dbModBTerm; using odb::dbModInst; +using odb::dbModITerm; +using odb::dbModNet; using odb::dbModule; using odb::dbMTerm; using odb::dbNet; @@ -114,26 +117,32 @@ class dbNetwork : public ConcreteNetwork LibertyCell* libertyCell(dbInst* inst); - // Use the this if you know you are dealing with a leaf instance dbInst* staToDb(const Instance* instance) const; - // Use the this if you might have a hierarchical instance void staToDb(const Instance* instance, - // Return values. dbInst*& db_inst, dbModInst*& mod_inst) const; - dbNet* staToDb(const Net* net) const; void staToDb(const Pin* pin, - // Return values. dbITerm*& iterm, - dbBTerm*& bterm) const; + dbBTerm*& bterm, + dbModITerm*& moditerm, + dbModBTerm*& modbterm) const; + + dbNet* staToDb(const Net* net) const; + void staToDb(const Net* net, dbNet*& dnet, dbModNet*& modnet) const; + + void staToDb(const Pin* pin, dbITerm*& iterm, dbBTerm*& bterm) const; dbBTerm* staToDb(const Term* term) const; + void staToDb(const Term* term, + dbITerm*& iterm, + dbBTerm*& bterm, + dbModITerm*& moditerm, + dbModBTerm*& modbterm) const; dbMaster* staToDb(const Cell* cell) const; void staToDb(const Cell* cell, dbMaster*& master, dbModule*& module) const; dbMaster* staToDb(const LibertyCell* cell) const; dbMTerm* staToDb(const Port* port) const; dbMTerm* staToDb(const LibertyPort* port) const; void staToDb(PortDirection* dir, - // Return values. dbSigType& sig_type, dbIoType& io_type) const; @@ -141,12 +150,20 @@ class dbNetwork : public ConcreteNetwork Term* dbToStaTerm(dbBTerm* bterm) const; Pin* dbToSta(dbITerm* iterm) const; Instance* dbToSta(dbInst* inst) const; - Instance* dbToSta(dbModInst* inst) const; Net* dbToSta(dbNet* net) const; const Net* dbToSta(const dbNet* net) const; Cell* dbToSta(dbMaster* master) const; - Cell* dbToSta(dbModule* master) const; Port* dbToSta(dbMTerm* mterm) const; + + Instance* dbToSta(dbModInst* inst) const; + Cell* dbToSta(dbModule* master) const; + Pin* dbToSta(dbModITerm* mod_iterm) const; + Pin* dbToStaPin(dbModBTerm* mod_bterm) const; + Net* dbToSta(dbModNet* net) const; + Port* dbToSta(dbModBTerm* modbterm) const; + Term* dbToStaTerm(dbModITerm* moditerm) const; + Term* dbToStaTerm(dbModBTerm* modbterm) const; + PortDirection* dbToSta(const dbSigType& sig_type, const dbIoType& io_type) const; // dbStaCbk::inDbBTermCreate diff --git a/src/dbSta/src/dbNetwork.cc b/src/dbSta/src/dbNetwork.cc index a90d93df4f4..35f71da430c 100644 --- a/src/dbSta/src/dbNetwork.cc +++ b/src/dbSta/src/dbNetwork.cc @@ -61,7 +61,10 @@ using odb::dbITermObj; using odb::dbLib; using odb::dbMaster; using odb::dbModBTerm; +using odb::dbModBTermObj; using odb::dbModInstObj; +using odb::dbModITerm; +using odb::dbModITermObj; using odb::dbModule; using odb::dbMTerm; using odb::dbNet; @@ -239,7 +242,6 @@ Net* DbInstanceNetIterator::next() } //////////////////////////////////////////////////////////////// - class DbInstancePinIterator : public InstancePinIterator { public: @@ -254,7 +256,11 @@ class DbInstancePinIterator : public InstancePinIterator dbSet::iterator iitr_end_; dbSet::iterator bitr_; dbSet::iterator bitr_end_; + dbSet::iterator mi_itr_; + dbSet::iterator mi_itr_end_; Pin* next_ = nullptr; + dbInst* db_inst_; + dbModInst* mod_inst_; }; DbInstancePinIterator::DbInstancePinIterator(const Instance* inst, @@ -262,19 +268,25 @@ DbInstancePinIterator::DbInstancePinIterator(const Instance* inst, : network_(network) { top_ = (inst == network->topInstance()); + db_inst_ = nullptr; + mod_inst_ = nullptr; + if (top_) { dbBlock* block = network->block(); - if (block) { - bitr_ = block->getBTerms().begin(); - bitr_end_ = block->getBTerms().end(); - } + bitr_ = block->getBTerms().begin(); + bitr_end_ = block->getBTerms().end(); } else { dbInst* db_inst; - dbModInst* mod_inst; // has no inst pins in odb + dbModInst* mod_inst; network_->staToDb(inst, db_inst, mod_inst); if (db_inst) { iitr_ = db_inst->getITerms().begin(); iitr_end_ = db_inst->getITerms().end(); + } else if (mod_inst_) { + if (network_->hasHierarchy()) { + mi_itr_ = mod_inst_->getModITerms().begin(); + mi_itr_end_ = mod_inst_->getModITerms().end(); + } } } } @@ -300,6 +312,13 @@ bool DbInstancePinIterator::hasNext() } iitr_++; } + + if ((mi_itr_ != mi_itr_end_) && (network_->hasHierarchy())) { + dbModITerm* mod_iterm = *mi_itr_; + next_ = network_->dbToSta(mod_iterm); + mi_itr_++; + return true; + } return false; } @@ -320,16 +339,29 @@ class DbNetPinIterator : public NetPinIterator private: dbSet::iterator iitr_; dbSet::iterator iitr_end_; + dbSet::iterator mitr_; + dbSet::iterator mitr_end_; Pin* next_; + const dbNetwork* network_; }; -DbNetPinIterator::DbNetPinIterator(const Net* net, - const dbNetwork* /* network */) +DbNetPinIterator::DbNetPinIterator(const Net* net, const dbNetwork* network) { - dbNet* dnet = reinterpret_cast(const_cast(net)); - iitr_ = dnet->getITerms().begin(); - iitr_end_ = dnet->getITerms().end(); - next_ = nullptr; + dbNet* dnet = nullptr; + dbModNet* modnet = nullptr; + network_ = network; + network->staToDb(net, dnet, modnet); + if (dnet) { + iitr_ = dnet->getITerms().begin(); + iitr_end_ = dnet->getITerms().end(); + next_ = nullptr; + } + if (modnet) { + iitr_ = modnet->getITerms().begin(); + iitr_end_ = modnet->getITerms().end(); + mitr_ = modnet->getModITerms().begin(); + mitr_end_ = modnet->getModITerms().end(); + } } bool DbNetPinIterator::hasNext() @@ -343,6 +375,11 @@ bool DbNetPinIterator::hasNext() } iitr_++; } + if ((mitr_ != mitr_end_) && (network_->hasHierarchy())) { + next_ = reinterpret_cast(*mitr_); + ++mitr_; + return true; + } return false; } @@ -364,27 +401,49 @@ class DbNetTermIterator : public NetTermIterator const dbNetwork* network_; dbSet::iterator iter_; dbSet::iterator end_; + dbSet::iterator mod_iter_; + dbSet::iterator mod_end_; }; DbNetTermIterator::DbNetTermIterator(const Net* net, const dbNetwork* network) : network_(network) { - dbNet* dnet = network_->staToDb(net); - dbSet terms = dnet->getBTerms(); - iter_ = terms.begin(); - end_ = terms.end(); + dbModNet* modnet = nullptr; + dbNet* dnet = nullptr; + network_->staToDb(net, dnet, modnet); + if (dnet && !modnet) { + dbSet terms = dnet->getBTerms(); + iter_ = terms.begin(); + end_ = terms.end(); + } else if (modnet) { + dbSet terms = modnet->getBTerms(); + iter_ = terms.begin(); + end_ = terms.end(); + dbSet modbterms = modnet->getModBTerms(); + mod_iter_ = modbterms.begin(); + mod_end_ = modbterms.end(); + } } bool DbNetTermIterator::hasNext() { - return iter_ != end_; + if (mod_iter_ != mod_end_ || iter_ != end_) + return true; + return false; } Term* DbNetTermIterator::next() { - dbBTerm* bterm = *iter_; - iter_++; - return network_->dbToStaTerm(bterm); + if (iter_ != end_) { + dbBTerm* bterm = *iter_; + iter_++; + return network_->dbToStaTerm(bterm); + } else if (mod_iter_ != mod_end_ && (network_->hasHierarchy())) { + dbModBTerm* modbterm = *mod_iter_; + mod_iter_++; + return network_->dbToStaTerm(modbterm); + } + return nullptr; } //////////////////////////////////////////////////////////////// @@ -515,6 +574,7 @@ void dbNetwork::makeVerilogCell(Library* library, dbModInst* mod_inst) } } +// upto here. Cell* dbNetwork::cell(const Instance* instance) const { if (instance == top_instance_) { @@ -591,7 +651,6 @@ Instance* dbNetwork::findChild(const Instance* parent, const char* name) const dbModInst* mod_inst = top_module->findModInst(name); return dbToSta(mod_inst); } - return dbToSta(inst); } dbInst* db_inst; @@ -618,7 +677,6 @@ Pin* dbNetwork::findPin(const Instance* instance, const char* port_name) const dbBTerm* bterm = block_->findBTerm(port_name); return dbToSta(bterm); } - dbInst* db_inst; dbModInst* mod_inst; staToDb(instance, db_inst, mod_inst); @@ -626,6 +684,10 @@ Pin* dbNetwork::findPin(const Instance* instance, const char* port_name) const dbITerm* iterm = db_inst->findITerm(port_name); return dbToSta(iterm); } + if (mod_inst) { + dbModITerm* miterm = mod_inst->findModITerm(port_name); + return dbToSta(miterm); + } return nullptr; // no pins on dbModInst in odb currently } @@ -687,21 +749,37 @@ InstanceNetIterator* dbNetwork::netIterator(const Instance* instance) const ObjectId dbNetwork::id(const Pin* pin) const { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm != nullptr) { return iterm->getId() << 1; } - return (bterm->getId() << 1) + 1; + if (bterm != nullptr) { + return (bterm->getId() << 1) + 1; + } + + if (moditerm != nullptr) { + return (moditerm->getId()); + } + if (modbterm != nullptr) { + return (modbterm->getId()); + } + return 0; } Instance* dbNetwork::instance(const Pin* pin) const { dbITerm* iterm; dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { dbInst* dinst = iterm->getInst(); return dbToSta(dinst); @@ -709,32 +787,88 @@ Instance* dbNetwork::instance(const Pin* pin) const if (bterm) { return top_instance_; } + if (moditerm) { + dbModInst* mod_inst = moditerm->getParent(); + return dbToSta(mod_inst); + } + if (modbterm) { + dbModule* module = modbterm->getParent(); + dbModInst* mod_inst = module->getModInst(); + return dbToSta(mod_inst); + } return nullptr; } Net* dbNetwork::net(const Pin* pin) const { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { dbNet* dnet = iterm->getNet(); - return dbToSta(dnet); + dbModNet* mnet = iterm->getModNet(); + // It is possible when writing out a hierarchical network + // that we have both a mod net and a dbinst net. + // In the case of writing out a hierachical network we always + // choose the mnet. + if (dnet && mnet) { + return dbToSta(mnet); + } + if (mnet) + return dbToSta(mnet); + if (dnet) + return dbToSta(dnet); + } + // only pins which act as bterms are top levels and have no net + if (bterm) { + return nullptr; + } + if (moditerm) { + dbModNet* mnet = moditerm->getModNet(); + return dbToSta(mnet); + } + if (modbterm) { + dbModNet* mnet = modbterm->getModNet(); + return dbToSta(mnet); } return nullptr; } Term* dbNetwork::term(const Pin* pin) const { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { return nullptr; } if (bterm) { return dbToStaTerm(bterm); } + if (moditerm) { + // get the mod bterm + std::string port_name_str = moditerm->getName(); + size_t last_idx = port_name_str.find_last_of('/'); + if (last_idx != string::npos) { + port_name_str = port_name_str.substr(last_idx + 1); + } + const char* port_name = port_name_str.c_str(); + dbModInst* mod_inst = moditerm->getParent(); + dbModule* module = mod_inst->getMaster(); + dbModBTerm* mod_port = module->findModBTerm(port_name); + if (mod_port) { + Term* ret = dbToStaTerm(mod_port); + return ret; + } + } + if (modbterm) { + return dbToStaTerm(modbterm); + } return nullptr; } @@ -742,16 +876,34 @@ Port* dbNetwork::port(const Pin* pin) const { dbITerm* iterm; dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbModITerm* moditerm; + dbModBTerm* modbterm; + Port* ret = nullptr; + + // Will return the bterm for a top level pin + staToDb(pin, iterm, bterm, moditerm, modbterm); + if (iterm) { dbMTerm* mterm = iterm->getMTerm(); - return dbToSta(mterm); - } - if (bterm) { + ret = dbToSta(mterm); + } else if (bterm) { const char* port_name = bterm->getConstName(); - return findPort(top_cell_, port_name); + ret = findPort(top_cell_, port_name); + } else if (moditerm) { + std::string port_name_str = moditerm->getName(); + const char* port_name = port_name_str.c_str(); + dbModInst* mod_inst = moditerm->getParent(); + dbModule* module = mod_inst->getMaster(); + dbModBTerm* mod_port = module->findModBTerm(port_name); + if (mod_port) { + ret = dbToSta(mod_port); + return ret; + } + } else if (modbterm) { + ret = dbToSta(modbterm); } - return nullptr; + assert(ret != nullptr); + return ret; } PortDirection* dbNetwork::direction(const Pin* pin) const @@ -764,7 +916,11 @@ PortDirection* dbNetwork::direction(const Pin* pin) const } dbITerm* iterm; dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbModBTerm* modbterm; + dbModITerm* moditerm; + // pin -> iterm or moditerm + + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { PortDirection* dir = dbToSta(iterm->getSigType(), iterm->getIoType()); return dir; @@ -773,14 +929,30 @@ PortDirection* dbNetwork::direction(const Pin* pin) const PortDirection* dir = dbToSta(bterm->getSigType(), bterm->getIoType()); return dir; } + if (modbterm) { + PortDirection* dir = dbToSta(modbterm->getSigType(), modbterm->getIoType()); + return dir; + } + if (moditerm) { + // get the direction off the modbterm + std::string pin_name = moditerm->getName(); + dbModInst* mod_inst = moditerm->getParent(); + dbModule* module = mod_inst->getParent(); + dbModBTerm* modbterm_local = module->findModBTerm(pin_name.c_str()); + PortDirection* dir + = dbToSta(modbterm_local->getSigType(), modbterm_local->getIoType()); + return dir; + } return PortDirection::unknown(); } VertexId dbNetwork::vertexId(const Pin* pin) const { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* miterm = nullptr; + dbModBTerm* mbterm = nullptr; + staToDb(pin, iterm, bterm, miterm, mbterm); if (iterm) { return iterm->staVertexId(); } @@ -792,9 +964,11 @@ VertexId dbNetwork::vertexId(const Pin* pin) const void dbNetwork::setVertexId(Pin* pin, VertexId id) { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { iterm->staSetVertexId(id); } else if (bterm) { @@ -822,9 +996,12 @@ void dbNetwork::location(const Pin* pin, Point dbNetwork::location(const Pin* pin) const { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { int x, y; if (iterm->getAvgXY(&x, &y)) { @@ -843,9 +1020,12 @@ Point dbNetwork::location(const Pin* pin) const bool dbNetwork::isPlaced(const Pin* pin) const { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + + staToDb(pin, iterm, bterm, moditerm, modbterm); dbPlacementStatus status = dbPlacementStatus::UNPLACED; if (iterm) { dbInst* inst = iterm->getInst(); @@ -866,9 +1046,17 @@ ObjectId dbNetwork::id(const Net* net) const const char* dbNetwork::name(const Net* net) const { - dbNet* dnet = staToDb(net); - const char* name = dnet->getConstName(); - return tmpStringCopy(name); + dbModNet* modnet = nullptr; + dbNet* dnet = nullptr; + staToDb(net, dnet, modnet); + if (dnet) { + const char* name = dnet->getConstName(); + return tmpStringCopy(name); + } else if (modnet) { + std::string net_name = modnet->getName(); + return tmpStringCopy(net_name.c_str()); + } + return nullptr; } Instance* dbNetwork::instance(const Net*) const @@ -903,14 +1091,74 @@ void dbNetwork::visitConnectedPins(const Net* net, PinVisitor& visitor, NetSet& visited_nets) const { - dbNet* db_net = staToDb(net); - for (dbITerm* iterm : db_net->getITerms()) { - Pin* pin = dbToSta(iterm); - visitor(pin); - } - for (dbBTerm* bterm : db_net->getBTerms()) { - Pin* pin = dbToSta(bterm); - visitor(pin); + dbModNet* mod_net = nullptr; + dbNet* db_net = nullptr; + + if (visited_nets.hasKey(net)) + return; + + visited_nets.insert(net); + staToDb(net, db_net, mod_net); + + if (mod_net) { + for (dbITerm* iterm : mod_net->getITerms()) { + Pin* pin = dbToSta(iterm); + visitor(pin); + } + for (dbBTerm* bterm : mod_net->getBTerms()) { + Pin* pin = dbToSta(bterm); + visitor(pin); + } + for (dbModBTerm* modbterm : mod_net->getModBTerms()) { + Pin* pin = dbToStaPin(modbterm); + // search up + visitor(pin); + } + for (dbModITerm* moditerm : mod_net->getModITerms()) { + Pin* pin = dbToSta(moditerm); + // search down + visitor(pin); + } + + // visit below nets + for (dbModITerm* moditerm : mod_net->getModITerms()) { + dbModInst* mod_inst = moditerm->getParent(); + // note we are deailing with a uniquified hierarchy + // so one master per instance.. + dbModule* module = mod_inst->getMaster(); + std::string pin_name = moditerm->getName(); + dbModBTerm* mod_bterm = module->findModBTerm(pin_name.c_str()); + Pin* below_pin = dbToStaPin(mod_bterm); + pin_name = name(below_pin); + visitor(below_pin); + // traverse along rest of net + Net* below_net = this->net(below_pin); + visitConnectedPins(below_net, visitor, visited_nets); + } + + // visit above nets + for (dbModBTerm* modbterm : mod_net->getModBTerms()) { + dbModule* db_module = modbterm->getParent(); + dbModInst* mod_inst = db_module->getModInst(); + std::string pin_name = modbterm->getName(); + dbModITerm* mod_iterm = mod_inst->findModITerm(pin_name.c_str()); + if (mod_iterm) { + Pin* above_pin = dbToSta(mod_iterm); + visitor(above_pin); + // traverse along rest of net + Net* above_net = this->net(above_pin); + visitConnectedPins(above_net, visitor, visited_nets); + } + } + } else if (db_net) { + for (dbITerm* iterm : db_net->getITerms()) { + Pin* pin = dbToSta(iterm); + visitor(pin); + } + for (dbBTerm* bterm : db_net->getBTerms()) { + Pin* pin = dbToSta(bterm); + visitor(pin); + } } } @@ -928,15 +1176,54 @@ ObjectId dbNetwork::id(const Term* term) const Pin* dbNetwork::pin(const Term* term) const { + // in original code + // Only terms are for top level instance pins, which are also BTerms. + // in new code: // Only terms are for top level instance pins, which are also BTerms. - return reinterpret_cast(const_cast(term)); + // return reinterpret_cast(const_cast(term)); + // terms now include modbterms. + // + dbBTerm* bterm = nullptr; + dbModBTerm* modbterm = nullptr; + dbITerm* iterm = nullptr; + dbModITerm* moditerm = nullptr; + staToDb(term, iterm, bterm, moditerm, modbterm); + if (bterm) { + return dbToSta(bterm); + } else if (modbterm) { + // get the moditerm + dbModule* cur_module = modbterm->getParent(); + dbModInst* cur_mod_inst = cur_module->getModInst(); + std::string pin_name = modbterm->getName(); + dbModITerm* parent_moditerm = cur_mod_inst->findModITerm(pin_name.c_str()); + if (parent_moditerm) { + return dbToSta(parent_moditerm); + } + } + return nullptr; } Net* dbNetwork::net(const Term* term) const { - dbBTerm* bterm = staToDb(term); - dbNet* dnet = bterm->getNet(); - return dbToSta(dnet); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + + staToDb(term, iterm, bterm, moditerm, modbterm); + + if (modbterm) { + return dbToSta(modbterm->getModNet()); + } + if (bterm) { + dbModNet* mod_net = bterm->getModNet(); + if (mod_net) + return dbToSta(mod_net); + dbNet* dnet = bterm->getNet(); + if (dnet) + return dbToSta(dnet); + } + return nullptr; } //////////////////////////////////////////////////////////////// @@ -1309,9 +1596,11 @@ Pin* dbNetwork::connect(Instance* inst, LibertyPort* port, Net* net) void dbNetwork::disconnectPin(Pin* pin) { - dbITerm* iterm; - dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbITerm* iterm = nullptr; + dbBTerm* bterm = nullptr; + dbModITerm* moditerm = nullptr; + dbModBTerm* modbterm = nullptr; + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { iterm->disconnect(); } else if (bterm) { @@ -1335,7 +1624,10 @@ void dbNetwork::deletePin(Pin* pin) { dbITerm* iterm; dbBTerm* bterm; - staToDb(pin, iterm, bterm); + dbModITerm* moditerm; + dbModBTerm* modbterm; + + staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm) { logger_->critical(ORD, 2003, "deletePin not implemented for dbITerm"); } @@ -1446,26 +1738,47 @@ dbNet* dbNetwork::staToDb(const Net* net) const return reinterpret_cast(const_cast(net)); } +void dbNetwork::staToDb(const Net* net, dbNet*& dnet, dbModNet*& modnet) const +{ + dnet = nullptr; + modnet = nullptr; + if (net) { + dbObject* obj = reinterpret_cast(const_cast(net)); + dbObjectType type = obj->getObjectType(); + if (type == odb::dbNetObj) { + dnet = static_cast(obj); + } else if (type == odb::dbModNetObj) { + modnet = static_cast(obj); + } + } +} + void dbNetwork::staToDb(const Pin* pin, // Return values. dbITerm*& iterm, - dbBTerm*& bterm) const -{ + dbBTerm*& bterm, + dbModITerm*& moditerm, + dbModBTerm*& modbterm) const +{ + iterm = nullptr; + bterm = nullptr; + modbterm = nullptr; + moditerm = nullptr; if (pin) { dbObject* obj = reinterpret_cast(const_cast(pin)); dbObjectType type = obj->getObjectType(); if (type == dbITermObj) { iterm = static_cast(obj); - bterm = nullptr; } else if (type == dbBTermObj) { - iterm = nullptr; bterm = static_cast(obj); + } else if (type == dbModBTermObj) { + modbterm = static_cast(obj); + } else if (type == dbModITermObj) { + moditerm = static_cast(obj); } else { - logger_->critical(ORD, 2006, "pin is not ITerm or BTerm"); + logger_->warn( + ORD, 2018, "pin is not ITerm or BTerm or modITerm or ModBTerm"); } - } else { - iterm = nullptr; - bterm = nullptr; } } @@ -1474,6 +1787,31 @@ dbBTerm* dbNetwork::staToDb(const Term* term) const return reinterpret_cast(const_cast(term)); } +void dbNetwork::staToDb(const Term* term, + dbITerm*& iterm, + dbBTerm*& bterm, + dbModITerm*& moditerm, + dbModBTerm*& modbterm) const +{ + iterm = nullptr; + bterm = nullptr; + moditerm = nullptr; + modbterm = nullptr; + if (term) { + dbObject* obj = reinterpret_cast(const_cast(term)); + dbObjectType type = obj->getObjectType(); + if (type == dbITermObj) { + iterm = static_cast(obj); + } else if (type == dbBTermObj) { + bterm = static_cast(obj); + } else if (type == dbModBTermObj) { + modbterm = static_cast(obj); + } else if (type == dbModITermObj) { + moditerm = static_cast(obj); + } + } +} + void dbNetwork::staToDb(const Cell* cell, dbMaster*& master, dbModule*& module) const @@ -1543,12 +1881,47 @@ void dbNetwork::staToDb(PortDirection* dir, //////////////////////////////////////////////////////////////// -Instance* dbNetwork::dbToSta(dbInst* inst) const +Instance* dbNetwork::dbToSta(dbModInst* inst) const { return reinterpret_cast(inst); } -Instance* dbNetwork::dbToSta(dbModInst* inst) const +Pin* dbNetwork::dbToSta(dbModITerm* mod_iterm) const +{ + return reinterpret_cast(mod_iterm); +} + +Pin* dbNetwork::dbToStaPin(dbModBTerm* mod_bterm) const +{ + return reinterpret_cast(mod_bterm); +} + +Net* dbNetwork::dbToSta(dbModNet* net) const +{ + return reinterpret_cast(net); +} + +Port* dbNetwork::dbToSta(dbModBTerm* modbterm) const +{ + return reinterpret_cast(modbterm->staPort()); +} + +Term* dbNetwork::dbToStaTerm(dbModITerm* moditerm) const +{ + return reinterpret_cast(moditerm); +} + +Term* dbNetwork::dbToStaTerm(dbModBTerm* modbterm) const +{ + return reinterpret_cast(modbterm); +} + +Cell* dbNetwork::dbToSta(dbModule* master) const +{ + return ((Cell*) (master->getStaCell())); +} + +Instance* dbNetwork::dbToSta(dbInst* inst) const { return reinterpret_cast(inst); } @@ -1588,11 +1961,6 @@ Cell* dbNetwork::dbToSta(dbMaster* master) const return reinterpret_cast(master->staCell()); } -Cell* dbNetwork::dbToSta(dbModule* master) const -{ - return ((Cell*) (master->getStaCell())); -} - PortDirection* dbNetwork::dbToSta(const dbSigType& sig_type, const dbIoType& io_type) const { diff --git a/src/dbSta/src/dbSta.i b/src/dbSta/src/dbSta.i index 8280fc1cb9c..ac239422103 100644 --- a/src/dbSta/src/dbSta.i +++ b/src/dbSta/src/dbSta.i @@ -103,7 +103,9 @@ sta_to_db_port(Port *port) Pin *pin = db_network->findPin(db_network->topInstance(), port); dbITerm *iterm; dbBTerm *bterm; - db_network->staToDb(pin, iterm, bterm); + dbModITerm *moditerm; + dbModBTerm *modbterm; + db_network->staToDb(pin, iterm, bterm, moditerm, modbterm); return bterm; } @@ -114,7 +116,9 @@ sta_to_db_pin(Pin *pin) sta::dbNetwork *db_network = openroad->getDbNetwork(); dbITerm *iterm; dbBTerm *bterm; - db_network->staToDb(pin, iterm, bterm); + dbModITerm *moditerm; + dbModBTerm* modbterm; + db_network->staToDb(pin, iterm, bterm, moditerm, modbterm); return iterm; } diff --git a/src/dbSta/test/hier2.ok b/src/dbSta/test/hier2.ok index c569949ce00..4df15c30bb4 100644 --- a/src/dbSta/test/hier2.ok +++ b/src/dbSta/test/hier2.ok @@ -1,5 +1,2 @@ -[INFO ODB-0222] Reading LEF file: example1.lef -[INFO ODB-0223] Created 2 technology layers -[INFO ODB-0225] Created 6 library cells -[INFO ODB-0226] Finished LEF file: example1.lef +[INFO ODB-0227] LEF file: example1.lef, created 2 layers, 6 library cells No differences found. diff --git a/src/dbSta/test/regression_tests.tcl b/src/dbSta/test/regression_tests.tcl index cd21593fdd6..7c2d5b165c0 100644 --- a/src/dbSta/test/regression_tests.tcl +++ b/src/dbSta/test/regression_tests.tcl @@ -1,4 +1,5 @@ record_tests { + hier2 readdb_hier constant1 make_port diff --git a/src/gui/src/chartsWidget.h b/src/gui/src/chartsWidget.h index 894d8c7e3a5..86f7efb5900 100644 --- a/src/gui/src/chartsWidget.h +++ b/src/gui/src/chartsWidget.h @@ -98,10 +98,7 @@ class ChartsWidget : public QDockWidget }; void setSTA(sta::dbSta* sta); - void setLogger(utl::Logger* logger) - { - logger_ = logger; - } + void setLogger(utl::Logger* logger) { logger_ = logger; } signals: void endPointsToReport(const std::set& report_pins); diff --git a/src/gui/src/clockWidget.cpp b/src/gui/src/clockWidget.cpp index a30ee59dcbb..4e87da2052f 100644 --- a/src/gui/src/clockWidget.cpp +++ b/src/gui/src/clockWidget.cpp @@ -101,7 +101,10 @@ void ClockTreeRenderer::drawObjects(Painter& painter) sta::Net* net = network->net(output_pin); odb::dbITerm* iterm; odb::dbBTerm* bterm; - network->staToDb(output_pin, iterm, bterm); + odb::dbModBTerm* modbterm; + odb::dbModITerm* moditerm; + + network->staToDb(output_pin, iterm, bterm, moditerm, modbterm); descriptor->highlight( DbNetDescriptor::NetWithSink{network->staToDb(net), iterm}, painter); } @@ -1129,7 +1132,10 @@ ClockNodeGraphicsViewItem* ClockTreeView::addRootToScene( { odb::dbITerm* iterm; odb::dbBTerm* bterm; - network->staToDb(output_pin.pin, iterm, bterm); + odb::dbModBTerm* modbterm; + odb::dbModITerm* moditerm; + + network->staToDb(output_pin.pin, iterm, bterm, moditerm, modbterm); ClockNodeGraphicsViewItem* node = nullptr; if (iterm != nullptr) { @@ -1153,7 +1159,10 @@ ClockNodeGraphicsViewItem* ClockTreeView::addLeafToScene( { odb::dbITerm* iterm; odb::dbBTerm* bterm; - network->staToDb(input_pin.pin, iterm, bterm); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + + network->staToDb(input_pin.pin, iterm, bterm, moditerm, modbterm); // distinguish between registers and macros ClockLeafNodeGraphicsViewItem* node; @@ -1214,7 +1223,9 @@ ClockNodeGraphicsViewItem* ClockTreeView::addCellToScene( auto convert_pin = [&network](const sta::Pin* pin) -> odb::dbITerm* { odb::dbITerm* iterm; odb::dbBTerm* bterm; - network->staToDb(pin, iterm, bterm); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + network->staToDb(pin, iterm, bterm, moditerm, modbterm); return iterm; }; diff --git a/src/gui/src/dbDescriptors.cpp b/src/gui/src/dbDescriptors.cpp index e0278142101..70a818a4ac3 100644 --- a/src/gui/src/dbDescriptors.cpp +++ b/src/gui/src/dbDescriptors.cpp @@ -1513,30 +1513,32 @@ Descriptor::Actions DbNetDescriptor::getActions(std::any object) const } if (!net->getSigType().isSupply()) { - actions.push_back({"Timing", [this, gui, net]() { - auto* network = sta_->getDbNetwork(); - auto* drivers - = network->drivers(network->dbToSta(net)); - - if (!drivers->empty()) { - std::set terms; - - for (auto* driver : *drivers) { - odb::dbITerm* iterm = nullptr; - odb::dbBTerm* bterm = nullptr; - - network->staToDb(driver, iterm, bterm); - if (iterm != nullptr) { - terms.insert(iterm); - } else { - terms.insert(bterm); - } - } - - gui->timingPathsThrough(terms); - } - return makeSelected(net); - }}); + actions.push_back( + {"Timing", [this, gui, net]() { + auto* network = sta_->getDbNetwork(); + auto* drivers = network->drivers(network->dbToSta(net)); + + if (!drivers->empty()) { + std::set terms; + + for (auto* driver : *drivers) { + odb::dbITerm* iterm = nullptr; + odb::dbBTerm* bterm = nullptr; + odb::dbModITerm* moditerm = nullptr; + odb::dbModBTerm* modbterm = nullptr; + + network->staToDb(driver, iterm, bterm, moditerm, modbterm); + if (iterm != nullptr) { + terms.insert(iterm); + } else { + terms.insert(bterm); + } + } + + gui->timingPathsThrough(terms); + } + return makeSelected(net); + }}); } if (!net->getGuides().empty()) { actions.push_back(Descriptor::Action{"Route Guides", [this, gui, net]() { diff --git a/src/gui/src/staGui.cpp b/src/gui/src/staGui.cpp index 9c5877aece5..fc421b47402 100644 --- a/src/gui/src/staGui.cpp +++ b/src/gui/src/staGui.cpp @@ -717,7 +717,9 @@ bool TimingConeRenderer::isSupplyPin(const sta::Pin* pin) const auto* network = sta_->getDbNetwork(); odb::dbITerm* iterm; odb::dbBTerm* bterm; - network->staToDb(pin, iterm, bterm); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + network->staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm != nullptr) { if (iterm->getSigType().isSupply()) { return true; @@ -1077,7 +1079,9 @@ void PinSetWidget::showMenu(const QPoint& point) auto* gui = Gui::get(); odb::dbITerm* iterm; odb::dbBTerm* bterm; - sta_->getDbNetwork()->staToDb(pin, iterm, bterm); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + sta_->getDbNetwork()->staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm != nullptr) { emit inspect(gui->makeSelected(iterm)); } else { diff --git a/src/gui/src/staGuiInterface.cpp b/src/gui/src/staGuiInterface.cpp index 7e1dd6a4385..55ab8d0fcb7 100644 --- a/src/gui/src/staGuiInterface.cpp +++ b/src/gui/src/staGuiInterface.cpp @@ -247,7 +247,9 @@ void TimingPath::populateNodeList(sta::Path* path, odb::dbITerm* term; odb::dbBTerm* port; - sta->getDbNetwork()->staToDb(pin, term, port); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + sta->getDbNetwork()->staToDb(pin, term, port, moditerm, modbterm); odb::dbObject* pin_object = term; if (term == nullptr) { pin_object = port; @@ -1105,7 +1107,9 @@ ConeDepthMap STAGuiInterface::buildConeConnectivity( odb::dbBTerm* bterm; odb::dbITerm* iterm; - network->staToDb(pin, iterm, bterm); + odb::dbModBTerm* modbterm; + odb::dbModITerm* moditerm; + network->staToDb(pin, iterm, bterm, moditerm, modbterm); if (bterm != nullptr) { dbpin = bterm; } else { diff --git a/src/rmp/src/Restructure.cpp b/src/rmp/src/Restructure.cpp index b2993552b86..6a2c462b76b 100644 --- a/src/rmp/src/Restructure.cpp +++ b/src/rmp/src/Restructure.cpp @@ -144,7 +144,9 @@ void Restructure::getBlob(unsigned max_depth) for (const sta::Pin* pin : boundary_points) { odb::dbITerm* term = nullptr; odb::dbBTerm* port = nullptr; - open_sta_->getDbNetwork()->staToDb(pin, term, port); + odb::dbModITerm* moditerm = nullptr; + odb::dbModBTerm* modbterm = nullptr; + open_sta_->getDbNetwork()->staToDb(pin, term, port, moditerm, modbterm); if (term && !term->getInst()->getMaster()->isBlock()) path_insts_.insert(term->getInst()); } diff --git a/src/rsz/src/Resizer.cc b/src/rsz/src/Resizer.cc index fb8be8b36df..0b6a0c9a347 100644 --- a/src/rsz/src/Resizer.cc +++ b/src/rsz/src/Resizer.cc @@ -639,7 +639,9 @@ bool Resizer::hasTristateOrDontTouchDriver(const Net* net) } odb::dbITerm* iterm; odb::dbBTerm* bterm; - db_network_->staToDb(pin, iterm, bterm); + odb::dbModITerm* moditerm; + odb::dbModBTerm* modbterm; + db_network_->staToDb(pin, iterm, bterm, moditerm, modbterm); if (iterm && iterm->getInst()->isDoNotTouch()) { logger_->warn(RSZ, 84,