Skip to content

Commit

Permalink
Merge pull request The-OpenROAD-Project#6048 from andyfox-rushc/repai…
Browse files Browse the repository at this point in the history
…r_setup4_hier_case_1_buffer

Repair setup4 hier case 1 buffer
  • Loading branch information
maliberty authored Nov 4, 2024
2 parents a15114a + 2f68b67 commit 71eabf5
Show file tree
Hide file tree
Showing 29 changed files with 1,233 additions and 67 deletions.
10 changes: 10 additions & 0 deletions src/dbSta/include/db_sta/dbNetwork.hh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ class dbNetwork : public ConcreteNetwork
dbModule* getNetDriverParentModule(Net* net);
Instance* getOwningInstanceParent(Pin* pin);

bool ConnectionToModuleExists(dbITerm* source_pin,
dbModule* dest_module,
dbModBTerm*& dest_modbterm);

void hierarchicalConnect(dbITerm* source_pin,
dbITerm* dest_pin,
const char* connection_name);
Expand Down Expand Up @@ -235,6 +239,11 @@ class dbNetwork : public ConcreteNetwork
Instance* instance(const Pin* pin) const override;
Net* net(const Pin* pin) const override;
void net(const Pin* pin, dbNet*& db_net, dbModNet*& db_modnet) const;
dbNet* flatNet(const Pin* pin) const;
dbModNet* hierNet(const Pin* pin) const;
dbITerm* flatPin(const Pin* pin) const;
dbModITerm* hierPin(const Pin* pin) const;

Term* term(const Pin* pin) const override;
PortDirection* direction(const Pin* pin) const override;
VertexId vertexId(const Pin* pin) const override;
Expand Down Expand Up @@ -284,6 +293,7 @@ class dbNetwork : public ConcreteNetwork
NetTermIterator* termIterator(const Net* net) const override;
const Net* highestConnectedNet(Net* net) const override;
bool isSpecial(Net* net);
dbNet* flatNet(const Net* net) const;

////////////////////////////////////////////////////////////////
// Edit functions
Expand Down
139 changes: 128 additions & 11 deletions src/dbSta/src/dbNetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,26 @@ Net* dbNetwork::net(const Pin* pin) const
return nullptr;
}

/*
Get the db net (flat net) for the pin
*/

dbNet* dbNetwork::flatNet(const Pin* pin) const
{
dbNet* db_net;
dbModNet* db_modnet;
net(pin, db_net, db_modnet);
return db_net;
}

dbModNet* dbNetwork::hierNet(const Pin* pin) const
{
dbNet* db_net;
dbModNet* db_modnet;
net(pin, db_net, db_modnet);
return db_modnet;
}

/*
Get the dbnet or the moddbnet for a pin
Sometimes a pin can be hooked to both and we want to expose them
Expand Down Expand Up @@ -1234,16 +1254,7 @@ Term* dbNetwork::term(const Pin* pin) const
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);
dbModBTerm* mod_port = moditerm->getChildModBTerm();
if (mod_port) {
Term* ret = dbToStaTerm(mod_port);
return ret;
Expand Down Expand Up @@ -2193,6 +2204,18 @@ dbNet* dbNetwork::staToDb(const Net* net) const
return reinterpret_cast<dbNet*>(const_cast<Net*>(net));
}

dbNet* dbNetwork::flatNet(const Net* net) const
{
if (net) {
dbObject* obj = reinterpret_cast<dbObject*>(const_cast<Net*>(net));
dbObjectType type = obj->getObjectType();
if (type == odb::dbNetObj) {
return static_cast<dbNet*>(obj);
}
}
return nullptr;
}

void dbNetwork::staToDb(const Net* net, dbNet*& dnet, dbModNet*& modnet) const
{
dnet = nullptr;
Expand All @@ -2208,12 +2231,37 @@ void dbNetwork::staToDb(const Net* net, dbNet*& dnet, dbModNet*& modnet) const
}
}

dbITerm* dbNetwork::flatPin(const Pin* pin) const
{
odb::dbITerm* iterm;
odb::dbBTerm* bterm;
odb::dbModITerm* moditerm;
odb::dbModBTerm* modbterm;
staToDb(pin, iterm, bterm, moditerm, modbterm);
(void) bterm;
(void) moditerm;
(void) modbterm;
return iterm;
}

dbModITerm* dbNetwork::hierPin(const Pin* pin) const
{
odb::dbITerm* iterm;
odb::dbBTerm* bterm;
odb::dbModITerm* moditerm;
odb::dbModBTerm* modbterm;
staToDb(pin, iterm, bterm, moditerm, modbterm);
(void) iterm;
(void) bterm;
(void) modbterm;
return moditerm;
}

void dbNetwork::staToDb(const Pin* pin,
// Return values.
dbITerm*& iterm,
dbBTerm*& bterm,
dbModITerm*& moditerm,
// axiom never see a modbterm...
dbModBTerm*& modbterm) const
{
iterm = nullptr;
Expand Down Expand Up @@ -2814,6 +2862,63 @@ dbModule* dbNetwork::findHighestCommonModule(std::vector<dbModule*>& itree1,
return common_module; // default to top
}

class PinModuleConnection : public PinVisitor
{
public:
PinModuleConnection(const dbNetwork* nwk,
const Pin* drvr_pin,
const dbModule* target_module_);
void operator()(const Pin* pin) override;

protected:
const dbNetwork* db_network_;
const Pin* drvr_pin_;
const dbModule* target_module_;
dbModBTerm* dest_modbterm_;
friend class dbNetwork;
};

PinModuleConnection::PinModuleConnection(const dbNetwork* nwk,
const Pin* drvr_pin,
const dbModule* target_module)
{
db_network_ = nwk;
drvr_pin_ = drvr_pin;
target_module_ = target_module;
dest_modbterm_ = nullptr;
}

void PinModuleConnection::operator()(const Pin* pin)
{
dbITerm* iterm;
dbBTerm* bterm;
dbModBTerm* modbterm;
dbModITerm* moditerm;
db_network_->staToDb(pin, iterm, bterm, moditerm, modbterm);
(void) (iterm);
(void) (bterm);
(void) (modbterm);
if (moditerm) {
dbModBTerm* modbterm = moditerm->getChildModBTerm();
if (modbterm->getParent() == target_module_) {
dest_modbterm_ = modbterm;
}
}
}

bool dbNetwork::ConnectionToModuleExists(dbITerm* source_pin,
dbModule* dest_module,
dbModBTerm*& dest_modbterm)
{
PinModuleConnection visitor(this, dbToSta(source_pin), dest_module);
network_->visitConnectedPins(dbToSta(source_pin), visitor);
if (visitor.dest_modbterm_ != nullptr) {
dest_modbterm = visitor.dest_modbterm_;
return true;
}
return false;
}

/*
Connect any two leaf instance pins anywhere in hierarchy
adding pins/nets/ports on the hierarchical objects
Expand All @@ -2837,6 +2942,16 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
}
dest_pin->connect(source_db_mod_net);
} else {
// Attempt to factor connection (minimize punch through)
dbModBTerm* dest_modbterm;
if (ConnectionToModuleExists(source_pin, dest_db_module, dest_modbterm)) {
dbModNet* dest_mod_net = dest_modbterm->getModNet();
if (dest_mod_net) {
dest_pin->connect(dest_mod_net);
return;
}
}

// case 2: source/dest in different modules. Find highest
// common module, traverse up adding pins/nets and make
// connection in highest common module
Expand All @@ -2863,6 +2978,7 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
cur_module = parent_inst->getParent();
dbModITerm* mod_iterm
= dbModITerm::create(parent_inst, connection_name_o.c_str());
mod_iterm->setChildModBTerm(mod_bterm);
source_db_mod_net = dbModNet::create(cur_module, connection_name);
mod_iterm->connect(source_db_mod_net);
top_net = source_db_mod_net;
Expand Down Expand Up @@ -2890,6 +3006,7 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
cur_module = parent_inst->getParent();
dbModITerm* mod_iterm
= dbModITerm::create(parent_inst, connection_name_i.c_str());
mod_iterm->setChildModBTerm(mod_bterm);
if (cur_module != highest_common_module) {
dest_db_mod_net = dbModNet::create(cur_module, connection_name);
mod_iterm->connect(dest_db_mod_net);
Expand Down
24 changes: 21 additions & 3 deletions src/dbSta/src/dbReadVerilog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,20 +430,38 @@ void Verilog2db::makeDbModule(
}
}
module->getModBTerms().reverse();
// make the instance iterms

// make the instance iterms and set up their reference
// to the child ports (dbModBTerms).

InstancePinIterator* ip_iter = network_->pinIterator(inst);
while (ip_iter->hasNext()) {
Pin* cur_pin = ip_iter->next();
std::string pin_name_string = network_->portName(cur_pin);
//
// we do not need to store the pin names.. But they are
// assumed to exist in the STA world.
//
dbModITerm* moditerm
= dbModITerm::create(modinst, pin_name_string.c_str());
dbModBTerm* modbterm;
std::string port_name_str = pin_name_string;
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);
}
dbModule* module = modinst->getMaster();
modbterm = module->findModBTerm(port_name_str.c_str());
moditerm->setChildModBTerm(modbterm);

(void) moditerm;
debugPrint(logger_,
utl::ODB,
"dbReadVerilog",
1,
"Created module iterm {} ",
moditerm->getName());
"Created module iterm {} for bterm {}",
moditerm->getName(),
modbterm->getName());
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/dbSta/test/readdb_hier.ok
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
[DEBUG ODB-dbReadVerilog] Created module bterm in
[DEBUG ODB-dbReadVerilog] Created module bterm clk
[DEBUG ODB-dbReadVerilog] Created module bterm out
[DEBUG ODB-dbReadVerilog] Created module iterm in
[DEBUG ODB-dbReadVerilog] Created module iterm clk
[DEBUG ODB-dbReadVerilog] Created module iterm out
[DEBUG ODB-dbReadVerilog] Created module iterm in for bterm in
[DEBUG ODB-dbReadVerilog] Created module iterm clk for bterm clk
[DEBUG ODB-dbReadVerilog] Created module iterm out for bterm out
[DEBUG ODB-dbReadVerilog] Created module instance b2 in parent top
[DEBUG ODB-dbReadVerilog] Created module bterm in
[DEBUG ODB-dbReadVerilog] Created module bterm clk
[DEBUG ODB-dbReadVerilog] Created module bterm out
[DEBUG ODB-dbReadVerilog] Created module iterm in
[DEBUG ODB-dbReadVerilog] Created module iterm clk
[DEBUG ODB-dbReadVerilog] Created module iterm out
[DEBUG ODB-dbReadVerilog] Created module iterm in for bterm in
[DEBUG ODB-dbReadVerilog] Created module iterm clk for bterm clk
[DEBUG ODB-dbReadVerilog] Created module iterm out for bterm out
3 changes: 3 additions & 0 deletions src/odb/include/odb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -8152,8 +8152,11 @@ class dbModNet : public dbObject
dbSet<dbBTerm> getBTerms();

const char* getName() const;
void rename(const char* new_name);
static dbModNet* getModNet(dbBlock* block, uint id);
static dbModNet* create(dbModule* parentModule, const char* name);
static void destroy(dbModNet*);

// User Code End dbModNet
};

Expand Down
40 changes: 39 additions & 1 deletion src/odb/src/db/dbITerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ void dbITerm::connect(dbNet* net_)
block->_journal->pushParam(dbITermObj);
block->_journal->pushParam(getId());
block->_journal->pushParam(net_->getId());
// put in a fake modnet here
block->_journal->pushParam(0);
block->_journal->endAction();
}

Expand Down Expand Up @@ -500,6 +502,22 @@ void dbITerm::connect(dbModNet* mod_net)
inst->_name);
}

if (block->_journal) {
debugPrint(iterm->getImpl()->getLogger(),
utl::ODB,
"DB_ECO",
1,
"ECO: connect Iterm {} to modnet {}",
getId(),
_mod_net->getId());
block->_journal->beginAction(dbJournal::CONNECT_OBJECT);
block->_journal->pushParam(dbITermObj);
block->_journal->pushParam(getId());
block->_journal->pushParam(0);
block->_journal->pushParam(_mod_net->getId());
block->_journal->endAction();
}

if (_mod_net->_iterms != 0) {
_dbITerm* head = block->_iterm_tbl->getPtr(_mod_net->_iterms);
iterm->_next_modnet_iterm = _mod_net->_iterms;
Expand Down Expand Up @@ -552,7 +570,6 @@ void dbITerm::disconnect()
block->_journal->pushParam(dbITermObj);
block->_journal->pushParam(getId());
block->_journal->pushParam(net->getOID());
block->_journal->endAction();
}

uint id = iterm->getOID();
Expand Down Expand Up @@ -580,9 +597,30 @@ void dbITerm::disconnect()

// the modnet part
if (iterm->_mnet == 0) {
if (block->_journal) {
debugPrint(iterm->getImpl()->getLogger(),
utl::ODB,
"DB_ECO",
1,
"ECO: disconnect modnet from Iterm {}",
getId());
block->_journal->pushParam(0);
block->_journal->endAction();
}
return;
}

_dbModNet* mod_net = block->_modnet_tbl->getPtr(iterm->_mnet);
if (block->_journal) {
debugPrint(iterm->getImpl()->getLogger(),
utl::ODB,
"DB_ECO",
1,
"ECO: disconnect Iterm -- modnet part {}",
getId());
block->_journal->pushParam(mod_net->getOID());
block->_journal->endAction();
}

if (mod_net->_iterms == id) {
mod_net->_iterms = iterm->_next_modnet_iterm;
Expand Down
Loading

0 comments on commit 71eabf5

Please sign in to comment.