Skip to content

Commit 5071203

Browse files
authored
Merge pull request #8861 from The-OpenROAD-Project-staging/secure-fix-dbsta-for-read-vcd
dbSta: Fixed `find*()` and `isConnected()` APIs for `read_spef` and `read_vcd`
2 parents 53af9e7 + a7d3c84 commit 5071203

31 files changed

+375509
-200
lines changed

src/dbSta/include/db_sta/dbNetwork.hh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "odb/db.h"
1010
#include "sta/ConcreteNetwork.hh"
1111
#include "sta/GraphClass.hh"
12+
#include "sta/Network.hh"
1213

1314
namespace utl {
1415
class Logger;
@@ -177,7 +178,10 @@ class dbNetwork : public ConcreteNetwork
177178
bool hier = false);
178179
Instance* getOwningInstanceParent(Pin* pin);
179180

180-
bool connected(Pin* source_pin, Pin* dest_pin);
181+
using Network::isConnected;
182+
bool isConnected(const Net* net, const Pin* pin) const override;
183+
bool isConnected(const Net* net1, const Net* net2) const override;
184+
bool isConnected(const Pin* source_pin, const Pin* dest_pin) const;
181185
void hierarchicalConnect(dbITerm* source_pin,
182186
dbITerm* dest_pin,
183187
const char* connection_name = "net");

src/dbSta/src/dbEditHierarchy.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ void dbEditHierarchy::hierarchicalConnect(dbITerm* source_pin,
293293
source_pin->connect(source_db_net);
294294
dlogHierConnConnectSrcToFlatNet(source_pin, connection_name);
295295
}
296-
if (!db_network_->connected(db_network_->dbToSta(source_pin),
297-
db_network_->dbToSta(dest_pin))) {
296+
if (!db_network_->isConnected(db_network_->dbToSta(source_pin),
297+
db_network_->dbToSta(dest_pin))) {
298298
dest_pin->connect(source_db_net);
299299
dlogHierConnConnectDstToFlatNet(dest_pin, source_db_net);
300300
}

src/dbSta/src/dbNetwork.cc

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,12 @@ bool dbNetwork::isLeaf(const Instance* instance) const
11321132
Instance* dbNetwork::findInstance(const char* path_name) const
11331133
{
11341134
if (hierarchy_) { // are we in hierarchical mode ?
1135+
// find a hierarchical module instance first
1136+
dbModInst* mod_inst = block()->findModInst(path_name);
1137+
if (mod_inst) {
1138+
return dbToSta(mod_inst);
1139+
}
1140+
11351141
std::string path_name_str = path_name;
11361142
// search for the last token in the string, which is the leaf instance name
11371143
size_t last_idx = path_name_str.find_last_of('/');
@@ -3745,13 +3751,6 @@ bool PinConnections::connected(const Pin* pin) const
37453751
return pins_.find(pin) != pins_.end();
37463752
}
37473753

3748-
bool dbNetwork::connected(Pin* source_pin, Pin* dest_pin)
3749-
{
3750-
PinConnections visitor;
3751-
network_->visitConnectedPins(source_pin, visitor);
3752-
return visitor.connected(dest_pin);
3753-
}
3754-
37553754
void dbNetwork::removeUnusedPortsAndPinsOnModuleInstances()
37563755
{
37573756
for (dbModInst* mi : block()->getModInsts()) {
@@ -3777,6 +3776,45 @@ class DbNetConnectedToBTerm : public PinVisitor
37773776
dbBTerm* bterm_{nullptr};
37783777
};
37793778

3779+
bool dbNetwork::isConnected(const Pin* source_pin, const Pin* dest_pin) const
3780+
{
3781+
PinConnections visitor;
3782+
network_->visitConnectedPins(source_pin, visitor);
3783+
return visitor.connected(dest_pin);
3784+
}
3785+
3786+
bool dbNetwork::isConnected(const Net* net, const Pin* pin) const
3787+
{
3788+
dbNet* dbnet;
3789+
dbModNet* modnet;
3790+
staToDb(net, dbnet, modnet);
3791+
3792+
dbNet* pin_dbnet = findFlatDbNet(pin);
3793+
if (dbnet != nullptr) {
3794+
return dbnet->isConnected(pin_dbnet);
3795+
}
3796+
if (modnet != nullptr) {
3797+
return modnet->isConnected(pin_dbnet);
3798+
}
3799+
3800+
return false;
3801+
}
3802+
3803+
bool dbNetwork::isConnected(const Net* net1, const Net* net2) const
3804+
{
3805+
if (net1 == net2) {
3806+
return true;
3807+
}
3808+
3809+
dbNet* flat_net1 = findFlatDbNet(net1);
3810+
dbNet* flat_net2 = findFlatDbNet(net2);
3811+
if (flat_net1 != nullptr && flat_net1 == flat_net2) {
3812+
return true;
3813+
}
3814+
3815+
return false;
3816+
}
3817+
37803818
void DbNetConnectedToBTerm::operator()(const Pin* pin)
37813819
{
37823820
dbITerm* iterm;
@@ -4293,14 +4331,13 @@ Net* dbNetwork::findFlatNet(const Pin* pin) const
42934331
// This function handles both internal instance pins and top-level port pins.
42944332
dbNet* dbNetwork::findFlatDbNet(const Pin* pin) const
42954333
{
4296-
dbNet* db_net = nullptr;
4334+
Net* sta_net = nullptr;
42974335
if (isTopLevelPort(pin)) {
4298-
Net* net = this->net(term(pin));
4299-
db_net = flatNet(net);
4336+
sta_net = net(term(pin));
43004337
} else {
4301-
db_net = flatNet(pin);
4338+
sta_net = net(pin);
43024339
}
4303-
return db_net;
4340+
return findFlatDbNet(sta_net);
43044341
}
43054342

43064343
dbModInst* dbNetwork::getModInst(Instance* inst) const

src/dbSta/test/BUILD

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ COMPULSORY_TESTS = [
1212
"check_axioms",
1313
"clock_pin",
1414
"constant1",
15-
#"escape_slash", # different result compared to CMake
16-
#"escape_slash_hier", # different result compared to CMake
15+
# "escape_slash", # different result compared to CMake
16+
# "escape_slash_hier", # different result compared to CMake
1717
"find_clks1",
1818
"find_clks2",
1919
"get_ports1",
@@ -26,6 +26,7 @@ COMPULSORY_TESTS = [
2626
"network_edit1",
2727
"power1",
2828
"read_liberty1",
29+
"read_vcd",
2930
"read_verilog1",
3031
"read_verilog2",
3132
"read_verilog3",
@@ -154,6 +155,13 @@ filegroup(
154155
test_name + ".*",
155156
],
156157
) + {
158+
"read_vcd": glob(
159+
[
160+
"Element.*",
161+
"MockArray.*",
162+
"asap7/*",
163+
],
164+
),
157165
"report_cell_usage_file": [
158166
"report_cell_usage.def",
159167
],
@@ -193,3 +201,23 @@ cc_test(
193201
"@googletest//:gtest_main",
194202
],
195203
)
204+
205+
cc_test(
206+
name = "dbsta_unittest",
207+
srcs = ["cpp/TestDbSta.cc"],
208+
data = [
209+
"Nangate45/Nangate45.lef",
210+
"Nangate45/Nangate45_typ.lib",
211+
"cpp/TestDbSta_0.v",
212+
],
213+
deps = [
214+
"//src/dbSta",
215+
"//src/dbSta:dbNetwork",
216+
"//src/odb",
217+
"//src/sta:opensta_lib",
218+
"//src/tst:integrated_fixture",
219+
"//src/utl",
220+
"@googletest//:gtest",
221+
"@googletest//:gtest_main",
222+
],
223+
)

src/dbSta/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ or_integration_tests(
1919
network_edit1
2020
power1
2121
read_liberty1
22+
read_vcd
2223
read_verilog1
2324
read_verilog2
2425
read_verilog3

0 commit comments

Comments
 (0)