Skip to content

Commit 96512a3

Browse files
authored
Merge pull request #8322 from The-OpenROAD-Project-staging/secure-fix-remove-cells
Added all LibertyCells into dbNetwork::concrete_cells_
2 parents c34081d + 649dd64 commit 96512a3

File tree

15 files changed

+119
-13
lines changed

15 files changed

+119
-13
lines changed

src/dbSta/include/db_sta/dbNetwork.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ class dbNetwork : public ConcreteNetwork
267267
const std::string& value) override;
268268

269269
bool isConcreteCell(const Cell*) const;
270-
void registerConcreteCell(const Cell*);
270+
void registerHierModule(const Cell* cell);
271+
void unregisterHierModule(const Cell* cell);
271272

272273
////////////////////////////////////////////////////////////////
273274
// Port functions
@@ -425,7 +426,7 @@ class dbNetwork : public ConcreteNetwork
425426

426427
private:
427428
bool hierarchy_ = false;
428-
std::set<const Cell*> concrete_cells_;
429+
std::set<const Cell*> hier_modules_;
429430
std::set<const Port*> concrete_ports_;
430431
std::unique_ptr<dbEditHierarchy> hierarchy_editor_;
431432
};

src/dbSta/include/db_sta/dbReadVerilog.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class dbVerilogNetwork : public ConcreteNetwork
4141
Cell* findAnyCell(const char* name) override;
4242
void init(dbNetwork* db_network);
4343
bool isBlackBox(ConcreteCell* cell);
44+
dbNetwork* getDbNetwork() { return static_cast<dbNetwork*>(db_network_); }
4445

4546
private:
4647
NetworkReader* db_network_ = nullptr;

src/dbSta/src/dbNetwork.cc

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,14 @@ void dbNetwork::readDbAfter(odb::dbDatabase* db)
20382038
for (dbLib* lib : db_->getLibs()) {
20392039
makeLibrary(lib);
20402040
}
2041+
2042+
for (dbModule* module : block_->getModules()) {
2043+
// top_module is not a hierarchical module in this context.
2044+
if (module != block_->getTopModule()) {
2045+
registerHierModule(dbToSta(module));
2046+
}
2047+
}
2048+
20412049
readDbNetlistAfter();
20422050
}
20432051

@@ -2062,7 +2070,6 @@ void dbNetwork::makeCell(Library* library, dbMaster* master)
20622070
master->staSetCell(reinterpret_cast<void*>(cell));
20632071
// keep track of db leaf cells. These are cells for which we
20642072
// use the concrete network.
2065-
registerConcreteCell(cell);
20662073
ConcreteCell* ccell = reinterpret_cast<ConcreteCell*>(cell);
20672074
ccell->setExtCell(reinterpret_cast<void*>(master));
20682075

@@ -2308,7 +2315,6 @@ Instance* dbNetwork::makeInstance(LibertyCell* cell,
23082315
// to get timing characteristics, so they have to be
23092316
// concrete
23102317
Cell* inst_cell = dbToSta(master);
2311-
registerConcreteCell(inst_cell);
23122318
std::unique_ptr<sta::CellPortIterator> port_iter{portIterator(inst_cell)};
23132319
while (port_iter->hasNext()) {
23142320
Port* cur_port = port_iter->next();
@@ -2326,13 +2332,12 @@ Instance* dbNetwork::makeInstance(LibertyCell* cell,
23262332
dbInst* inst = dbInst::create(block_, master, name, false, parent);
23272333
Cell* inst_cell = dbToSta(master);
23282334
//
2329-
// Register all liberty cells as being concrete
2335+
// Register all ports of liberty cells as being concrete
23302336
// Sometimes this method is called by the sta
23312337
// to build "test circuits" eg to find the max wire length
23322338
// And those cells need to use the external api
23332339
// to get timing characteristics, so they have to be
23342340
// concrete
2335-
registerConcreteCell(inst_cell);
23362341
std::unique_ptr<sta::CellPortIterator> port_iter{portIterator(inst_cell)};
23372342
while (port_iter->hasNext()) {
23382343
Port* cur_port = port_iter->next();
@@ -3193,6 +3198,16 @@ LibertyPort* dbNetwork::libertyPort(const Pin* pin) const
31933198
return nullptr;
31943199
}
31953200

3201+
void dbNetwork::registerHierModule(const Cell* cell)
3202+
{
3203+
hier_modules_.insert(cell);
3204+
}
3205+
3206+
void dbNetwork::unregisterHierModule(const Cell* cell)
3207+
{
3208+
hier_modules_.erase(cell);
3209+
}
3210+
31963211
/*
31973212
We keep a registry of the concrete cells.
31983213
For these we know to use the concrete network interface.
@@ -3201,18 +3216,17 @@ The concrete cells are created outside of the odb world
32013216
So we simply note them and then when we inspect a cell
32023217
we can decide whether or not to use the ConcreteNetwork api.
32033218
*/
3204-
3205-
void dbNetwork::registerConcreteCell(const Cell* cell)
3206-
{
3207-
concrete_cells_.insert(cell);
3208-
}
3209-
32103219
bool dbNetwork::isConcreteCell(const Cell* cell) const
32113220
{
32123221
if (!hierarchy_) {
32133222
return true;
32143223
}
3215-
return (concrete_cells_.find(cell) != concrete_cells_.end());
3224+
3225+
if (cell == top_cell_) {
3226+
return false;
3227+
}
3228+
3229+
return (hier_modules_.find(cell) == hier_modules_.end());
32163230
}
32173231

32183232
void dbNetwork::registerConcretePort(const Port* port)

src/dbSta/src/dbReadVerilog.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class Verilog2db
170170
void makeChildInsts(Instance* inst, dbModule* module, InstPairs& inst_pairs);
171171
void makeModBTerms(Cell* cell, dbModule* module);
172172
void makeModITerms(Instance* inst, dbModInst* modinst);
173+
void registerHierModule(dbModule* module);
173174
dbIoType staToDb(PortDirection* dir);
174175
bool staToDb(dbModule* module,
175176
const Pin* pin,
@@ -390,6 +391,8 @@ void Verilog2db::makeDbModule(
390391
module = dbModule::makeUniqueDbModule(
391392
network_->name(cell), network_->name(inst), block_);
392393

394+
registerHierModule(module);
395+
393396
std::string module_inst_name = network_->name(inst);
394397

395398
dbModInst* modinst
@@ -433,6 +436,14 @@ void Verilog2db::makeDbModule(
433436
makeChildInsts(inst, module, inst_pairs);
434437
}
435438

439+
void Verilog2db::registerHierModule(dbModule* module)
440+
{
441+
// Register the module as a hierarchical module in the dbNetwork.
442+
dbNetwork* db_network
443+
= static_cast<dbVerilogNetwork*>(network_)->getDbNetwork();
444+
db_network->registerHierModule(db_network->dbToSta(module));
445+
}
446+
436447
void Verilog2db::makeModBTerms(Cell* cell, dbModule* module)
437448
{
438449
dbBusPort* dbbusport = nullptr;

src/dbSta/src/dbSta.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ class dbStaCbk : public dbBlockCallBackObj
156156
void setNetwork(dbNetwork* network);
157157
void inDbInstCreate(dbInst* inst) override;
158158
void inDbInstDestroy(dbInst* inst) override;
159+
void inDbModuleCreate(dbModule* module) override;
160+
void inDbModuleDestroy(dbModule* module) override;
159161
void inDbInstSwapMasterBefore(dbInst* inst, dbMaster* master) override;
160162
void inDbInstSwapMasterAfter(dbInst* inst) override;
161163
void inDbNetDestroy(dbNet* net) override;
@@ -928,6 +930,16 @@ void dbStaCbk::inDbInstDestroy(dbInst* inst)
928930
sta_->deleteLeafInstanceBefore(network_->dbToSta(inst));
929931
}
930932

933+
void dbStaCbk::inDbModuleCreate(dbModule* module)
934+
{
935+
network_->registerHierModule(network_->dbToSta(module));
936+
}
937+
938+
void dbStaCbk::inDbModuleDestroy(dbModule* module)
939+
{
940+
network_->unregisterHierModule(network_->dbToSta(module));
941+
}
942+
931943
void dbStaCbk::inDbInstSwapMasterBefore(dbInst* inst, dbMaster* master)
932944
{
933945
LibertyCell* to_lib_cell = network_->libertyCell(network_->dbToSta(master));

src/dbSta/test/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ COMPULSORY_TESTS = [
5858
"write_verilog6",
5959
"write_verilog7",
6060
"write_verilog8",
61+
"write_verilog9",
62+
"write_verilog9_hier",
6163
]
6264

6365
ALL_TESTS = COMPULSORY_TESTS
@@ -134,6 +136,7 @@ filegroup(
134136
"reg5.v",
135137
"reg6.def",
136138
"report_cell_usage_no_taps.def",
139+
"write_verilog9.v",
137140
],
138141
)
139142

src/dbSta/test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ or_integration_tests(
5555
write_verilog6
5656
write_verilog7
5757
write_verilog8
58+
write_verilog9
59+
write_verilog9_hier
5860
)
5961

6062
if(ENABLE_TESTS)

src/dbSta/test/write_verilog9.ok

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[INFO ODB-0227] LEF file: Nangate45/Nangate45.lef, created 22 layers, 27 vias, 135 library cells
2+
module top (in1,
3+
out1);
4+
input in1;
5+
output out1;
6+
7+
8+
endmodule

src/dbSta/test/write_verilog9.tcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Test write_verilog -remove_cells in a flat flow
2+
source "helpers.tcl"
3+
read_lef Nangate45/Nangate45.lef
4+
read_liberty Nangate45/Nangate45_typ.lib
5+
read_verilog write_verilog9.v
6+
link_design top
7+
8+
set verilog_file [make_result_file write_verilog9.v]
9+
write_verilog -remove_cells BUF* $verilog_file
10+
report_file $verilog_file

src/dbSta/test/write_verilog9.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module top (in1,
2+
out1);
3+
input in1;
4+
output out1;
5+
6+
7+
BUF_X1 u1 (.A(in1),
8+
.Z(out1));
9+
endmodule

0 commit comments

Comments
 (0)