Skip to content

Commit c7af57d

Browse files
authored
Merge pull request #7878 from AcKoucher/odb-inst-to-scan-inst
odb: hash instance to its scan version
2 parents d5dd734 + dda94a7 commit c7af57d

File tree

7 files changed

+61
-3
lines changed

7 files changed

+61
-3
lines changed

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_map_insts_to_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/dbDatabase.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ namespace odb {
4343
const uint db_schema_major = 0; // Not used...
4444
const uint db_schema_initial = 57;
4545

46-
const uint db_schema_minor = 110; // Current revision number
46+
const uint db_schema_minor = 111; // Current revision number
4747

48+
// Revision where the map which associates instances to their
49+
// scan version was added
50+
const uint db_schema_map_insts_to_scan_insts = 111;
51+
52+
// Revision where the ownership of the scan insts was changed
53+
// from the its scan list to the block
4854
const uint db_schema_block_owns_scan_insts = 110;
4955

5056
// Revision where is_connect_to_term_ flag was added to dbGuide

src/odb/src/db/dbInst.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "dbNet.h"
3030
#include "dbNullIterator.h"
3131
#include "dbRegion.h"
32+
#include "dbScanInst.h"
3233
#include "dbTable.h"
3334
#include "dbTable.hpp"
3435
#include "odb/db.h"
@@ -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;
@@ -1411,6 +1428,15 @@ void dbInst::destroy(dbInst* inst_)
14111428
inst->_name);
14121429
}
14131430

1431+
dbScanInst* scan_inst = inst_->getScanInst();
1432+
if (scan_inst) {
1433+
inst->getLogger()->error(
1434+
utl::ODB,
1435+
505,
1436+
"Attempt to destroy instance {} with an associated scan inst.",
1437+
inst->_name);
1438+
}
1439+
14141440
uint i;
14151441
uint n = inst->_iterms.size();
14161442

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)