forked from The-OpenROAD-Project-Attic/Resizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LefDefNetwork.cc
323 lines (280 loc) · 6.51 KB
/
LefDefNetwork.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// Resizer, LEF/DEF gate resizer
// Copyright (c) 2019, Parallax Software, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Machine.hh"
#include "Liberty.hh"
#include "SdcNetwork.hh"
#include "LefDefNetwork.hh"
namespace sta {
using std::round;
LefDefNetwork::LefDefNetwork() :
ConcreteNetwork(),
def_filename_(nullptr),
lef_library_(nullptr),
manufacturing_grid_(0.0)
{
}
LefDefNetwork::~LefDefNetwork()
{
clear();
}
void
LefDefNetwork::clear()
{
stringDelete(def_filename_);
def_filename_ = nullptr;
lef_library_ = nullptr;
def_component_map_.deleteContentsClear();
lef_macro_map_.deleteContents();
lef_size_map_.deleteContents();
manufacturing_grid_ = 0.0;
lef_layers_.clear();
ConcreteNetwork::clear();
}
void
LefDefNetwork::initState(Report *report,
Debug *debug)
{
report_ = report;
debug_ = debug;
sdc_network_ = new SdcNetwork(this);
}
void
LefDefNetwork::setDivider(char divider)
{
divider_ = divider;
}
void
LefDefNetwork::setDefUnits(int def_units)
{
def_units_ = def_units;
}
double
LefDefNetwork::dbuToMeters(DefDbu dbu) const
{
return (dbu / def_units_) * 1e-6;
}
DefDbu
LefDefNetwork::metersToDbu(double dist) const
{
return round((dist * 1e6) * def_units_);
}
void
LefDefNetwork::setDefFilename(const char *filename)
{
def_filename_ = stringCopy(filename);
}
void
LefDefNetwork::setManufacturingGrid(double grid)
{
manufacturing_grid_ = grid;
}
Library *
LefDefNetwork::makeLefLibrary(const char *name,
const char *filename)
{
lef_library_ = ConcreteNetwork::makeLibrary(name, filename);
return lef_library_;
}
void
LefDefNetwork::setLefMacro(Cell *cell,
lefiMacro *lef_macro)
{
lef_macro_map_[cell] = lef_macro;
}
lefiMacro *
LefDefNetwork::lefMacro(Cell *cell) const
{
return lef_macro_map_.findKey(cell);
}
Cell *
LefDefNetwork::lefCell(LibertyCell *cell)
{
return findCell(lef_library_, cell->name());
}
bool
LefDefNetwork::isLefCell(Cell *cell) const
{
return library(cell) == lef_library_;
}
////////////////////////////////////////////////////////////////
void
LefDefNetwork::setDieArea(DefDbu die_lx,
DefDbu die_ly,
DefDbu die_ux,
DefDbu die_uy)
{
die_lx_ = die_lx;
die_ly_ = die_ly;
die_ux_ = die_ux;
die_uy_ = die_uy;
}
void
LefDefNetwork::dieArea(// Return values.
DefDbu &die_lx,
DefDbu &die_ly,
DefDbu &die_ux,
DefDbu &die_uy)
{
die_lx = die_lx_;
die_ly = die_ly_;
die_ux = die_ux_;
die_uy = die_uy_;
}
void
LefDefNetwork::initTopInstancePins()
{
ConcreteInstance *ctop_inst = reinterpret_cast<ConcreteInstance*>(top_instance_);
ctop_inst->initPins();
}
Instance *
LefDefNetwork::makeDefComponent(Cell *cell,
const char *name,
defiComponent *def_component)
{
Instance *inst = makeInstance(cell, name, top_instance_);
if (def_component)
def_component_map_[inst] = def_component;
return inst;
}
defiComponent *
LefDefNetwork::defComponent(Instance *inst) const
{
return def_component_map_.findKey(inst);
}
void
LefDefNetwork::setLocation(Instance *instance,
DefPt location)
{
defiComponent *def_component = defComponent(instance);
if (def_component == nullptr) {
def_component = new defiComponent(nullptr);
def_component_map_[instance] = def_component;
}
def_component->setPlacementStatus(DEFI_COMPONENT_PLACED);
def_component->setPlacementLocation(location.x(), location.y(), 0);
}
DefPt
LefDefNetwork::location(const Pin *pin) const
{
Instance *inst = instance(pin);
defiComponent *def_component = def_component_map_.findKey(inst);
if (def_component
&& def_component->isPlaced()) {
// Component location is good enough for now.
return DefPt(def_component->placementX(),
def_component->placementY());
}
else if (isTopLevelPort(pin)) {
Port *port = this->port(pin);
DefPt location;
bool exists;
port_locations_.findKey(port, location, exists);
if (exists)
return location;
}
return DefPt(0, 0);
}
void
LefDefNetwork::setLocation(Port *port,
DefPt location)
{
port_locations_[port] = location;
}
bool
LefDefNetwork::isPlaced(const Pin *pin) const
{
Instance *inst = instance(pin);
if (inst == top_instance_)
return port_locations_.hasKey(port(pin));
else {
defiComponent *def_component = defComponent(inst);
return def_component
&& def_component->isPlaced();
}
}
Instance *
LefDefNetwork::findInstance(const char *path_name) const
{
return findChild(top_instance_, path_name);
}
Net *
LefDefNetwork::findNet(const char *path_name) const
{
return findNet(top_instance_, path_name);
}
////////////////////////////////////////////////////////////////
void
LefDefNetwork::makeLefSite(lefiSite *site)
{
lefiSite *copy = new lefiSite(*site);
lef_size_map_[copy->name()] = copy;
}
lefiSite *
LefDefNetwork::findLefSite(const char *name)
{
return lef_size_map_.findKey(name);
}
////////////////////////////////////////////////////////////////
void
LefDefNetwork::makeLefLayer(lefiLayer *layer)
{
lef_layers_.push_back(*layer);
}
////////////////////////////////////////////////////////////////
double
LefDefNetwork::designArea()
{
double design_area = 0.0;
LeafInstanceIterator *leaf_iter = leafInstanceIterator();
while (leaf_iter->hasNext()) {
Instance *leaf = leaf_iter->next();
design_area += area(leaf);
}
delete leaf_iter;
return design_area;
}
double
LefDefNetwork::area(Instance *inst) const
{
return area(cell(inst));
}
double
LefDefNetwork::area(Cell *cell) const
{
const char *cell_name = name(cell);
if (lef_library_) {
Cell *lef_cell = findCell(lef_library_, cell_name);
if (lef_cell) {
lefiMacro *lef_macro = lefMacro(lef_cell);
if (lef_macro && lef_macro->hasSize())
return lef_macro->sizeX() * 1e-6 * lef_macro->sizeY() * 1e-6;
}
}
return 0.0;
}
////////////////////////////////////////////////////////////////
DefPt::DefPt(int x,
int y) :
x_(x),
y_(y)
{
}
DefPt::DefPt() :
x_(0),
y_(0)
{
}
} // namespace