-
Notifications
You must be signed in to change notification settings - Fork 755
odb: Refactored insert buffer code #9182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
odb: Refactored insert buffer code #9182
Conversation
openroad-ci
commented
Jan 1, 2026
- Added const qualifiers.
- Added std::vector.reserve(16) calls.
- Minor name changes.
- Fixed lint issues.
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
src/odb/src/db/dbModNet.cpp
Outdated
| std::vector<dbModNet*> worklist; | ||
| std::set<dbModNet*> visited; | ||
| std::vector<dbModNet*> worklist; | ||
| worklist.reserve(16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea here that most often we need just a small number of list items? If so using boost small vector would be a better choice. The current code will always cause a heap allocation, boost small vector will allocate up to N items on the stack, and only go to the heap if the initial capacity is exceeded.
https://www.boost.org/doc/libs/1_69_0/doc/html/boost/container/small_vector.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small_vector looks good. Thanks for the suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request primarily focuses on improving const-correctness and clarity across several OpenDB (ODB) classes, particularly dbNet, dbModule, and dbInsertBuffer. Key changes include adding const qualifiers to numerous method parameters and return types, such as load_pins in buffer insertion functions and various get and find methods in dbModule and dbInsertBuffer. Function parameter names were also updated for better readability, like changing mcf to MillerMult in dbNet::getGndTotalCap and dbid_ to oid in dbNet::getNet functions. Additionally, internal helper functions for buffer placement were renamed for more descriptive purposes (e.g., placeNewBuffer to placeBufferAtLocationOrPin). Performance improvements were made in dbModNet by pre-allocating vector capacity. The documentation for buffer insertion APIs was updated to reflect default parameter values. Review comments highlighted and suggested fixes for several instances of const_cast and potential const-correctness violations, specifically in dbInsertBuffer::findLCA and dbModule::getOwner, recommending changes to return const pointers. The reviewer also suggested reverting some parameter name changes, such as rid back to rseg_id in dbNet::set1stRSegId and mapFile back to capNodeMap in dbNet::collapseInternalCapNum, for improved descriptiveness.
src/odb/src/db/dbInsertBuffer.cpp
Outdated
| m2 = m2->getParentModule(); | ||
| } | ||
| return m1; | ||
| return const_cast<dbModule*>(m1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using const_cast here breaks const-correctness. The function findLCA is declared const and takes const pointers, but it returns a non-const pointer. This can lead to unintended modifications of what should be a const object.
To maintain const-correctness, it's better to change the return type of findLCA to const dbModule*. This may require propagating const to the calling functions, but it leads to safer and more robust code. I've added a suggestion on the header file to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, the suggested solution makes using this API more difficult.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by the original comment saying "findLCA is declared const and takes const pointers" as it signature was
findLCA(dbModule* m1, dbModule* m2) const
which doesn't take const pointers. I see no const_cast at all in the original. I think this is a bad suggestion and would undo the change it suggested.
src/odb/src/db/dbInsertBuffer.h
Outdated
| dbITerm* drvr_term, | ||
| const std::set<dbObject*>& load_pins); | ||
| int getModuleDepth(const dbModule* mod) const; | ||
| dbModule* findLCA(const dbModule* m1, const dbModule* m2) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is const and takes const pointers, but returns a non-const pointer. This breaks const-correctness and requires a const_cast in the implementation. To fix this, the return type should be const dbModule*. This will likely require propagating const to callers of findLCA.
| dbModule* findLCA(const dbModule* m1, const dbModule* m2) const; | |
| const dbModule* findLCA(const dbModule* m1, const dbModule* m2) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again not true " takes const pointers,"
| dbBlock* dbModule::getOwner() const | ||
| { | ||
| _dbModule* obj = (_dbModule*) this; | ||
| return (dbBlock*) obj->getOwner(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast (_dbModule*) this inside a const member function is a const_cast in disguise, which breaks const-correctness. This function should return a const dbBlock* to be const-correct.
Consider changing the function signature in db.h and this implementation to:
const dbBlock* dbModule::getOwner() const
{
const _dbModule* obj = (const _dbModule*) this;
return (const dbBlock*) obj->getOwner();
}
This would require _dbObject::getOwner() to be a const method, and callers of dbModule::getOwner() might need to be updated to handle a const dbBlock*.
const dbBlock* dbModule::getOwner() const
{
const _dbModule* obj = (const _dbModule*) this;
return (const dbBlock*) obj->getOwner();
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't change the return type but you could do
const _dbModule* obj = (const _dbModule*) this;
src/odb/include/odb/db.h
Outdated
| /// Set the 1st R segment of this net. | ||
| /// | ||
| void set1stRSegId(uint32_t rseg_id); | ||
| void set1stRSegId(uint32_t rid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter name rid is less descriptive than the original rseg_id. While the function name set1stRSegId provides context, a more descriptive name like rseg_id or rsegId would improve readability and clarity, especially for developers unfamiliar with this part of the codebase.
| void set1stRSegId(uint32_t rid); | |
| void set1stRSegId(uint32_t rseg_id); |
src/odb/include/odb/db.h
Outdated
| /// compact internal capnode number' | ||
| /// | ||
| void collapseInternalCapNum(FILE* capNodeMap); | ||
| void collapseInternalCapNum(FILE* mapFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new parameter name mapFile is more generic than the original capNodeMap. Given the function collapseInternalCapNum and its comment "compact internal capnode number", capNodeMap seems more descriptive of the file's contents. Consider reverting to the original name for better clarity.
| void collapseInternalCapNum(FILE* mapFile); | |
| void collapseInternalCapNum(FILE* capNodeMap); |
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
src/odb/src/db/dbInsertBuffer.cpp
Outdated
| m2 = m2->getParentModule(); | ||
| } | ||
| return m1; | ||
| return const_cast<dbModule*>(m1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by the original comment saying "findLCA is declared const and takes const pointers" as it signature was
findLCA(dbModule* m1, dbModule* m2) const
which doesn't take const pointers. I see no const_cast at all in the original. I think this is a bad suggestion and would undo the change it suggested.
src/odb/src/db/dbInsertBuffer.h
Outdated
| dbITerm* drvr_term, | ||
| const std::set<dbObject*>& load_pins); | ||
| int getModuleDepth(const dbModule* mod) const; | ||
| dbModule* findLCA(const dbModule* m1, const dbModule* m2) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again not true " takes const pointers,"
| dbBlock* dbModule::getOwner() const | ||
| { | ||
| _dbModule* obj = (_dbModule*) this; | ||
| return (dbBlock*) obj->getOwner(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't change the return type but you could do
const _dbModule* obj = (const _dbModule*) this;
src/odb/src/db/dbNet.cpp
Outdated
| } | ||
|
|
||
| void dbNet::getGndTotalCap(double* gndcap, double* totalcap, double mcf) | ||
| void dbNet::getGndTotalCap(double* gndcap, double* totalcap, double MillerMult) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any connection to insert buffer. MillerMult should be miller_mult (or miller_coupling_factor to match mcf).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to insert_buffer. I just fixed lint issues I found by chance.
Let me change it by using millter_mult including other APIs as follows.
miller_coupling_factoris somewhat long.mcflooks not intuitive.
Other APIs using MillerMult
void addGndTotalCap(double* gndcap, double* totalcap, double MillerMult);
void accAllCcCap(double* totalcap, double MillerMult);
double getCapacitance(int corner, double MillerMult);
| void dbInsertBuffer::placeNewBuffer(dbInst* buffer_inst, | ||
| const Point* loc, | ||
| dbObject* term) | ||
| void dbInsertBuffer::placeBufferAtLocationOrPin(dbInst* buffer_inst, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it clearer to have two single-purposes methods (pin / location).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the thumbs up but I don't see any change
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
|
clang-tidy review says "All clean, LGTM! 👍" |