Skip to content

Commit e6b5d08

Browse files
committed
odb: hash instance to its scan version
Signed-off-by: Arthur Koucher <arthurkoucher@precisioninno.com>
1 parent 59f780d commit e6b5d08

6 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/odb/include/odb/db.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,6 +3263,12 @@ class dbInst : public dbObject
32633263
///
32643264
bool isEndCap() const;
32653265

3266+
///
3267+
/// Get the scan version of this instance.
3268+
/// Returns nullptr if this instance has no scan version.
3269+
///
3270+
dbScanInst* getScanInst() const;
3271+
32663272
void setPinAccessIdx(uint idx);
32673273

32683274
uint getPinAccessIdx() const;

src/odb/include/odb/dbId.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,17 @@ class dbId
4040
};
4141

4242
} // namespace odb
43+
44+
// Enable unordered_map/set usage
45+
namespace std {
46+
47+
template <typename T>
48+
struct hash<odb::dbId<T>>
49+
{
50+
std::size_t operator()(const odb::dbId<T>& db_id) const
51+
{
52+
return std::hash<unsigned int>()(db_id);
53+
}
54+
};
55+
56+
} // namespace std

src/odb/src/db/dbBlock.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ dbOStream& operator<<(dbOStream& stream, const _dbBlock& block)
846846
stream << block._max_layer_for_clock;
847847
stream << block._bterm_groups;
848848
stream << block._bterm_top_layer_grid;
849+
stream << block._inst_scan_inst_map;
849850

850851
//---------------------------------------------------------- stream out
851852
// properties
@@ -1024,6 +1025,9 @@ dbIStream& operator>>(dbIStream& stream, _dbBlock& block)
10241025
if (db->isSchema(db_schema_bterm_top_layer_grid)) {
10251026
stream >> block._bterm_top_layer_grid;
10261027
}
1028+
if (db->isSchema(db_schema_block_owns_scan_insts)) {
1029+
stream >> block._inst_scan_inst_map;
1030+
}
10271031

10281032
//---------------------------------------------------------- stream in
10291033
// properties

src/odb/src/db/dbBlock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class _dbBlock : public _dbObject
287287

288288
std::unordered_map<std::string, int> _module_name_id_map;
289289
std::unordered_map<std::string, int> _inst_name_id_map;
290+
std::unordered_map<dbId<_dbInst>, dbId<_dbScanInst>> _inst_scan_inst_map;
290291

291292
unsigned char _num_ext_dbs;
292293

src/odb/src/db/dbInst.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "odb/dbSet.h"
3737
#include "odb/dbTransform.h"
3838
#include "utl/Logger.h"
39+
#include "dbScanInst.h"
3940

4041
namespace odb {
4142

@@ -785,6 +786,22 @@ bool dbInst::isEndCap() const
785786
return getMaster()->isEndCap();
786787
}
787788

789+
dbScanInst* dbInst::getScanInst() const
790+
{
791+
_dbInst* inst = (_dbInst*) this;
792+
_dbBlock* block = (_dbBlock*) inst->getOwner();
793+
auto itr = block->_inst_scan_inst_map.find(inst->getId());
794+
795+
if (itr == block->_inst_scan_inst_map.end()) {
796+
return nullptr;
797+
}
798+
799+
dbId<_dbScanInst> scan_inst_id = itr->second;
800+
_dbScanInst* scan_inst = block->_scan_inst_tbl->getPtr(scan_inst_id);
801+
802+
return (dbScanInst*) scan_inst;
803+
}
804+
788805
dbSet<dbITerm> dbInst::getITerms()
789806
{
790807
_dbInst* inst = (_dbInst*) this;

src/odb/src/db/dbScanInst.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ dbScanInst* dbScanInst::create(dbScanList* scan_list, dbInst* inst)
255255
{
256256
_dbBlock* block = (_dbBlock*) ((_dbInst*) inst)->getOwner();
257257
_dbScanInst* scan_inst = (_dbScanInst*) block->_scan_inst_tbl->create();
258-
scan_inst->inst_ = ((_dbInst*) inst)->getId();
259-
258+
odb::uint inst_id = ((_dbInst*) inst)->getId();
259+
scan_inst->inst_ = (dbId<dbInst>) inst_id;
260+
block->_inst_scan_inst_map[(dbId<_dbInst>) inst_id] = scan_inst->getId();
260261
return (dbScanInst*) scan_inst;
261262
}
262263

0 commit comments

Comments
 (0)