Skip to content

Commit 6729dae

Browse files
committed
Added undoEco support for rename() methods in dbInst, dbNet, and dbModnet
Signed-off-by: Jaehyun Kim <[email protected]>
1 parent d4a4962 commit 6729dae

File tree

13 files changed

+381
-15
lines changed

13 files changed

+381
-15
lines changed

src/dbSta/test/cpp/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,27 @@ gtest_discover_tests(TestHconn
2323
add_dependencies(build_and_test TestHconn
2424
)
2525

26+
add_executable(TestRename TestRename.cpp)
27+
target_link_libraries(TestRename
28+
OpenSTA
29+
GTest::gtest
30+
GTest::gtest_main
31+
GTest::gmock
32+
dbSta_lib
33+
utl_lib
34+
${TCL_LIBRARY}
35+
)
36+
37+
target_include_directories(TestRename
38+
PRIVATE
39+
${PROJECT_SOURCE_DIR}/src/dbSta/src
40+
${PROJECT_SOURCE_DIR}/src/odb/src/db
41+
)
42+
43+
gtest_discover_tests(TestRename
44+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..
45+
)
46+
47+
add_dependencies(build_and_test TestRename
48+
)
49+

src/dbSta/test/cpp/TestRename.cpp

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file or at
5+
// https://developers.google.com/open-source/licenses/bsd
6+
7+
#include <tcl.h>
8+
#include <unistd.h>
9+
10+
#include <array>
11+
#include <cstddef>
12+
#include <cstdio>
13+
#include <filesystem>
14+
#include <iostream>
15+
#include <map>
16+
#include <memory>
17+
#include <mutex>
18+
#include <set>
19+
#include <sstream>
20+
#include <string>
21+
22+
#include "dbBlock.h"
23+
#include "dbJournal.h"
24+
#include "db_sta/MakeDbSta.hh"
25+
#include "db_sta/dbNetwork.hh"
26+
#include "db_sta/dbSta.hh"
27+
#include "gmock/gmock.h"
28+
#include "gtest/gtest.h"
29+
#include "odb/db.h"
30+
#include "odb/dbSet.h"
31+
#include "odb/lefin.h"
32+
#include "sta/Corner.hh"
33+
#include "sta/FuncExpr.hh"
34+
#include "sta/Graph.hh"
35+
#include "sta/Liberty.hh"
36+
#include "sta/PathAnalysisPt.hh"
37+
#include "sta/Search.hh"
38+
#include "sta/Sta.hh"
39+
#include "sta/Units.hh"
40+
#include "utl/Logger.h"
41+
#include "utl/deleter.h"
42+
43+
namespace odb {
44+
45+
std::once_flag init_sta_flag_rename;
46+
47+
class TestRename : public ::testing::Test
48+
{
49+
protected:
50+
void SetUp() override
51+
{
52+
db_ = utl::UniquePtrWithDeleter<odb::dbDatabase>(odb::dbDatabase::create(),
53+
&odb::dbDatabase::destroy);
54+
std::call_once(init_sta_flag_rename, []() { sta::initSta(); });
55+
sta_ = std::unique_ptr<sta::dbSta>(sta::makeDbSta());
56+
sta_->initVars(Tcl_CreateInterp(), db_.get(), &logger_);
57+
auto path = std::filesystem::canonical("./Nangate45/Nangate45_typ.lib");
58+
library_ = sta_->readLiberty(path.string().c_str(),
59+
sta_->findCorner("default"),
60+
sta::MinMaxAll::all(),
61+
false);
62+
odb::lefin lef_parser(db_.get(), &logger_, false);
63+
const char* lib_name = "Nangate45.lef";
64+
lib_ = lef_parser.createTechAndLib(
65+
"tech", lib_name, "./Nangate45/Nangate45.lef");
66+
67+
sta_->postReadLef(nullptr, lib_);
68+
69+
db_network_ = sta_->getDbNetwork();
70+
db_->setLogger(&logger_);
71+
72+
odb::dbChip* chip = odb::dbChip::create(db_.get());
73+
block_ = odb::dbBlock::create(chip, "top");
74+
db_network_->setBlock(block_);
75+
block_->setDieArea(odb::Rect(0, 0, 1000, 1000));
76+
sta_->postReadDef(block_);
77+
}
78+
79+
utl::UniquePtrWithDeleter<odb::dbDatabase> db_;
80+
std::unique_ptr<sta::dbSta> sta_;
81+
sta::LibertyLibrary* library_;
82+
utl::Logger logger_;
83+
sta::dbNetwork* db_network_;
84+
dbBlock* block_;
85+
odb::dbLib* lib_;
86+
};
87+
88+
TEST_F(TestRename, RenameNet)
89+
{
90+
dbNet* net = dbNet::create(block_, "original_net_name");
91+
ASSERT_NE(net, nullptr);
92+
EXPECT_EQ(net->getName(), "original_net_name");
93+
94+
odb::dbDatabase::beginEco(block_);
95+
net->rename("new_net_name");
96+
EXPECT_EQ(net->getName(), "new_net_name");
97+
odb::dbDatabase::endEco(block_);
98+
99+
odb::dbDatabase::undoEco(block_);
100+
EXPECT_EQ(net->getName(), "original_net_name");
101+
102+
dbNet::destroy(net);
103+
}
104+
105+
TEST_F(TestRename, RenameInst)
106+
{
107+
dbMaster* master = lib_->findMaster("INV_X1");
108+
ASSERT_NE(master, nullptr);
109+
dbInst* inst = dbInst::create(block_, master, "original_inst_name");
110+
ASSERT_NE(inst, nullptr);
111+
EXPECT_EQ(inst->getName(), "original_inst_name");
112+
113+
odb::dbDatabase::beginEco(block_);
114+
inst->rename("new_inst_name");
115+
EXPECT_EQ(inst->getName(), "new_inst_name");
116+
odb::dbDatabase::endEco(block_);
117+
118+
odb::dbDatabase::undoEco(block_);
119+
EXPECT_EQ(inst->getName(), "original_inst_name");
120+
121+
dbInst::destroy(inst);
122+
}
123+
124+
TEST_F(TestRename, RenameModNet)
125+
{
126+
dbModule* module = dbModule::create(block_, "original_module_name");
127+
ASSERT_NE(module, nullptr);
128+
129+
dbModNet* mod_net = dbModNet::create(module, "original_mod_net_name");
130+
ASSERT_NE(mod_net, nullptr);
131+
EXPECT_EQ(mod_net->getName(), "original_mod_net_name");
132+
133+
odb::dbDatabase::beginEco(block_);
134+
mod_net->rename("new_mod_net_name");
135+
EXPECT_EQ(mod_net->getName(), "new_mod_net_name");
136+
odb::dbDatabase::endEco(block_);
137+
138+
odb::dbDatabase::undoEco(block_);
139+
EXPECT_EQ(mod_net->getName(), "original_mod_net_name");
140+
141+
dbModNet::destroy(mod_net);
142+
dbModule::destroy(module);
143+
}
144+
145+
} // namespace odb

src/odb/include/odb/db.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8291,7 +8291,8 @@ class dbModNet : public dbObject
82918291
dbSet<dbITerm> getITerms();
82928292
dbSet<dbBTerm> getBTerms();
82938293
unsigned connectionCount();
8294-
const char* getName() const;
8294+
std::string getName() const;
8295+
const char* getConstName() const;
82958296
void rename(const char* new_name);
82968297
void disconnectAllTerms();
82978298

src/odb/src/db/dbInst.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,17 @@ bool dbInst::rename(const char* name)
368368
return false;
369369
}
370370

371+
if (block->_journal) {
372+
debugPrint(getImpl()->getLogger(),
373+
utl::ODB,
374+
"DB_ECO",
375+
1,
376+
"ECO: inst {}, rename to {}",
377+
getId(),
378+
name);
379+
block->_journal->updateField(this, _dbInst::NAME, inst->_name, name);
380+
}
381+
371382
block->_inst_hash.remove(inst);
372383
free((void*) inst->_name);
373384
inst->_name = safe_strdup(name);

src/odb/src/db/dbInst.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class _dbInst : public _dbObject
4646
enum Field // dbJournalField name
4747
{
4848
FLAGS,
49-
ORIGIN
49+
ORIGIN,
50+
NAME
5051
};
5152

5253
_dbInstFlags _flags;

0 commit comments

Comments
 (0)