forked from The-OpenROAD-Project/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSdcGraph.cc
397 lines (358 loc) · 10.3 KB
/
SdcGraph.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2022, 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 "Stats.hh"
#include "PortDirection.hh"
#include "Network.hh"
#include "Graph.hh"
#include "DisabledPorts.hh"
#include "PortDelay.hh"
#include "ClockLatency.hh"
#include "Sdc.hh"
namespace sta {
static void
annotateGraphDisabledWireEdge(Pin *from_pin,
Pin *to_pin,
Graph *graph);
// Annotate constraints to the timing graph.
void
Sdc::annotateGraph()
{
Stats stats(debug_, report_);
// All output pins are considered constrained because
// they may be downstream from a set_min/max_delay -from that
// does not have a set_output_delay.
annotateGraphConstrainOutputs();
annotateDisables();
annotateGraphOutputDelays();
annotateGraphDataChecks();
annotateHierClkLatency();
stats.report("Annotate constraints to graph");
}
void
Sdc::annotateGraphConstrainOutputs()
{
Instance *top_inst = network_->topInstance();
InstancePinIterator *pin_iter = network_->pinIterator(top_inst);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
if (network_->direction(pin)->isAnyOutput())
annotateGraphConstrained(pin);
}
delete pin_iter;
}
void
Sdc::annotateDisables()
{
PinSet::Iterator pin_iter(disabled_pins_);
while (pin_iter.hasNext()) {
Pin *pin = pin_iter.next();
annotateGraphDisabled(pin);
}
if (!disabled_lib_ports_.empty()) {
VertexIterator vertex_iter(graph_);
while (vertex_iter.hasNext()) {
Vertex *vertex = vertex_iter.next();
Pin *pin = vertex->pin();
LibertyPort *port = network_->libertyPort(pin);
if (disabled_lib_ports_.hasKey(port))
annotateGraphDisabled(pin);
}
}
Instance *top_inst = network_->topInstance();
PortSet::Iterator port_iter(disabled_ports_);
while (port_iter.hasNext()) {
Port *port = port_iter.next();
Pin *pin = network_->findPin(top_inst, port);
annotateGraphDisabled(pin);
}
PinPairSet::Iterator pair_iter(disabled_wire_edges_);
while (pair_iter.hasNext()) {
PinPair *pair = pair_iter.next();
annotateGraphDisabledWireEdge(pair->first, pair->second, graph_);
}
EdgeSet::Iterator edge_iter(disabled_edges_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
edge->setIsDisabledConstraint(true);
}
DisabledInstancePortsMap::Iterator disable_inst_iter(disabled_inst_ports_);
while (disable_inst_iter.hasNext()) {
DisabledInstancePorts *disabled_inst = disable_inst_iter.next();
setEdgeDisabledInstPorts(disabled_inst);
}
}
class DisableHpinEdgeVisitor : public HierPinThruVisitor
{
public:
DisableHpinEdgeVisitor(Graph *graph);
virtual void visit(Pin *from_pin,
Pin *to_pin);
protected:
bool annotate_;
Graph *graph_;
private:
DISALLOW_COPY_AND_ASSIGN(DisableHpinEdgeVisitor);
};
DisableHpinEdgeVisitor::DisableHpinEdgeVisitor(Graph *graph) :
HierPinThruVisitor(),
graph_(graph)
{
}
void
DisableHpinEdgeVisitor::visit(Pin *from_pin,
Pin *to_pin)
{
annotateGraphDisabledWireEdge(from_pin, to_pin, graph_);
}
static void
annotateGraphDisabledWireEdge(Pin *from_pin,
Pin *to_pin,
Graph *graph)
{
Vertex *from_vertex = graph->pinDrvrVertex(from_pin);
Vertex *to_vertex = graph->pinLoadVertex(to_pin);
if (from_vertex && to_vertex) {
VertexOutEdgeIterator edge_iter(from_vertex, graph);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
if (edge->isWire()
&& edge->to(graph) == to_vertex)
edge->setIsDisabledConstraint(true);
}
}
}
void
Sdc::annotateGraphDisabled(const Pin *pin)
{
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
vertex->setIsDisabledConstraint(true);
if (bidirect_drvr_vertex)
bidirect_drvr_vertex->setIsDisabledConstraint(true);
}
void
Sdc::setEdgeDisabledInstPorts(DisabledInstancePorts *disabled_inst)
{
setEdgeDisabledInstPorts(disabled_inst, disabled_inst->instance());
}
void
Sdc::setEdgeDisabledInstPorts(DisabledPorts *disabled_port,
Instance *inst)
{
if (disabled_port->all()) {
InstancePinIterator *pin_iter = network_->pinIterator(inst);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
// set_disable_timing instance does not disable timing checks.
setEdgeDisabledInstFrom(pin, false);
}
delete pin_iter;
}
// Disable from pins.
LibertyPortSet::Iterator from_iter(disabled_port->from());
while (from_iter.hasNext()) {
LibertyPort *from_port = from_iter.next();
Pin *from_pin = network_->findPin(inst, from_port);
if (from_pin)
setEdgeDisabledInstFrom(from_pin, true);
}
// Disable to pins.
LibertyPortSet::Iterator to_iter(disabled_port->to());
while (to_iter.hasNext()) {
LibertyPort *to_port = to_iter.next();
Pin *to_pin = network_->findPin(inst, to_port);
if (to_pin) {
if (network_->direction(to_pin)->isAnyOutput()) {
Vertex *vertex = graph_->pinDrvrVertex(to_pin);
if (vertex) {
VertexInEdgeIterator edge_iter(vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
edge->setIsDisabledConstraint(true);
}
}
}
}
}
// Disable from/to pins.
LibertyPortPairSet::Iterator from_to_iter(disabled_port->fromTo());
while (from_to_iter.hasNext()) {
LibertyPortPair *pair = from_to_iter.next();
const LibertyPort *from_port = pair->first;
const LibertyPort *to_port = pair->second;
Pin *from_pin = network_->findPin(inst, from_port);
Pin *to_pin = network_->findPin(inst, to_port);
if (from_pin && network_->direction(from_pin)->isAnyInput()
&& to_pin) {
Vertex *from_vertex = graph_->pinLoadVertex(from_pin);
Vertex *to_vertex = graph_->pinDrvrVertex(to_pin);
if (from_vertex && to_vertex) {
VertexOutEdgeIterator edge_iter(from_vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
if (edge->to(graph_) == to_vertex)
edge->setIsDisabledConstraint(true);
}
}
}
}
}
void
Sdc::setEdgeDisabledInstFrom(Pin *from_pin,
bool disable_checks)
{
if (network_->direction(from_pin)->isAnyInput()) {
Vertex *from_vertex = graph_->pinLoadVertex(from_pin);
if (from_vertex) {
VertexOutEdgeIterator edge_iter(from_vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
if (disable_checks
|| !edge->role()->isTimingCheck())
edge->setIsDisabledConstraint(true);
}
}
}
}
void
Sdc::annotateGraphOutputDelays()
{
for (OutputDelay *output_delay : output_delays_) {
for (Pin *lpin : output_delay->leafPins())
annotateGraphConstrained(lpin);
}
}
void
Sdc::annotateGraphDataChecks()
{
DataChecksMap::Iterator data_checks_iter(data_checks_to_map_);
while (data_checks_iter.hasNext()) {
DataCheckSet *checks = data_checks_iter.next();
DataCheckSet::Iterator check_iter(checks);
// There may be multiple data checks on a single pin,
// but we only need to mark it as constrained once.
if (check_iter.hasNext()) {
DataCheck *check = check_iter.next();
annotateGraphConstrained(check->to());
}
}
}
void
Sdc::annotateGraphConstrained(const PinSet *pins)
{
PinSet::ConstIterator pin_iter(pins);
while (pin_iter.hasNext()) {
const Pin *pin = pin_iter.next();
annotateGraphConstrained(pin);
}
}
void
Sdc::annotateGraphConstrained(const InstanceSet *insts)
{
InstanceSet::ConstIterator inst_iter(insts);
while (inst_iter.hasNext()) {
const Instance *inst = inst_iter.next();
annotateGraphConstrained(inst);
}
}
void
Sdc::annotateGraphConstrained(const Instance *inst)
{
InstancePinIterator *pin_iter = network_->pinIterator(inst);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
if (network_->direction(pin)->isAnyInput())
annotateGraphConstrained(pin);
}
delete pin_iter;
}
void
Sdc::annotateGraphConstrained(const Pin *pin)
{
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
// Pin may be hierarchical and have no vertex.
if (vertex)
vertex->setIsConstrained(true);
if (bidirect_drvr_vertex)
bidirect_drvr_vertex->setIsConstrained(true);
}
void
Sdc::annotateHierClkLatency()
{
ClockLatencies::Iterator latency_iter(clk_latencies_);
while (latency_iter.hasNext()) {
ClockLatency *latency = latency_iter.next();
const Pin *pin = latency->pin();
if (pin && network_->isHierarchical(pin))
annotateHierClkLatency(pin, latency);
}
}
void
Sdc::annotateHierClkLatency(const Pin *hpin,
ClockLatency *latency)
{
EdgesThruHierPinIterator edge_iter(hpin, network_, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
edge_clk_latency_[edge] = latency;
}
}
ClockLatency *
Sdc::clockLatency(Edge *edge) const
{
return edge_clk_latency_.findKey(edge);
}
void
Sdc::clockLatency(Edge *edge,
const RiseFall *rf,
const MinMax *min_max,
// Return values.
float &latency,
bool &exists) const
{
ClockLatency *latencies = edge_clk_latency_.findKey(edge);
if (latencies)
latencies->delay(rf, min_max, latency, exists);
else {
latency = 0.0;
exists = false;
}
}
////////////////////////////////////////////////////////////////
void
Sdc::removeGraphAnnotations()
{
VertexIterator vertex_iter(graph_);
while (vertex_iter.hasNext()) {
Vertex *vertex = vertex_iter.next();
vertex->setIsDisabledConstraint(false);
vertex->setIsConstrained(false);
VertexOutEdgeIterator edge_iter(vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
edge->setIsDisabledConstraint(false);
}
}
edge_clk_latency_.clear();
}
void
Sdc::searchPreamble()
{
ensureClkHpinDisables();
ensureClkGroupExclusions();
}
} // namespace