Skip to content

Commit

Permalink
Cloning, first cut with tests
Browse files Browse the repository at this point in the history
Signed-off-by: andyfox-rushc <[email protected]>
  • Loading branch information
andyfox-rushc committed Nov 8, 2024
1 parent 56be17c commit 6dc4043
Show file tree
Hide file tree
Showing 20 changed files with 1,838 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/dbSta/include/db_sta/dbNetwork.hh
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ class dbNetwork : public ConcreteNetwork

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

void hierarchicalConnect(dbITerm* source_pin,
dbITerm* dest_pin,
Expand Down
48 changes: 41 additions & 7 deletions src/dbSta/src/dbNetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,6 @@ Port* dbNetwork::port(const Pin* pin) const
dbModITerm* moditerm;
dbModBTerm* modbterm;
Port* ret = nullptr;
static int debug;
debug++;
// Will return the bterm for a top level pin
staToDb(pin, iterm, bterm, moditerm, modbterm);

Expand Down Expand Up @@ -2891,6 +2889,7 @@ class PinModuleConnection : public PinVisitor
const Pin* drvr_pin_;
const dbModule* target_module_;
dbModBTerm* dest_modbterm_;
dbModITerm* dest_moditerm_;
friend class dbNetwork;
};

Expand All @@ -2902,6 +2901,7 @@ PinModuleConnection::PinModuleConnection(const dbNetwork* nwk,
drvr_pin_ = drvr_pin;
target_module_ = target_module;
dest_modbterm_ = nullptr;
dest_moditerm_ = nullptr;
}

void PinModuleConnection::operator()(const Pin* pin)
Expand All @@ -2910,6 +2910,7 @@ void PinModuleConnection::operator()(const Pin* pin)
dbBTerm* bterm;
dbModBTerm* modbterm;
dbModITerm* moditerm;

db_network_->staToDb(pin, iterm, bterm, moditerm, modbterm);
(void) (iterm);
(void) (bterm);
Expand All @@ -2920,18 +2921,32 @@ void PinModuleConnection::operator()(const Pin* pin)
dest_modbterm_ = modbterm;
}
}
else if (modbterm){
if (modbterm -> getParent() == target_module_){
dest_modbterm_ = modbterm;
}
dbModITerm* moditerm = modbterm -> getParentModITerm();
if (moditerm -> getParent() -> getParent() == target_module_){
dest_moditerm_ = moditerm;
}
}
}

bool dbNetwork::ConnectionToModuleExists(dbITerm* source_pin,
dbModule* dest_module,
dbModBTerm*& dest_modbterm)
dbModBTerm*& dest_modbterm,
dbModITerm*& dest_moditerm)
{
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;
}
if (visitor.dest_moditerm_ != nullptr) {
dest_moditerm = visitor.dest_moditerm_;
return true;
}
return false;
}

Expand All @@ -2949,7 +2964,8 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
// it is possible that one or other of the pins is not involved
// in hierarchy, which is ok, and the source/dest modnet will be null
dbModNet* source_db_mod_net = source_pin->getModNet();
dbModNet* dest_db_mod_net = dest_pin->getModNet();
dbModNet* dest_db_mod_net = dest_pin->getModNet(
);
// case 1: source/dest in same module
if (source_db_module == dest_db_module) {
if (!source_db_mod_net) {
Expand All @@ -2958,16 +2974,27 @@ 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();
//
dbModBTerm* dest_modbterm=nullptr;
dbModITerm* dest_moditerm=nullptr;
if (ConnectionToModuleExists(source_pin, dest_db_module, dest_modbterm, dest_moditerm)) {
dbModNet* dest_mod_net=nullptr;
if (dest_modbterm){
dest_mod_net = dest_modbterm->getModNet();
}
else if (dest_moditerm){
dest_mod_net = dest_moditerm->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 @@ -2987,6 +3014,10 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
= std::string(connection_name) + std::string("_o");
dbModBTerm* mod_bterm
= dbModBTerm::create(cur_module, connection_name_o.c_str());
if (!source_db_mod_net) {
source_db_mod_net = dbModNet::create(source_db_module, connection_name);
source_pin->connect(source_db_mod_net);
}
mod_bterm->connect(source_db_mod_net);
mod_bterm->setIoType(dbIoType::OUTPUT);
mod_bterm->setSigType(dbSigType::SIGNAL);
Expand All @@ -3000,6 +3031,8 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
mod_iterm->connect(source_db_mod_net);
top_net = source_db_mod_net;
}


// make dest hierarchy
cur_module = dest_db_module;
while (cur_module != highest_common_module) {
Expand All @@ -3024,6 +3057,7 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
dbModITerm* mod_iterm
= dbModITerm::create(parent_inst, connection_name_i.c_str());
mod_iterm->setChildModBTerm(mod_bterm);
mod_bterm->setParentModITerm(mod_iterm);
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
2 changes: 2 additions & 0 deletions src/odb/include/odb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -8082,6 +8082,7 @@ class dbModBTerm : public dbObject
dbBusPort* getBusPort() const;
static dbModBTerm* create(dbModule* parentModule, const char* name);
static void destroy(dbModBTerm*);
static dbModBTerm* getModBTerm(dbBlock* block, uint dbid);

private:
// User Code End dbModBTerm
Expand Down Expand Up @@ -8137,6 +8138,7 @@ class dbModITerm : public dbObject
void disconnect();
static dbModITerm* create(dbModInst* parentInstance, const char* name);
static void destroy(dbModITerm*);
static dbModITerm* getModITerm(dbBlock* block, uint dbid);
// User Code End dbModITerm
};

Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/codeGenerator/schema/chip/dbModBterm.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@
}
],
"constructors":[],
"cpp_includes":["dbBlock.h","dbModule.h","dbModNet.h","dbHashTable.hpp","dbModITerm.h","dbBusPort.h"]
"cpp_includes":["dbBlock.h","dbModule.h","dbModNet.h","dbHashTable.hpp","dbModITerm.h","dbBusPort.h","dbJournal.h"]
}
2 changes: 1 addition & 1 deletion src/odb/src/codeGenerator/schema/chip/dbModIterm.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@

],
"constructors":[],
"cpp_includes":["dbBlock.h","dbModInst.h","dbModNet.h","dbHashTable.hpp","dbModBTerm.h"]
"cpp_includes":["dbBlock.h","dbModInst.h","dbModNet.h","dbHashTable.hpp","dbModBTerm.h", "dbJournal.h"]
}
60 changes: 50 additions & 10 deletions src/odb/src/db/dbJournal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,14 +1490,16 @@ void dbJournal::undo_createObject()
auto obj_type = popObjectType();

switch (obj_type) {
case dbGuideObj: {


case dbGuideObj: {
uint guide_id;
_log.pop(guide_id);
dbGuide* guide = dbGuide::getGuide(_block, guide_id);
dbGuide::destroy(guide);
break;
}
case dbInstObj: {
case dbInstObj: {
uint lib_id;
uint master_id;
uint inst_id;
Expand All @@ -1521,13 +1523,29 @@ void dbJournal::undo_createObject()
break;
}

default: {
_logger->critical(utl::ODB,
441,
"No undo_createObject support for type {}",
dbObject::getTypeName(obj_type));
break;
}
case dbModBTermObj:{
uint modbterm_id;
_log.pop(modbterm_id);
dbModBTerm* modbterm = dbModBTerm::getModBTerm(_block,modbterm_id);
dbModBTerm::destroy(modbterm);
break;
}

case dbModITermObj:{
uint moditerm_id;
_log.pop(moditerm_id);
dbModITerm* moditerm = dbModITerm::getModITerm(_block,moditerm_id);
dbModITerm::destroy(moditerm);
break;
}

default: {
_logger->critical(utl::ODB,
441,
"No undo_createObject support for type {}",
dbObject::getTypeName(obj_type));
break;
}
}
}

Expand Down Expand Up @@ -1628,7 +1646,29 @@ void dbJournal::undo_connectObject()
auto obj_type = popObjectType();

switch (obj_type) {
case dbITermObj: {

case dbModITermObj:{
uint moditerm_id;
_log.pop(moditerm_id);
dbModITerm* moditerm = dbModITerm::getModITerm(_block, moditerm_id);
uint net_id;
_log.pop(net_id);
moditerm->disconnect();
break;
}

case dbModBTermObj:{
uint modbterm_id;
_log.pop(modbterm_id);
dbModBTerm* modbterm = dbModBTerm::getModBTerm(_block, modbterm_id);
uint net_id;
_log.pop(net_id);
modbterm->disconnect();
break;
}


case dbITermObj: {
uint iterm_id;
_log.pop(iterm_id);
dbITerm* iterm = dbITerm::getITerm(_block, iterm_id);
Expand Down
25 changes: 25 additions & 0 deletions src/odb/src/db/dbModBTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "dbDatabase.h"
#include "dbDiff.hpp"
#include "dbHashTable.hpp"
#include "dbJournal.h"
#include "dbModITerm.h"
#include "dbModNet.h"
#include "dbModule.h"
Expand Down Expand Up @@ -365,6 +366,14 @@ dbModBTerm* dbModBTerm::create(dbModule* parentModule, const char* name)
}
module->_modbterms = modbterm->getOID();
module->_modbterm_hash[name] = dbId<_dbModBTerm>(modbterm->getOID());

if (block->_journal) {
block->_journal->beginAction(dbJournal::CREATE_OBJECT);
block->_journal->pushParam(dbModBTermObj);
block->_journal->pushParam(modbterm->getId());
block->_journal->endAction();
}

return (dbModBTerm*) modbterm;
}

Expand All @@ -391,6 +400,15 @@ void dbModBTerm::connect(dbModNet* net)
}
_modbterm->_prev_net_modbterm = 0; // previous of head always zero
_modnet->_modbterms = getId(); // set new head

if (_block -> _journal){
_block->_journal->beginAction(dbJournal::CONNECT_OBJECT);
_block->_journal->pushParam(dbModBTermObj);
_block->_journal->pushParam(getId());
_block->_journal->pushParam(net->getId());
_block->_journal->endAction();
}

}

void dbModBTerm::disconnect()
Expand Down Expand Up @@ -448,8 +466,15 @@ void dbModBTerm::setBusPort(dbBusPort* bus_port)
_modbterm->_busPort = bus_port->getId();
}

dbModBTerm* dbModBTerm::getModBTerm(dbBlock* block, uint dbid)
{
_dbBlock* owner = (_dbBlock*) block;
return (dbModBTerm*) (owner->_modbterm_tbl->getPtr(dbid));
}

void dbModBTerm::destroy(dbModBTerm* val)
{
printf("Destroying mod bterm %d\n", val -> getId());
_dbModBTerm* _modbterm = (_dbModBTerm*) val;
_dbBlock* block = (_dbBlock*) (_modbterm->getOwner());
_dbModule* module = block->_module_tbl->getPtr(_modbterm->_parent);
Expand Down
28 changes: 28 additions & 0 deletions src/odb/src/db/dbModITerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "dbDatabase.h"
#include "dbDiff.hpp"
#include "dbHashTable.hpp"
#include "dbJournal.h"
#include "dbModBTerm.h"
#include "dbModInst.h"
#include "dbModNet.h"
Expand Down Expand Up @@ -282,6 +283,14 @@ dbModITerm* dbModITerm::create(dbModInst* parentInstance, const char* name)
}
parent->_moditerms = moditerm->getOID();
parent->_moditerm_hash[name] = dbId<_dbModITerm>(moditerm->getOID());

if (block->_journal) {
block->_journal->beginAction(dbJournal::CREATE_OBJECT);
block->_journal->pushParam(dbModITermObj);
block->_journal->pushParam(moditerm->getId());
block->_journal->endAction();
}

return (dbModITerm*) moditerm;
}

Expand All @@ -307,6 +316,15 @@ void dbModITerm::connect(dbModNet* net)
// set up new head
_moditerm->_prev_net_moditerm = 0;
_modnet->_moditerms = getId();

if (_block -> _journal){
_block->_journal->beginAction(dbJournal::CONNECT_OBJECT);
_block->_journal->pushParam(dbModITermObj);
_block->_journal->pushParam(getId());
_block->_journal->pushParam(_modnet->getId());
_block->_journal->endAction();
}

}

void dbModITerm::disconnect()
Expand Down Expand Up @@ -336,8 +354,18 @@ void dbModITerm::disconnect()
}
}

dbModITerm* dbModITerm::getModITerm(dbBlock* block, uint dbid)
{
_dbBlock* owner = (_dbBlock*) block;
return (dbModITerm*) (owner->_moditerm_tbl->getPtr(dbid));
}

void dbModITerm::destroy(dbModITerm* val)
{
printf("Destroying mod iterm %d\n", val -> getId());
printf("Which is connected to net %s\n",val -> getModNet() ?
val -> getModNet() -> getName():
"empty");
_dbModITerm* _moditerm = (_dbModITerm*) val;
_dbBlock* block = (_dbBlock*) _moditerm->getOwner();

Expand Down
1 change: 1 addition & 0 deletions src/odb/src/db/dbModuleBusPortModBTermItr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "dbBusPort.h"
#include "dbModBTerm.h"
#include "dbModBTerm.h"
#include "dbModule.h"
#include "dbTable.h"

Expand Down
1 change: 1 addition & 0 deletions src/odb/src/db/dbModuleModBTermItr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "dbBusPort.h"
#include "dbModBTerm.h"
#include "dbModBTerm.h"
#include "dbModule.h"
#include "dbTable.h"

Expand Down
Loading

0 comments on commit 6dc4043

Please sign in to comment.