forked from The-OpenROAD-Project/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisitPathGroupVertices.cc
313 lines (283 loc) · 8.88 KB
/
VisitPathGroupVertices.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
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2023, 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 "VisitPathGroupVertices.hh"
#include "Debug.hh"
#include "Graph.hh"
#include "Bfs.hh"
#include "Search.hh"
#include "PathVertex.hh"
#include "PathEnd.hh"
#include "Tag.hh"
#include "VisitPathEnds.hh"
namespace sta {
typedef Set<PathVertex*, PathLess> PathVertexSet;
typedef Map<Vertex*, PathVertexSet*> VertexPathSetMap;
static void
vertexPathSetMapInsertPath(VertexPathSetMap *matching_path_map,
Vertex *vertex,
Tag *tag,
int arrival_index,
const StaState *sta);
// Visit each path end for a vertex and add the worst one in each
// path group to the group.
class VisitPathGroupEnds : public PathEndVisitor
{
public:
VisitPathGroupEnds(PathGroup *path_group,
VertexVisitor *vertex_visitor,
VertexPathSetMap *matching_path_map,
BfsBkwdIterator *bkwd_iter,
StaState *sta);
VisitPathGroupEnds(const VisitPathGroupEnds&) = default;
virtual PathEndVisitor *copy() const;
virtual void visit(PathEnd *path_end);
virtual void vertexBegin(Vertex *vertex);
virtual void vertexEnd(Vertex *vertex);
private:
PathGroup *path_group_;
VertexVisitor *vertex_visitor_;
BfsBkwdIterator *bkwd_iter_;
VertexPathSetMap *matching_path_map_;
bool vertex_matches_;
StaState *sta_;
};
class PathGroupPathVisitor : public PathVisitor
{
public:
PathGroupPathVisitor(VertexVisitor *visitor,
BfsBkwdIterator *bkwd_iter,
VertexPathSetMap *matching_path_map,
const StaState *sta);
virtual ~PathGroupPathVisitor();
virtual VertexVisitor *copy() const;
virtual void visit(Vertex *vertex);
protected:
// Return false to stop visiting.
virtual bool visitFromToPath(const Pin *from_pin,
Vertex *from_vertex,
const RiseFall *from_rf,
Tag *from_tag,
PathVertex *from_path,
Edge *edge,
TimingArc *arc,
ArcDelay arc_delay,
Vertex *to_vertex,
const RiseFall *to_rf,
Tag *to_tag,
Arrival &to_arrival,
const MinMax *min_max,
const PathAnalysisPt *path_ap);
void fromMatches(Vertex *from_vertex,
Tag *from_tag,
int from_arrival_index);
private:
VertexVisitor *visitor_;
BfsBkwdIterator *bkwd_iter_;
VertexPathSetMap *matching_path_map_;
bool vertex_matches_;
};
////////////////////////////////////////////////////////////////
// Visit the fanin vertices for the path group.
// Vertices in the clock network are NOT visited.
void
visitPathGroupVertices(PathGroup *path_group,
VertexVisitor *visitor,
StaState *sta)
{
Search *search = sta->search();
VertexPathSetMap matching_path_map;
// Do not visit clock network.
SearchPredNonReg2 srch_non_reg(sta);
BfsBkwdIterator bkwd_iter(BfsIndex::other, &srch_non_reg, sta);
// Visit the path ends and filter by path_group to seed the backward search.
VisitPathGroupEnds end_visitor(path_group, visitor, &matching_path_map,
&bkwd_iter, sta);
VisitPathEnds visit_path_ends(sta);
for(Vertex *vertex : *search->endpoints())
visit_path_ends.visitPathEnds(vertex, &end_visitor);
// Search backward from the path ends thru vertices that have arrival tags
// that match path_group end paths.
PathGroupPathVisitor path_visitor(visitor, &bkwd_iter, &matching_path_map,
sta);
bkwd_iter.visit(0, &path_visitor);
// Cleanup.
VertexPathSetMap::Iterator matching_iter(matching_path_map);
while (matching_iter.hasNext()) {
PathVertexSet *paths = matching_iter.next();
PathVertexSet::Iterator path_iter(paths);
while (path_iter.hasNext()) {
PathVertex *path = path_iter.next();
delete path;
}
delete paths;
}
}
////////////////////////////////////////////////////////////////
VisitPathGroupEnds::VisitPathGroupEnds(PathGroup *path_group,
VertexVisitor *vertex_visitor,
VertexPathSetMap *matching_path_map,
BfsBkwdIterator *bkwd_iter,
StaState *sta) :
path_group_(path_group),
vertex_visitor_(vertex_visitor),
bkwd_iter_(bkwd_iter),
matching_path_map_(matching_path_map),
sta_(sta)
{
}
PathEndVisitor *
VisitPathGroupEnds::copy() const
{
return new VisitPathGroupEnds(*this);
}
void
VisitPathGroupEnds::vertexBegin(Vertex *)
{
vertex_matches_ = false;
}
void
VisitPathGroupEnds::visit(PathEnd *path_end)
{
PathGroup *group = sta_->search()->pathGroup(path_end);
if (group == path_group_) {
PathRef path(path_end->pathRef());
Vertex *vertex = path.vertex(sta_);
int arrival_index;
bool arrival_exists;
path.arrivalIndex(arrival_index, arrival_exists);
vertexPathSetMapInsertPath(matching_path_map_, vertex, path.tag(sta_),
arrival_index, sta_);
vertex_matches_ = true;
}
}
static void
vertexPathSetMapInsertPath(VertexPathSetMap *matching_path_map,
Vertex *vertex,
Tag *tag,
int arrival_index,
const StaState *sta)
{
PathVertexSet *matching_paths = matching_path_map->findKey(vertex);
if (matching_paths == nullptr) {
PathLess path_less(sta);
matching_paths = new PathVertexSet(path_less);
(*matching_path_map)[vertex] = matching_paths;
}
PathVertex *vpath = new PathVertex(vertex, tag, arrival_index);
matching_paths->insert(vpath);
}
void
VisitPathGroupEnds::vertexEnd(Vertex *vertex)
{
if (vertex_matches_) {
vertex_visitor_->visit(vertex);
// Seed backward bfs fanin search.
bkwd_iter_->enqueueAdjacentVertices(vertex);
}
}
////////////////////////////////////////////////////////////////
PathGroupPathVisitor::PathGroupPathVisitor(VertexVisitor *visitor,
BfsBkwdIterator *bkwd_iter,
VertexPathSetMap *matching_path_map,
const StaState *sta) :
PathVisitor(sta),
visitor_(visitor),
bkwd_iter_(bkwd_iter),
matching_path_map_(matching_path_map)
{
}
PathGroupPathVisitor::~PathGroupPathVisitor()
{
}
VertexVisitor *
PathGroupPathVisitor::copy() const
{
return new PathGroupPathVisitor(visitor_, bkwd_iter_,
matching_path_map_, this);
}
void
PathGroupPathVisitor::visit(Vertex *vertex)
{
vertex_matches_ = false;
visitFanoutPaths(vertex);
if (vertex_matches_) {
debugPrint(debug_, "visit_path_group", 1, "visit %s",
vertex->name(network_));
visitor_->visit(vertex);
bkwd_iter_->enqueueAdjacentVertices(vertex);
}
}
bool
PathGroupPathVisitor::visitFromToPath(const Pin *,
Vertex *from_vertex,
const RiseFall *,
Tag *from_tag,
PathVertex *from_path,
Edge *,
TimingArc *,
ArcDelay ,
Vertex *to_vertex,
const RiseFall *to_rf,
Tag *to_tag,
Arrival &,
const MinMax *,
const PathAnalysisPt *path_ap)
{
PathVertexSet *matching_paths = matching_path_map_->findKey(to_vertex);
if (matching_paths) {
int arrival_index;
bool arrival_exists;
from_path->arrivalIndex(arrival_index, arrival_exists);
PathVertex to_path(to_vertex, to_tag, this);
if (!to_path.isNull()) {
if (matching_paths->hasKey(&to_path)) {
debugPrint(debug_, "visit_path_group", 2, "match %s %s -> %s %s",
from_vertex->name(network_),
from_tag->asString(this),
to_vertex->name(network_),
to_tag->asString(this));
fromMatches(from_vertex, from_tag, arrival_index);
}
}
else {
VertexPathIterator to_iter(to_vertex, to_rf, path_ap, this);
while (to_iter.hasNext()) {
PathVertex *to_path = to_iter.next();
if (tagMatchNoCrpr(to_path->tag(this), to_tag)
&& matching_paths->hasKey(to_path)) {
debugPrint(debug_, "visit_path_group", 2,
"match crpr %s %s -> %s %s",
from_vertex->name(network_),
from_tag->asString(this),
to_vertex->name(network_),
to_tag->asString(this));
fromMatches(from_vertex, from_tag, arrival_index);
}
}
}
}
return true;
}
void
PathGroupPathVisitor::fromMatches(Vertex *from_vertex,
Tag *from_tag,
int from_arrival_index)
{
vertex_matches_ = true;
vertexPathSetMapInsertPath(matching_path_map_, from_vertex,
from_tag, from_arrival_index, this);
}
} // namespace