Skip to content

Commit 47ef041

Browse files
committed
odb: dbChipConnItr
Signed-off-by: Osama <[email protected]>
1 parent d090e6a commit 47ef041

File tree

14 files changed

+304
-20
lines changed

14 files changed

+304
-20
lines changed

src/odb/include/odb/db.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7010,6 +7010,8 @@ class dbChip : public dbObject
70107010

70117011
dbSet<dbChipInst> getChipInsts() const;
70127012

7013+
dbSet<dbChipConn> getChipConns() const;
7014+
70137015
///
70147016
/// Create a new chip.
70157017
/// Returns nullptr if there is no database technology.
@@ -7041,6 +7043,8 @@ class dbChipConn : public dbObject
70417043

70427044
// User Code Begin dbChipConn
70437045

7046+
dbChip* getParentChip() const;
7047+
70447048
dbChipRegionInst* getTopRegion() const;
70457049

70467050
dbChipRegionInst* getBottomRegion() const;
@@ -7050,10 +7054,11 @@ class dbChipConn : public dbObject
70507054
std::vector<dbChipInst*> getBottomRegionPath() const;
70517055

70527056
static dbChipConn* create(const std::string& name,
7053-
dbChipRegionInst* top_region,
7054-
dbChipRegionInst* bottom_region,
7057+
dbChip* parent_chip,
70557058
std::vector<dbChipInst*> top_region_path,
7056-
std::vector<dbChipInst*> bottom_region_path);
7059+
dbChipRegionInst* top_region,
7060+
std::vector<dbChipInst*> bottom_region_path,
7061+
dbChipRegionInst* bottom_region);
70577062

70587063
static void destroy(dbChipConn* chipConn);
70597064
// User Code End dbChipConn

src/odb/src/codeGenerator/schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@
180180
"orderReversed": "true",
181181
"sequential": 0,
182182
"includes": ["dbChipInst.h", "dbChip.h"]
183+
},
184+
{
185+
"name": "dbChipConnItr",
186+
"parentObject": "dbChipConn",
187+
"tableName": "chip_conn_tbl",
188+
"reversible": "true",
189+
"orderReversed": "true",
190+
"sequential": 0,
191+
"includes": ["dbChipConn.h", "dbChip.h"]
183192
}
184193
],
185194
"relations":[

src/odb/src/codeGenerator/schema/chip/dbChip.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@
148148
"type": "dbId<_dbChipInst>",
149149
"flags": ["private"],
150150
"schema":"db_schema_chip_inst"
151+
},
152+
{
153+
"name": "conns_",
154+
"type": "dbId<_dbChipConn>",
155+
"flags": ["private"],
156+
"schema": "db_schema_chip_region"
151157
}
152158
],
153159
"declared_classes": ["dbPropertyItr", "_dbNameCache","dbBlockItr"],
@@ -161,6 +167,7 @@
161167
"dbBlockItr.h",
162168
"dbBlock.h",
163169
"dbTech.h",
164-
"dbPropertyItr.h"
170+
"dbPropertyItr.h",
171+
"dbChipConn.h"
165172
]
166173
}

src/odb/src/codeGenerator/schema/chip/dbChipConn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"fields": [
55
{ "name": "name_", "type": "std::string", "flags": ["no-set"] },
66
{ "name": "thickness_", "type": "int", "flags": [] },
7+
{ "name": "chip_", "type": "dbId<_dbChip>", "flags": ["private"] },
8+
{ "name": "chip_conn_next_", "type": "dbId<_dbChipConn>", "flags": ["private"] },
79
{ "name": "top_region_", "type": "dbId<_dbChipRegionInst>", "flags": ["private"] },
810
{ "name": "top_region_path_", "type": "std::vector<dbId<_dbChipInst>>", "flags": ["private"] },
911
{ "name": "bottom_region_", "type": "dbId<_dbChipRegionInst>", "flags": ["private"] },

src/odb/src/db/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ add_library(db
148148
dbTechLayerTwoWiresForbiddenSpcRule.cpp
149149
dbTechLayerWidthTableRule.cpp
150150
dbTechLayerWrongDirSpacingRule.cpp
151+
dbChipConnItr.cpp
151152
dbChipInstItr.cpp
152153
dbChipRegionInstItr.cpp
153154
dbGroupInstItr.cpp

src/odb/src/db/dbChip.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "dbBlock.h"
88
#include "dbBlockItr.h"
9+
#include "dbChipConn.h"
910
#include "dbChipRegion.h"
1011
#include "dbDatabase.h"
1112
#include "dbNameCache.h"
@@ -17,6 +18,7 @@
1718
#include "odb/db.h"
1819
#include "odb/dbSet.h"
1920
// User Code Begin Includes
21+
#include "dbChipConnItr.h"
2022
#include "dbChipInst.h"
2123
#include "dbChipInstItr.h"
2224
// User Code End Includes
@@ -79,6 +81,9 @@ bool _dbChip::operator==(const _dbChip& rhs) const
7981
if (chipinsts_ != rhs.chipinsts_) {
8082
return false;
8183
}
84+
if (conns_ != rhs.conns_) {
85+
return false;
86+
}
8287
if (*_prop_tbl != *rhs._prop_tbl) {
8388
return false;
8489
}
@@ -197,6 +202,9 @@ dbIStream& operator>>(dbIStream& stream, _dbChip& obj)
197202
if (obj.getDatabase()->isSchema(db_schema_chip_inst)) {
198203
stream >> obj.chipinsts_;
199204
}
205+
if (obj.getDatabase()->isSchema(db_schema_chip_region)) {
206+
stream >> obj.conns_;
207+
}
200208
if (obj.getDatabase()->isSchema(db_schema_chip_region)) {
201209
stream >> *obj.chip_region_tbl_;
202210
}
@@ -232,6 +240,7 @@ dbOStream& operator<<(dbOStream& stream, const _dbChip& obj)
232240
stream << obj.tsv_;
233241
stream << obj._top;
234242
stream << obj.chipinsts_;
243+
stream << obj.conns_;
235244
stream << *obj.chip_region_tbl_;
236245
// User Code Begin <<
237246
stream << *obj._block_tbl;
@@ -514,6 +523,13 @@ dbSet<dbChipInst> dbChip::getChipInsts() const
514523
return dbSet<dbChipInst>(chip, db->chip_inst_itr_);
515524
}
516525

526+
dbSet<dbChipConn> dbChip::getChipConns() const
527+
{
528+
_dbChip* chip = (_dbChip*) this;
529+
_dbDatabase* db = (_dbDatabase*) chip->getOwner();
530+
return dbSet<dbChipConn>(chip, db->chip_conn_itr_);
531+
}
532+
517533
dbChip* dbChip::create(dbDatabase* db_, const std::string& name, ChipType type)
518534
{
519535
_dbDatabase* db = (_dbDatabase*) db_;
@@ -541,6 +557,11 @@ void dbChip::destroy(dbChip* chip_)
541557
for (dbChipRegion* chipRegion : chipRegions) {
542558
dbChipRegion::destroy(chipRegion);
543559
}
560+
// Destroy chip connections
561+
dbSet<dbChipConn> chipConns = chip_->getChipConns();
562+
for (dbChipConn* chipConn : chipConns) {
563+
dbChipConn::destroy(chipConn);
564+
}
544565
// Destroy chip
545566
_dbDatabase* db = chip->getDatabase();
546567
if (db->_chip == chip->getOID()) {

src/odb/src/db/dbChip.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class _dbProperty;
1919
class _dbChipRegion;
2020
class _dbBlock;
2121
class _dbChipInst;
22+
class _dbChipConn;
2223

2324
class _dbChip : public _dbObject
2425
{
@@ -56,6 +57,7 @@ class _dbChip : public _dbObject
5657
dbBlockItr* _block_itr;
5758
dbPropertyItr* _prop_itr;
5859
dbId<_dbChipInst> chipinsts_;
60+
dbId<_dbChipConn> conns_;
5961
dbTable<_dbProperty>* _prop_tbl;
6062
dbTable<_dbChipRegion>* chip_region_tbl_;
6163
dbId<_dbChip> _next_entry;

src/odb/src/db/dbChipConn.cpp

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ bool _dbChipConn::operator==(const _dbChipConn& rhs) const
2626
if (thickness_ != rhs.thickness_) {
2727
return false;
2828
}
29+
if (chip_ != rhs.chip_) {
30+
return false;
31+
}
32+
if (chip_conn_next_ != rhs.chip_conn_next_) {
33+
return false;
34+
}
2935
if (top_region_ != rhs.top_region_) {
3036
return false;
3137
}
@@ -49,6 +55,8 @@ dbIStream& operator>>(dbIStream& stream, _dbChipConn& obj)
4955
{
5056
stream >> obj.name_;
5157
stream >> obj.thickness_;
58+
stream >> obj.chip_;
59+
stream >> obj.chip_conn_next_;
5260
stream >> obj.top_region_;
5361
stream >> obj.top_region_path_;
5462
stream >> obj.bottom_region_;
@@ -60,6 +68,8 @@ dbOStream& operator<<(dbOStream& stream, const _dbChipConn& obj)
6068
{
6169
stream << obj.name_;
6270
stream << obj.thickness_;
71+
stream << obj.chip_;
72+
stream << obj.chip_conn_next_;
6373
stream << obj.top_region_;
6474
stream << obj.top_region_path_;
6575
stream << obj.bottom_region_;
@@ -99,6 +109,14 @@ int dbChipConn::getThickness() const
99109
}
100110

101111
// User Code Begin dbChipConnPublicMethods
112+
113+
dbChip* dbChipConn::getParentChip() const
114+
{
115+
_dbChipConn* obj = (_dbChipConn*) this;
116+
_dbDatabase* _db = (_dbDatabase*) obj->getOwner();
117+
return (dbChip*) _db->chip_tbl_->getPtr(obj->chip_);
118+
}
119+
102120
dbChipRegionInst* dbChipConn::getTopRegion() const
103121
{
104122
_dbChipConn* obj = (_dbChipConn*) this;
@@ -139,35 +157,89 @@ std::vector<dbChipInst*> dbChipConn::getBottomRegionPath() const
139157
return bottom_region_path;
140158
}
141159

160+
std::vector<dbId<_dbChipInst>> extractChipInstsPath(
161+
dbChip* parent_chip,
162+
std::vector<dbChipInst*> chip_insts)
163+
{
164+
_dbDatabase* _db = (_dbDatabase*) parent_chip->getImpl()->getOwner();
165+
utl::Logger* logger = _db->getLogger();
166+
std::vector<dbId<_dbChipInst>> chip_insts_path;
167+
for (auto chipinst : chip_insts) {
168+
if (chipinst->getParentChip() != parent_chip) {
169+
logger->error(utl::ODB,
170+
510,
171+
"Cannot create chip connection. ChipInst {} is not a child "
172+
"of chip {}",
173+
chipinst->getName(),
174+
parent_chip->getName());
175+
}
176+
chip_insts_path.push_back(chipinst->getImpl()->getOID());
177+
parent_chip = chipinst->getMasterChip();
178+
}
179+
return chip_insts_path;
180+
}
181+
142182
dbChipConn* dbChipConn::create(const std::string& name,
143-
dbChipRegionInst* top_region,
144-
dbChipRegionInst* bottom_region,
183+
dbChip* parent_chip,
145184
std::vector<dbChipInst*> top_region_path,
146-
std::vector<dbChipInst*> bottom_region_path)
185+
dbChipRegionInst* top_region,
186+
std::vector<dbChipInst*> bottom_region_path,
187+
dbChipRegionInst* bottom_region)
147188
{
148189
_dbDatabase* _db = (_dbDatabase*) top_region->getImpl()->getOwner();
190+
if (parent_chip == nullptr || top_region_path.empty()
191+
|| bottom_region_path.empty() || top_region == nullptr
192+
|| bottom_region == nullptr) {
193+
return nullptr;
194+
}
195+
if (top_region->getChipInst() != top_region_path.back()) {
196+
_db->getLogger()->error(utl::ODB,
197+
511,
198+
"Cannot create chip connection. Top region path "
199+
"does not match top region");
200+
}
201+
if (bottom_region->getChipInst() != bottom_region_path.back()) {
202+
_db->getLogger()->error(utl::ODB,
203+
512,
204+
"Cannot create chip connection. Bottom region path "
205+
"does not match bottom region");
206+
}
149207
_dbChipConn* obj = (_dbChipConn*) _db->chip_conn_tbl_->create();
208+
_dbChip* chip = (_dbChip*) parent_chip;
150209
obj->name_ = name;
151210
obj->thickness_ = 0;
211+
obj->chip_ = chip->getOID();
152212
obj->top_region_ = top_region->getImpl()->getOID();
153213
obj->bottom_region_ = bottom_region->getImpl()->getOID();
154-
std::vector<dbId<_dbChipInst>> top_region_path_ids;
155-
for (auto chipinst : top_region_path) {
156-
top_region_path_ids.push_back(chipinst->getImpl()->getOID());
157-
}
158-
obj->top_region_path_ = top_region_path_ids;
159-
std::vector<dbId<_dbChipInst>> bottom_region_path_ids;
160-
for (auto chipinst : bottom_region_path) {
161-
bottom_region_path_ids.push_back(chipinst->getImpl()->getOID());
162-
}
163-
obj->bottom_region_path_ = bottom_region_path_ids;
214+
obj->top_region_path_ = extractChipInstsPath(parent_chip, top_region_path);
215+
obj->bottom_region_path_
216+
= extractChipInstsPath(parent_chip, bottom_region_path);
217+
218+
obj->chip_conn_next_ = chip->conns_;
219+
chip->conns_ = obj->getOID();
164220
return (dbChipConn*) obj;
165221
}
166222

167223
void dbChipConn::destroy(dbChipConn* chipConn)
168224
{
169225
_dbChipConn* obj = (_dbChipConn*) chipConn;
170226
_dbDatabase* _db = (_dbDatabase*) obj->getOwner();
227+
// Remove from chip's list of connections
228+
_dbChip* chip = (_dbChip*) chipConn->getParentChip();
229+
if (chip->conns_ == obj->getOID()) {
230+
chip->conns_ = obj->chip_conn_next_;
231+
} else {
232+
uint id = chip->conns_;
233+
while (id != 0) {
234+
_dbChipConn* _chipconn = _db->chip_conn_tbl_->getPtr(id);
235+
if (_chipconn->chip_conn_next_ == obj->getOID()) {
236+
_chipconn->chip_conn_next_ = obj->chip_conn_next_;
237+
break;
238+
}
239+
id = _chipconn->chip_conn_next_;
240+
}
241+
}
242+
// Destroy the connection
171243
_db->chip_conn_tbl_->destroy(obj);
172244
}
173245

src/odb/src/db/dbChipConn.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace odb {
1515
class dbIStream;
1616
class dbOStream;
1717
class _dbDatabase;
18+
class _dbChip;
1819
class _dbChipRegionInst;
1920
class _dbChipInst;
2021

@@ -30,6 +31,8 @@ class _dbChipConn : public _dbObject
3031

3132
std::string name_;
3233
int thickness_;
34+
dbId<_dbChip> chip_;
35+
dbId<_dbChipConn> chip_conn_next_;
3336
dbId<_dbChipRegionInst> top_region_;
3437
std::vector<dbId<_dbChipInst>> top_region_path_;
3538
dbId<_dbChipRegionInst> bottom_region_;

0 commit comments

Comments
 (0)