Skip to content

Commit

Permalink
Removal of unused ports after hierarchical cts. Fixes for hierarchy s…
Browse files Browse the repository at this point in the history
…earch (top down). Signed-off-by: Andy Fox [email protected]

Signed-off-by: andyfox-rushc <[email protected]>
  • Loading branch information
andyfox-rushc committed Sep 6, 2024
1 parent d941af4 commit f04933b
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 114 deletions.
1 change: 1 addition & 0 deletions src/cts/src/TritonCTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,7 @@ void TritonCTS::writeClockNetsToDb(Clock& clockNet,
std::set<odb::dbNet*>& clkLeafNets)
{
odb::dbNet* topClockNet = clockNet.getNetObj();
// gets the module for the driver for the net
odb::dbModule* top_module = network_->getParentModule(topClockNet);

const std::string topRegBufferName = "clkbuf_regs_0_" + clockNet.getSdcName();
Expand Down
56 changes: 16 additions & 40 deletions src/cts/test/simple_test_hier_out.vok
Original file line number Diff line number Diff line change
Expand Up @@ -10,110 +10,86 @@ module test_16_sinks (clk);
CLKBUF_X3 clkbuf_0_clk (.A(clk),
.Z(clknet_0_clk));
flop_pair U1 (.clknet_1_1__leaf_clk_i(clknet_1_1__leaf_clk),
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
flop_pair-1 U2 (.clknet_1_1__leaf_clk_i(clknet_1_1__leaf_clk),
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
flop_pair-2 U3 (.clknet_1_1__leaf_clk_i(clknet_1_1__leaf_clk),
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
flop_pair-3 U4 (.clknet_1_1__leaf_clk_i(clknet_1_1__leaf_clk),
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
flop_pair-4 U5 (.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
flop_pair-4 U5 (.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
flop_pair-5 U6 (.clknet_1_1__leaf_clk_i(clknet_1_1__leaf_clk),
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
flop_pair-6 U7 (.clknet_1_1__leaf_clk_i(clknet_1_1__leaf_clk),
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
flop_pair-7 U8 (.clknet_1_1__leaf_clk_i(clknet_1_1__leaf_clk),
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk),
.origclk(clk));
.clknet_1_0__leaf_clk_i(clknet_1_0__leaf_clk));
endmodule
module flop_pair (clknet_1_1__leaf_clk_i,
clknet_1_0__leaf_clk_i,
origclk);
clknet_1_0__leaf_clk_i);
input clknet_1_1__leaf_clk_i;
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U1/ff1 (.CK(clknet_1_1__leaf_clk_i));
DFF_X1 \U1/ff2 (.CK(clknet_1_0__leaf_clk_i));
endmodule
module flop_pair-1 (clknet_1_1__leaf_clk_i,
clknet_1_0__leaf_clk_i,
origclk);
clknet_1_0__leaf_clk_i);
input clknet_1_1__leaf_clk_i;
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U2/ff1 (.CK(clknet_1_1__leaf_clk_i));
DFF_X1 \U2/ff2 (.CK(clknet_1_0__leaf_clk_i));
endmodule
module flop_pair-2 (clknet_1_1__leaf_clk_i,
clknet_1_0__leaf_clk_i,
origclk);
clknet_1_0__leaf_clk_i);
input clknet_1_1__leaf_clk_i;
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U3/ff1 (.CK(clknet_1_1__leaf_clk_i));
DFF_X1 \U3/ff2 (.CK(clknet_1_0__leaf_clk_i));
endmodule
module flop_pair-3 (clknet_1_1__leaf_clk_i,
clknet_1_0__leaf_clk_i,
origclk);
clknet_1_0__leaf_clk_i);
input clknet_1_1__leaf_clk_i;
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U4/ff1 (.CK(clknet_1_0__leaf_clk_i));
DFF_X1 \U4/ff2 (.CK(clknet_1_1__leaf_clk_i));
endmodule
module flop_pair-4 (clknet_1_0__leaf_clk_i,
origclk);
module flop_pair-4 (clknet_1_0__leaf_clk_i);
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U5/ff1 (.CK(clknet_1_0__leaf_clk_i));
DFF_X1 \U5/ff2 (.CK(clknet_1_0__leaf_clk_i));
endmodule
module flop_pair-5 (clknet_1_1__leaf_clk_i,
clknet_1_0__leaf_clk_i,
origclk);
clknet_1_0__leaf_clk_i);
input clknet_1_1__leaf_clk_i;
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U6/ff1 (.CK(clknet_1_1__leaf_clk_i));
DFF_X1 \U6/ff2 (.CK(clknet_1_0__leaf_clk_i));
endmodule
module flop_pair-6 (clknet_1_1__leaf_clk_i,
clknet_1_0__leaf_clk_i,
origclk);
clknet_1_0__leaf_clk_i);
input clknet_1_1__leaf_clk_i;
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U7/ff1 (.CK(clknet_1_0__leaf_clk_i));
DFF_X1 \U7/ff2 (.CK(clknet_1_1__leaf_clk_i));
endmodule
module flop_pair-7 (clknet_1_1__leaf_clk_i,
clknet_1_0__leaf_clk_i,
origclk);
clknet_1_0__leaf_clk_i);
input clknet_1_1__leaf_clk_i;
input clknet_1_0__leaf_clk_i;
input origclk;


DFF_X1 \U8/ff1 (.CK(clknet_1_1__leaf_clk_i));
Expand Down
5 changes: 3 additions & 2 deletions src/dbSta/include/db_sta/dbNetwork.hh
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ class dbNetwork : public ConcreteNetwork
void hierarchicalConnect(dbITerm* source_pin,
dbITerm* dest_pin,
const char* connection_name);
void getInstanceTree(dbModule* start_module,
std::vector<dbModule*>& instance_tree);

void getParentHierarchy(dbModule* start_module,
std::vector<dbModule*>& parent_hierarchy);
dbModule* findHighestCommonModule(std::vector<dbModule*>& itree1,
std::vector<dbModule*>& itree2);

Expand Down
124 changes: 56 additions & 68 deletions src/dbSta/src/dbNetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1351,50 +1351,6 @@ NetTermIterator* dbNetwork::termIterator(const Net* net) const
return new DbNetTermIterator(net, this);
}

class AccumulatePins : public PinVisitor
{
public:
AccumulatePins(const sta::Network* network) { network_ = network; }
virtual void operator()(const sta::Pin* pin)
{
accumulated_pins_.insert(pin);
}
std::set<const sta::Pin*> accumulated_pins_;
const sta::Network* network_;
};

/* find equivalent modnet for a dbnet */
dbModNet* dbNetwork::getDbModNetFromDbNet(dbNet* db_net)
{
NetSet visited_nets;
AccumulatePins visitor(this);
sta::Net* cur_net = dbToSta(db_net);
visitConnectedPins(cur_net, visitor, visited_nets);
for (auto pin : visitor.accumulated_pins_) {
dbITerm* iterm = nullptr;
dbBTerm* bterm = nullptr;
dbModITerm* moditerm = nullptr;
dbModBTerm* modbterm = nullptr;

staToDb(pin, iterm, bterm, moditerm, modbterm);
if (iterm) {
dbModNet* mnet = iterm->getModNet();
if (mnet) {
return mnet;
}
}
if (moditerm) {
dbModNet* mnet = moditerm->getModNet();
return mnet;
}
if (bterm) {
dbModNet* mnet = bterm->getModNet();
return mnet;
}
}
return nullptr;
}

// override ConcreteNetwork::visitConnectedPins

void dbNetwork::visitConnectedPins(const Net* net,
Expand Down Expand Up @@ -2629,13 +2585,13 @@ dbModule* dbNetwork::getParentModule(dbNet* net)
return nullptr;
}

void dbNetwork::getInstanceTree(dbModule* start_module,
std::vector<dbModule*>& instance_tree)
void dbNetwork::getParentHierarchy(dbModule* start_module,
std::vector<dbModule*>& parent_hierarchy)
{
dbModule* top_module = block_->getTopModule();
dbModule* cur_module = start_module;
while (cur_module) {
instance_tree.push_back(cur_module);
parent_hierarchy.push_back(cur_module);
if (cur_module == top_module)
return;
cur_module = start_module->getModInst()->getParent();
Expand All @@ -2645,19 +2601,38 @@ void dbNetwork::getInstanceTree(dbModule* start_module,
dbModule* dbNetwork::findHighestCommonModule(std::vector<dbModule*>& itree1,
std::vector<dbModule*>& itree2)
{
// order lowest to highest (push_back in getInstanceTree)
for (auto i : itree1) {
for (auto j : itree2) {
if (i == j)
return i;
int ix1 = itree1.size();
int ix2 = itree2.size();
int limit = std::min(ix1, ix2);
dbModule* top_module = block_->getTopModule();

// reverse traversal. (note hierarchy stored so top is end of list)
// get to first divergence
std::vector<dbModule*>::reverse_iterator itree1_iter = itree1.rbegin();
std::vector<dbModule*>::reverse_iterator itree2_iter = itree2.rbegin();
dbModule* common_module = top_module;
if (limit > 0) {
for (int i = 0; i != limit; i++) {
if (*itree1_iter != *itree2_iter) {
return common_module;
} else {
common_module = *itree1_iter;
}
itree1_iter++;
itree2_iter++;
}
}
return nullptr;
return common_module; // default to top
}

/*
Connect any two leaf instance pins anywhere in hierarchy
adding pins/nets/ports on the hierarchical objects
*/
void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
dbITerm* dest_pin,
const char* connection_name)

{
dbModule* source_db_module = source_pin->getInst()->getModule();
dbModule* dest_db_module = dest_pin->getInst()->getModule();
Expand All @@ -2678,24 +2653,16 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
// case 2: source/dest in different modules. Find highest
// common module, traverse up adding pins/nets and make
// connection in highest common module
std::vector<dbModule*> source_instance_tree;
std::vector<dbModule*> dest_instance_tree;
getInstanceTree(source_db_module, source_instance_tree);
getInstanceTree(dest_db_module, dest_instance_tree);
dbModule* highest_common_module = nullptr;
// arrange so first argument to findHighestCommonModule has deepest
// hierarchy.
if (source_instance_tree.size() > dest_instance_tree.size()) {
highest_common_module
= findHighestCommonModule(source_instance_tree, dest_instance_tree);
} else {
highest_common_module
= findHighestCommonModule(dest_instance_tree, source_instance_tree);
}
std::vector<dbModule*> source_parent_tree;
std::vector<dbModule*> dest_parent_tree;
getParentHierarchy(source_db_module, source_parent_tree);
getParentHierarchy(dest_db_module, dest_parent_tree);
dbModule* highest_common_module
= findHighestCommonModule(source_parent_tree, dest_parent_tree);
dbModNet* top_net = source_db_mod_net;
dbModITerm* top_mod_dest = nullptr;

// make source hierarchy
// make source hierarchy (bottom to top).
dbModule* cur_module = source_db_module;
while (cur_module != highest_common_module) {
std::string connection_name_o
Expand Down Expand Up @@ -2740,6 +2707,7 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
dest_db_mod_net = dbModNet::create(cur_module, connection_name);
mod_iterm->connect(dest_db_mod_net);
}

// save the top level destination pin for final connection
top_mod_dest = mod_iterm;
}
Expand All @@ -2759,6 +2727,26 @@ void dbNetwork::hierarchicalConnect(dbITerm* source_pin,
} else {
dest_pin->connect(top_net);
}

// During the addition of new ports and new wiring we may
// leave orphaned pins, clean them up.
std::set<dbModInst*> cleaned_up;
for (auto module_to_clean_up : source_parent_tree) {
dbModInst* mi = module_to_clean_up->getModInst();
if (mi) {
mi->RemoveUnusedPortsAndPins();
cleaned_up.insert(mi);
}
}
for (auto module_to_clean_up : dest_parent_tree) {
dbModInst* mi = module_to_clean_up->getModInst();
if (mi) {
if (cleaned_up.find(mi) == cleaned_up.end()) {
mi->RemoveUnusedPortsAndPins();
cleaned_up.insert(mi);
}
}
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/odb/include/odb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,9 @@ class dbBlock : public dbObject
///
dbSet<dbITerm> getITerms();

///
/// Get iterm from block
///
dbITerm* getITerm(int);

///
Expand Down Expand Up @@ -7615,6 +7618,7 @@ class dbModBTerm : public dbObject
dbModule* getParent() const;

// User Code Begin dbModBTerm

void setParentModITerm(dbModITerm* parent_pin);
dbModITerm* getParentModITerm() const;
void setModNet(dbModNet* modNet);
Expand All @@ -7629,6 +7633,7 @@ class dbModBTerm : public dbObject
void setBusPort(dbBusPort*);
dbBusPort* getBusPort() const;
static dbModBTerm* create(dbModule* parentModule, const char* name);
static void destroy(dbModBTerm*);

private:
// User Code End dbModBTerm
Expand All @@ -7653,6 +7658,8 @@ class dbModInst : public dbObject

dbSet<dbModITerm> getModITerms();

void RemoveUnusedPortsAndPins();

static dbModInst* create(dbModule* parentModule,
dbModule* masterModule,
const char* name);
Expand Down Expand Up @@ -7681,7 +7688,7 @@ class dbModITerm : public dbObject
void connect(dbModNet* modnet);
void disconnect();
static dbModITerm* create(dbModInst* parentInstance, const char* name);

static void destroy(dbModITerm*);
// User Code End dbModITerm
};

Expand All @@ -7698,6 +7705,7 @@ class dbModNet : public dbObject

const char* getName() const;
static dbModNet* create(dbModule* parentModule, const char* name);
static void destroy(dbModNet*);
// User Code End dbModNet
};

Expand Down
Loading

0 comments on commit f04933b

Please sign in to comment.