Skip to content

Commit 98d3827

Browse files
authored
Merge pull request #9109 from The-OpenROAD-Project-staging/secure-store-hier-flag-in-odb
odb: Store hierarchy_ flag in odb
2 parents 5a77d9e + 9cc00f1 commit 98d3827

File tree

11 files changed

+263
-23
lines changed

11 files changed

+263
-23
lines changed

src/OpenRoad.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,21 @@ void OpenRoad::read3DBloxBMap(const std::string& filename)
504504
odb::ThreeDBlox parser(logger_, db_);
505505
parser.readBMap(filename);
506506
}
507+
507508
void OpenRoad::write3Dbv(const std::string& filename)
508509
{
509510
odb::ThreeDBlox writer(logger_, db_, sta_);
510511
writer.writeDbv(filename, db_->getChip());
511512
}
513+
512514
void OpenRoad::write3Dbx(const std::string& filename)
513515
{
514516
odb::ThreeDBlox writer(logger_, db_, sta_);
515517
writer.writeDbx(filename, db_->getChip());
516518
}
519+
520+
// TODO: bool hierarchy should be removed in the future.
521+
// It is retained for a while for backward compatibility.
517522
void OpenRoad::readDb(const char* filename, bool hierarchy)
518523
{
519524
try {
@@ -523,7 +528,7 @@ void OpenRoad::readDb(const char* filename, bool hierarchy)
523528
logger_->error(ORD, 54, "odb file {} is invalid: {}", filename, f.what());
524529
}
525530
// treat this as a hierarchical network.
526-
if (hierarchy) {
531+
if (hierarchy || db_->hasHierarchy()) {
527532
logger_->warn(
528533
ORD,
529534
12,

src/OpenRoad.tcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ sta::define_cmd_args "write_db" {filename}
233233
sta::define_cmd_args "read_db" {[-hier] filename}
234234

235235
proc read_db { args } {
236+
# TODO: -hier is not needed anymore.
237+
# - It will be removed in a future release.
238+
# - It is currently retained for backward compatibility.
236239
sta::parse_key_args "read_db" args keys {} flags {-hier}
237240
sta::check_argc_eq1or2 "read_db" $args
238241
set filename [file nativename [lindex $args 0]]

src/dbSta/include/db_sta/dbNetwork.hh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ class dbNetwork : public ConcreteNetwork
394394

395395
// hierarchy handler, set in openroad tested in network child traverserser
396396

397-
void setHierarchy() { hierarchy_ = true; }
398-
void disableHierarchy() { hierarchy_ = false; }
399-
bool hasHierarchy() const { return hierarchy_; }
397+
void setHierarchy() { db_->setHierarchy(true); }
398+
void disableHierarchy() { db_->setHierarchy(false); }
399+
bool hasHierarchy() const { return db_->hasHierarchy(); }
400400
bool hasHierarchicalElements() const;
401401
void reassociateHierFlatNet(dbModNet* mod_net,
402402
dbNet* new_flat_net,
@@ -470,7 +470,6 @@ class dbNetwork : public ConcreteNetwork
470470
static constexpr unsigned DBIDTAG_WIDTH = 0x4;
471471

472472
private:
473-
bool hierarchy_ = false;
474473
std::set<const Cell*> hier_modules_;
475474
std::set<const Port*> concrete_ports_;
476475
std::unique_ptr<dbEditHierarchy> hierarchy_editor_;

src/dbSta/src/dbEditHierarchy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void dbEditHierarchy::hierarchicalConnect(dbITerm* source_pin,
252252
//
253253
dbNet* source_db_net = source_pin->getNet();
254254
dbNet* dest_db_net = dest_pin->getNet();
255-
if (db_network_->hierarchy_ == false) {
255+
if (db_network_->hasHierarchy() == false) {
256256
// If both source pin and dest pin do not have a corresponding flat net,
257257
// Create a new net and connect it with source pin.
258258
if (source_db_net == nullptr && dest_db_net == nullptr) {

src/dbSta/src/dbNetwork.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ ObjectId dbNetwork::id(const Port* port) const
768768
return std::numeric_limits<ObjectId>::max();
769769
}
770770

771-
if (hierarchy_) {
771+
if (hasHierarchy()) {
772772
if (isConcretePort(port)) {
773773
return ConcreteNetwork::id(port);
774774
}
@@ -790,7 +790,7 @@ ObjectId dbNetwork::id(const Port* port) const
790790
ObjectId dbNetwork::id(const Cell* cell) const
791791
{
792792
// in hierarchical flow we use the object id for the index
793-
if (hierarchy_) {
793+
if (hasHierarchy()) {
794794
if (!isConcreteCell(cell)) {
795795
const dbObject* obj = reinterpret_cast<const dbObject*>(cell);
796796
return getDbNwkObjectId(obj);
@@ -808,7 +808,7 @@ ObjectId dbNetwork::id(const Instance* instance) const
808808
if (instance == top_instance_) {
809809
return 0;
810810
}
811-
if (hierarchy_) {
811+
if (hasHierarchy()) {
812812
const dbObject* obj = reinterpret_cast<const dbObject*>(instance);
813813
return getDbNwkObjectId(obj);
814814
}
@@ -840,7 +840,7 @@ const char* dbNetwork::name(const Port* port) const
840840
return nullptr;
841841
}
842842

843-
if (hierarchy_) {
843+
if (hasHierarchy()) {
844844
size_t last_idx = name.find_last_of('/');
845845
if (last_idx != std::string::npos) {
846846
name = name.substr(last_idx + 1);
@@ -887,7 +887,7 @@ const char* dbNetwork::name(const Instance* instance) const
887887
name = mod_inst->getName();
888888
}
889889

890-
if (hierarchy_) {
890+
if (hasHierarchy()) {
891891
size_t last_idx = std::string::npos;
892892
size_t pos = name.length();
893893
while ((pos = name.rfind('/', pos)) != std::string::npos) {
@@ -1096,7 +1096,7 @@ Instance* dbNetwork::parent(const Instance* instance) const
10961096

10971097
Port* dbNetwork::findPort(const Cell* cell, const char* name) const
10981098
{
1099-
if (hierarchy_) {
1099+
if (hasHierarchy()) {
11001100
dbMaster* db_master;
11011101
dbModule* db_module;
11021102
staToDb(cell, db_master, db_module);
@@ -1125,7 +1125,7 @@ bool dbNetwork::isLeaf(const Instance* instance) const
11251125
if (instance == top_instance_) {
11261126
return false;
11271127
}
1128-
if (hierarchy_) {
1128+
if (hasHierarchy()) {
11291129
dbMaster* db_master;
11301130
dbModule* db_module;
11311131
Cell* cur_cell = cell(instance);
@@ -1140,7 +1140,7 @@ bool dbNetwork::isLeaf(const Instance* instance) const
11401140

11411141
Instance* dbNetwork::findInstance(const char* path_name) const
11421142
{
1143-
if (hierarchy_) { // are we in hierarchical mode ?
1143+
if (hasHierarchy()) { // are we in hierarchical mode ?
11441144
// find a hierarchical module instance first
11451145
dbModInst* mod_inst = block()->findModInst(path_name);
11461146
if (mod_inst) {
@@ -1395,7 +1395,7 @@ ObjectId dbNetwork::id(const Pin* pin) const
13951395

13961396
staToDb(pin, iterm, bterm, moditerm);
13971397

1398-
if (hierarchy_) {
1398+
if (hasHierarchy()) {
13991399
// get the id for hierarchical objects using dbid.
14001400
std::uintptr_t tag_value
14011401
= reinterpret_cast<std::uintptr_t>(pin) & kPointerTagMask;
@@ -1784,7 +1784,7 @@ ObjectId dbNetwork::id(const Net* net) const
17841784
dbModNet* modnet = nullptr;
17851785
dbNet* dnet = nullptr;
17861786
staToDb(net, dnet, modnet);
1787-
if (hierarchy_) {
1787+
if (hasHierarchy()) {
17881788
const dbObject* obj = reinterpret_cast<const dbObject*>(net);
17891789
return getDbNwkObjectId(obj);
17901790
}
@@ -1865,7 +1865,7 @@ const char* dbNetwork::name(const Net* net) const
18651865
// strip out the parent name in hierarchy mode
18661866
// turn this off to get full flat names
18671867

1868-
if (hierarchy_) {
1868+
if (hasHierarchy()) {
18691869
//
18701870
// If this is not a hierarchical name, return it
18711871
//
@@ -2054,7 +2054,7 @@ const Net* dbNetwork::highestConnectedNet(Net* net) const
20542054

20552055
ObjectId dbNetwork::id(const Term* term) const
20562056
{
2057-
if (hierarchy_) {
2057+
if (hasHierarchy()) {
20582058
const dbObject* obj = reinterpret_cast<const dbObject*>(term);
20592059
return getDbNwkObjectId(obj);
20602060
}
@@ -3408,7 +3408,7 @@ we can decide whether or not to use the ConcreteNetwork api.
34083408
*/
34093409
bool dbNetwork::isConcreteCell(const Cell* cell) const
34103410
{
3411-
if (!hierarchy_) {
3411+
if (!hasHierarchy()) {
34123412
return true;
34133413
}
34143414

@@ -3426,7 +3426,7 @@ void dbNetwork::registerConcretePort(const Port* port)
34263426

34273427
bool dbNetwork::isConcretePort(const Port* port) const
34283428
{
3429-
if (!hierarchy_) {
3429+
if (!hasHierarchy()) {
34303430
return true;
34313431
}
34323432
if (concrete_ports_.find(port) != concrete_ports_.end()) {
@@ -3494,7 +3494,7 @@ int dbNetwork::toIndex(const Port* port) const
34943494

34953495
bool dbNetwork::hasMembers(const Port* port) const
34963496
{
3497-
if (hierarchy_) {
3497+
if (hasHierarchy()) {
34983498
dbMTerm* mterm = nullptr;
34993499
dbBTerm* bterm = nullptr;
35003500
dbModBTerm* modbterm = nullptr;
@@ -3580,7 +3580,7 @@ PortMemberIterator* dbNetwork::memberIterator(const Port* port) const
35803580
{
35813581
// top-level port is concrete port. DbNetworkPortMemberIterator cannot handle
35823582
// it.
3583-
if (!hierarchy_ || isConcretePort(port)) {
3583+
if (!hasHierarchy() || isConcretePort(port)) {
35843584
return ConcreteNetwork::memberIterator(port);
35853585
}
35863586

src/odb/include/odb/db.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7377,6 +7377,9 @@ class dbDatabase : public dbObject
73777377

73787378
// User Code Begin dbDatabase
73797379

7380+
void setHierarchy(bool value);
7381+
bool hasHierarchy() const;
7382+
73807383
void setTopChip(dbChip* chip);
73817384
///
73827385
/// Return the libs contained in the database. A database can contain

src/odb/src/db/dbDatabase.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ _dbDatabase::_dbDatabase(_dbDatabase* db)
180180
master_id_ = 0;
181181
logger_ = utl::Logger::defaultLogger();
182182
unique_id_ = db_unique_id++;
183+
hierarchy_ = false;
183184

184185
gds_lib_tbl_ = new dbTable<_dbGDSLib, 2>(
185186
this, this, (GetObjTbl_t) &_dbDatabase::getObjectTable, dbGdsLibObj);
@@ -290,6 +291,11 @@ dbIStream& operator>>(dbIStream& stream, _dbDatabase& obj)
290291
stream >> obj.dbu_per_micron_;
291292
}
292293
}
294+
if (obj.isSchema(kSchemaHierarchyFlag)) {
295+
stream >> obj.hierarchy_;
296+
} else {
297+
obj.hierarchy_ = false;
298+
}
293299
// Set the _tech on the block & libs now they are loaded
294300
if (!obj.isSchema(kSchemaBlockTech)) {
295301
if (obj.chip_) {
@@ -354,6 +360,7 @@ dbOStream& operator<<(dbOStream& stream, const _dbDatabase& obj)
354360
stream << *obj.chip_bump_inst_tbl_;
355361
stream << *obj.chip_net_tbl_;
356362
stream << obj.dbu_per_micron_;
363+
stream << obj.hierarchy_;
357364
// User Code End <<
358365
return stream;
359366
}
@@ -455,6 +462,7 @@ _dbDatabase::_dbDatabase(_dbDatabase* /* unused: db */, int id)
455462
logger_ = nullptr;
456463
unique_id_ = id;
457464
dbu_per_micron_ = 0;
465+
hierarchy_ = false;
458466

459467
chip_tbl_ = new dbTable<_dbChip, 2>(
460468
this, this, (GetObjTbl_t) &_dbDatabase::getObjectTable, dbChipObj);
@@ -693,6 +701,18 @@ dbTech* dbDatabase::getTech()
693701
utl::ODB, 432, "getTech() is obsolete in a multi-tech db");
694702
}
695703

704+
void dbDatabase::setHierarchy(bool value)
705+
{
706+
_dbDatabase* db = reinterpret_cast<_dbDatabase*>(this);
707+
db->hierarchy_ = value;
708+
}
709+
710+
bool dbDatabase::hasHierarchy() const
711+
{
712+
const _dbDatabase* db = reinterpret_cast<const _dbDatabase*>(this);
713+
return db->hierarchy_;
714+
}
715+
696716
void dbDatabase::read(std::istream& file)
697717
{
698718
_dbDatabase* db = (_dbDatabase*) this;

src/odb/src/db/dbDatabase.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ namespace odb {
4848
inline constexpr uint kSchemaMajor = 0; // Not used...
4949
inline constexpr uint kSchemaInitial = 57;
5050

51-
inline constexpr uint kSchemaMinor = 123; // Current revision number
51+
inline constexpr uint kSchemaMinor = 124; // Current revision number
52+
53+
// Revision where _dbDatabase::hierarchy_ was added
54+
inline constexpr uint kSchemaHierarchyFlag = 124;
5255

5356
// Revision where dbMarkerCategory was moved from dbBlock to dbChip
5457
inline constexpr uint kSchemaChipMarkerCategories = 123;
@@ -320,6 +323,7 @@ class _dbDatabase : public _dbObject
320323
dbChipBumpInstItr* chip_bump_inst_itr_;
321324
dbChipNetItr* chip_net_itr_;
322325
int unique_id_;
326+
bool hierarchy_;
323327

324328
utl::Logger* logger_;
325329
std::set<dbDatabaseObserver*> observers_;

src/odb/test/cpp/BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,25 @@ cc_test(
251251
],
252252
)
253253

254+
cc_test(
255+
name = "TestWriteReadDbHier",
256+
srcs = [
257+
"TestWriteReadDbHier.cpp",
258+
],
259+
data = [
260+
"//src/odb/test:regression_resources",
261+
],
262+
deps = [
263+
"//src/dbSta",
264+
"//src/dbSta:dbNetwork",
265+
"//src/odb",
266+
"//src/sta:opensta_lib",
267+
"//src/tst",
268+
"//src/tst:integrated_fixture",
269+
"//src/utl",
270+
"@googletest//:gtest",
271+
"@googletest//:gtest_main",
272+
],
273+
)
274+
254275
# TODO: more to come.

src/odb/test/cpp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_executable(TestChips TestChips.cpp)
3838
add_executable(Test3DBloxParser Test3DBloxParser.cpp)
3939
add_executable(Test3DBloxChecker Test3DBloxChecker.cpp)
4040
add_executable(TestSwapMaster TestSwapMaster.cpp)
41+
add_executable(TestWriteReadDbHier TestWriteReadDbHier.cpp)
4142

4243
target_link_libraries(OdbGTests ${TEST_LIBS})
4344
target_link_libraries(TestCallBacks ${TEST_LIBS})
@@ -56,6 +57,7 @@ target_link_libraries(TestChips ${TEST_LIBS})
5657
target_link_libraries(Test3DBloxParser ${TEST_LIBS})
5758
target_link_libraries(Test3DBloxChecker ${TEST_LIBS})
5859
target_link_libraries(TestSwapMaster ${TEST_LIBS})
60+
target_link_libraries(TestWriteReadDbHier ${TEST_LIBS})
5961

6062
# Skip the tests from being registered here, since they are called via
6163
# cpp_tests.tcl and don't need to be executed twice. The cpp_tests.tcl
@@ -82,6 +84,7 @@ add_dependencies(build_and_test
8284
Test3DBloxParser
8385
Test3DBloxChecker
8486
TestSwapMaster
87+
TestWriteReadDbHier
8588
OdbGTests
8689
)
8790
add_subdirectory(helper)

0 commit comments

Comments
 (0)