forked from The-OpenROAD-Project/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.cc
4039 lines (3759 loc) · 113 KB
/
Search.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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 "Search.hh"
#include <algorithm>
#include <cmath> // abs
#include "Mutex.hh"
#include "Report.hh"
#include "Debug.hh"
#include "Stats.hh"
#include "Fuzzy.hh"
#include "TimingRole.hh"
#include "FuncExpr.hh"
#include "TimingArc.hh"
#include "Sequential.hh"
#include "Units.hh"
#include "Liberty.hh"
#include "Network.hh"
#include "PortDirection.hh"
#include "Graph.hh"
#include "GraphCmp.hh"
#include "PortDelay.hh"
#include "Clock.hh"
#include "CycleAccting.hh"
#include "ExceptionPath.hh"
#include "DataCheck.hh"
#include "Sdc.hh"
#include "DcalcAnalysisPt.hh"
#include "SearchPred.hh"
#include "Levelize.hh"
#include "Bfs.hh"
#include "Corner.hh"
#include "Sim.hh"
#include "PathVertex.hh"
#include "PathVertexRep.hh"
#include "PathRef.hh"
#include "ClkInfo.hh"
#include "Tag.hh"
#include "TagGroup.hh"
#include "PathEnd.hh"
#include "PathGroup.hh"
#include "PathAnalysisPt.hh"
#include "VisitPathEnds.hh"
#include "GatedClk.hh"
#include "WorstSlack.hh"
#include "Latches.hh"
#include "Crpr.hh"
#include "Genclks.hh"
namespace sta {
using std::min;
using std::max;
using std::abs;
////////////////////////////////////////////////////////////////
EvalPred::EvalPred(const StaState *sta) :
SearchPred0(sta),
search_thru_latches_(true)
{
}
void
EvalPred::setSearchThruLatches(bool thru_latches)
{
search_thru_latches_ = thru_latches;
}
bool
EvalPred::searchThru(Edge *edge)
{
const Sdc *sdc = sta_->sdc();
TimingRole *role = edge->role();
return SearchPred0::searchThru(edge)
&& (sdc->dynamicLoopBreaking()
|| !edge->isDisabledLoop())
&& !role->isTimingCheck()
&& (search_thru_latches_
|| role != TimingRole::latchDtoQ()
|| sta_->latches()->latchDtoQState(edge) == LatchEnableState::open);
}
bool
EvalPred::searchTo(const Vertex *to_vertex)
{
const Sdc *sdc = sta_->sdc();
const Pin *pin = to_vertex->pin();
return SearchPred0::searchTo(to_vertex)
&& !(sdc->isLeafPinClock(pin)
&& !sdc->isPathDelayInternalEndpoint(pin));
}
////////////////////////////////////////////////////////////////
DynLoopSrchPred::DynLoopSrchPred(TagGroupBldr *tag_bldr) :
tag_bldr_(tag_bldr)
{
}
bool
DynLoopSrchPred::loopEnabled(Edge *edge,
const Sdc *sdc,
const Graph *graph,
Search *search)
{
return !edge->isDisabledLoop()
|| (sdc->dynamicLoopBreaking()
&& hasPendingLoopPaths(edge, graph, search));
}
bool
DynLoopSrchPred::hasPendingLoopPaths(Edge *edge,
const Graph *graph,
Search *search)
{
if (tag_bldr_
&& tag_bldr_->hasLoopTag()) {
Corners *corners = search->corners();
Vertex *from_vertex = edge->from(graph);
TagGroup *prev_tag_group = search->tagGroup(from_vertex);
ArrivalMap::Iterator arrival_iter(tag_bldr_->arrivalMap());
while (arrival_iter.hasNext()) {
Tag *from_tag;
int arrival_index;
arrival_iter.next(from_tag, arrival_index);
if (from_tag->isLoop()) {
// Loop false path exceptions apply to rise/fall edges so to_rf
// does not matter.
PathAPIndex path_ap_index = from_tag->pathAPIndex();
PathAnalysisPt *path_ap = corners->findPathAnalysisPt(path_ap_index);
Tag *to_tag = search->thruTag(from_tag, edge, RiseFall::rise(),
path_ap->pathMinMax(), path_ap);
if (to_tag
&& (prev_tag_group == nullptr
|| !prev_tag_group->hasTag(from_tag)))
return true;
}
}
}
return false;
}
// EvalPred unless
// latch D->Q edge
class SearchThru : public EvalPred, public DynLoopSrchPred
{
public:
SearchThru(TagGroupBldr *tag_bldr,
const StaState *sta);
virtual bool searchThru(Edge *edge);
};
SearchThru::SearchThru(TagGroupBldr *tag_bldr,
const StaState *sta) :
EvalPred(sta),
DynLoopSrchPred(tag_bldr)
{
}
bool
SearchThru::searchThru(Edge *edge)
{
const Graph *graph = sta_->graph();
const Sdc *sdc = sta_->sdc();
Search *search = sta_->search();
return EvalPred::searchThru(edge)
// Only search thru latch D->Q if it is always open.
// Enqueue thru latches is handled explicitly by search.
&& (edge->role() != TimingRole::latchDtoQ()
|| sta_->latches()->latchDtoQState(edge) == LatchEnableState::open)
&& loopEnabled(edge, sdc, graph, search);
}
ClkArrivalSearchPred::ClkArrivalSearchPred(const StaState *sta) :
EvalPred(sta)
{
}
bool
ClkArrivalSearchPred::searchThru(Edge *edge)
{
const TimingRole *role = edge->role();
return (role->isWire()
|| role == TimingRole::combinational())
&& EvalPred::searchThru(edge);
}
////////////////////////////////////////////////////////////////
Search::Search(StaState *sta) :
StaState(sta)
{
init(sta);
}
void
Search::init(StaState *sta)
{
initVars();
search_adj_ = new SearchThru(nullptr, sta);
eval_pred_ = new EvalPred(sta);
check_crpr_ = new CheckCrpr(sta);
genclks_ = new Genclks(sta);
arrival_visitor_ = new ArrivalVisitor(sta);
clk_arrivals_valid_ = false;
arrivals_exist_ = false;
arrivals_at_endpoints_exist_ = false;
arrivals_seeded_ = false;
requireds_exist_ = false;
requireds_seeded_ = false;
invalid_arrivals_ = new VertexSet(graph_);
invalid_requireds_ = new VertexSet(graph_);
invalid_tns_ = new VertexSet(graph_);
tns_exists_ = false;
worst_slacks_ = nullptr;
arrival_iter_ = new BfsFwdIterator(BfsIndex::arrival, nullptr, sta);
required_iter_ = new BfsBkwdIterator(BfsIndex::required, search_adj_, sta);
tag_capacity_ = 127;
tag_set_ = new TagSet(tag_capacity_);
clk_info_set_ = new ClkInfoSet(ClkInfoLess(sta));
tag_next_ = 0;
tags_ = new Tag*[tag_capacity_];
tag_group_capacity_ = 127;
tag_groups_ = new TagGroup*[tag_group_capacity_];
tag_group_next_ = 0;
tag_group_set_ = new TagGroupSet(tag_group_capacity_);
pending_latch_outputs_ = new VertexSet(graph_);
visit_path_ends_ = new VisitPathEnds(this);
gated_clk_ = new GatedClk(this);
path_groups_ = nullptr;
endpoints_ = nullptr;
invalid_endpoints_ = nullptr;
filter_ = nullptr;
filter_from_ = nullptr;
filter_to_ = nullptr;
filtered_arrivals_ = new VertexSet(graph_);
found_downstream_clk_pins_ = false;
}
// Init "options".
void
Search::initVars()
{
unconstrained_paths_ = false;
crpr_path_pruning_enabled_ = true;
crpr_approx_missing_requireds_ = true;
}
Search::~Search()
{
deletePaths();
deleteTags();
delete tag_set_;
delete clk_info_set_;
delete [] tags_;
delete [] tag_groups_;
delete tag_group_set_;
delete search_adj_;
delete eval_pred_;
delete arrival_visitor_;
delete arrival_iter_;
delete required_iter_;
delete endpoints_;
delete invalid_arrivals_;
delete invalid_requireds_;
delete invalid_tns_;
delete invalid_endpoints_;
delete pending_latch_outputs_;
delete visit_path_ends_;
delete gated_clk_;
delete worst_slacks_;
delete check_crpr_;
delete genclks_;
delete filtered_arrivals_;
deleteFilter();
deletePathGroups();
}
void
Search::clear()
{
initVars();
clk_arrivals_valid_ = false;
arrivals_at_endpoints_exist_ = false;
arrivals_seeded_ = false;
requireds_exist_ = false;
requireds_seeded_ = false;
tns_exists_ = false;
clearWorstSlack();
invalid_arrivals_->clear();
arrival_iter_->clear();
invalid_requireds_->clear();
invalid_tns_->clear();
required_iter_->clear();
endpointsInvalid();
deletePathGroups();
deletePaths();
deleteTags();
clearPendingLatchOutputs();
deleteFilter();
genclks_->clear();
found_downstream_clk_pins_ = false;
}
bool
Search::crprPathPruningEnabled() const
{
return crpr_path_pruning_enabled_;
}
void
Search::setCrprpathPruningEnabled(bool enabled)
{
crpr_path_pruning_enabled_ = enabled;
}
bool
Search::crprApproxMissingRequireds() const
{
return crpr_approx_missing_requireds_;
}
void
Search::setCrprApproxMissingRequireds(bool enabled)
{
crpr_approx_missing_requireds_ = enabled;
}
void
Search::deleteTags()
{
for (TagGroupIndex i = 0; i < tag_group_next_; i++) {
TagGroup *group = tag_groups_[i];
delete group;
}
tag_group_next_ = 0;
tag_group_set_->clear();
tag_group_free_indices_.clear();
tag_next_ = 0;
tag_set_->deleteContentsClear();
tag_free_indices_.clear();
clk_info_set_->deleteContentsClear();
}
void
Search::deleteFilter()
{
if (filter_) {
sdc_->deleteException(filter_);
filter_ = nullptr;
filter_from_ = nullptr;
}
else {
// Filter owns filter_from_ if it exists.
delete filter_from_;
filter_from_ = nullptr;
}
delete filter_to_;
filter_to_ = nullptr;
}
void
Search::copyState(const StaState *sta)
{
StaState::copyState(sta);
// Notify sub-components.
arrival_iter_->copyState(sta);
required_iter_->copyState(sta);
arrival_visitor_->copyState(sta);
visit_path_ends_->copyState(sta);
gated_clk_->copyState(sta);
check_crpr_->copyState(sta);
genclks_->copyState(sta);
}
////////////////////////////////////////////////////////////////
void
Search::deletePaths()
{
debugPrint(debug_, "search", 1, "delete paths");
if (arrivals_exist_) {
VertexIterator vertex_iter(graph_);
while (vertex_iter.hasNext()) {
Vertex *vertex = vertex_iter.next();
vertex->deletePaths();
}
filtered_arrivals_->clear();
graph_->clearArrivals();
graph_->clearPrevPaths();
arrivals_exist_ = false;
}
}
void
Search::deletePaths(Vertex *vertex)
{
tnsNotifyBefore(vertex);
if (worst_slacks_)
worst_slacks_->worstSlackNotifyBefore(vertex);
vertex->deletePaths();
}
////////////////////////////////////////////////////////////////
// from/thrus/to are owned and deleted by Search.
// Returned sequence is owned by the caller.
// PathEnds are owned by Search PathGroups and deleted on next call.
PathEndSeq
Search::findPathEnds(ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
bool unconstrained,
const Corner *corner,
const MinMaxAll *min_max,
int group_count,
int endpoint_count,
bool unique_pins,
float slack_min,
float slack_max,
bool sort_by_slack,
PathGroupNameSet *group_names,
bool setup,
bool hold,
bool recovery,
bool removal,
bool clk_gating_setup,
bool clk_gating_hold)
{
findFilteredArrivals(from, thrus, to, unconstrained, true);
if (!sdc_->recoveryRemovalChecksEnabled())
recovery = removal = false;
if (!sdc_->gatedClkChecksEnabled())
clk_gating_setup = clk_gating_hold = false;
path_groups_ = makePathGroups(group_count, endpoint_count, unique_pins,
slack_min, slack_max,
group_names, setup, hold,
recovery, removal,
clk_gating_setup, clk_gating_hold);
ensureDownstreamClkPins();
PathEndSeq path_ends = path_groups_->makePathEnds(to, unconstrained_paths_,
corner, min_max,
sort_by_slack);
sdc_->reportClkToClkMaxCycleWarnings();
return path_ends;
}
void
Search::findFilteredArrivals(ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
bool unconstrained,
bool thru_latches)
{
unconstrained_paths_ = unconstrained;
// Delete results from last findPathEnds.
// Filtered arrivals are deleted by Sta::searchPreamble.
deletePathGroups();
checkFromThrusTo(from, thrus, to);
filter_from_ = from;
filter_to_ = to;
if ((from
&& (from->pins()
|| from->instances()))
|| thrus) {
filter_ = sdc_->makeFilterPath(from, thrus, nullptr);
findFilteredArrivals(thru_latches);
}
else
// These cases do not require filtered arrivals.
// -from clocks
// -to
findAllArrivals(thru_latches);
}
// From/thrus/to are used to make a filter exception. If the last
// search used a filter arrival/required times were only found for a
// subset of the paths. Delete the paths that have a filter
// exception state.
void
Search::deleteFilteredArrivals()
{
if (filter_) {
ExceptionFrom *from = filter_->from();
ExceptionThruSeq *thrus = filter_->thrus();
if ((from
&& (from->pins()
|| from->instances()))
|| thrus) {
for (Vertex *vertex : *filtered_arrivals_) {
deletePaths(vertex);
arrivalInvalid(vertex);
requiredInvalid(vertex);
}
bool check_filter_arrivals = false;
if (check_filter_arrivals) {
VertexIterator vertex_iter(graph_);
while (vertex_iter.hasNext()) {
Vertex *vertex = vertex_iter.next();
TagGroup *tag_group = tagGroup(vertex);
if (tag_group
&& tag_group->hasFilterTag())
filtered_arrivals_->erase(vertex);
}
if (!filtered_arrivals_->empty()) {
report_->reportLine("Filtered verticies mismatch");
for (Vertex *vertex : *filtered_arrivals_)
report_->reportLine(" %s", vertex->name(network_));
}
}
filtered_arrivals_->clear();
deleteFilterTagGroups();
deleteFilterClkInfos();
deleteFilterTags();
}
deleteFilter();
}
}
void
Search::deleteFilterTagGroups()
{
for (TagGroupIndex i = 0; i < tag_group_next_; i++) {
TagGroup *group = tag_groups_[i];
if (group
&& group->hasFilterTag()) {
tag_group_set_->erase(group);
tag_groups_[group->index()] = nullptr;
tag_group_free_indices_.push_back(i);
delete group;
}
}
}
void
Search::deleteFilterTags()
{
for (TagIndex i = 0; i < tag_next_; i++) {
Tag *tag = tags_[i];
if (tag
&& tag->isFilter()) {
tags_[i] = nullptr;
tag_set_->erase(tag);
delete tag;
tag_free_indices_.push_back(i);
}
}
}
void
Search::deleteFilterClkInfos()
{
ClkInfoSet::Iterator clk_info_iter(clk_info_set_);
while (clk_info_iter.hasNext()) {
ClkInfo *clk_info = clk_info_iter.next();
if (clk_info->refsFilter(this)) {
clk_info_set_->erase(clk_info);
delete clk_info;
}
}
}
void
Search::findFilteredArrivals(bool thru_latches)
{
filtered_arrivals_->clear();
findArrivalsSeed();
seedFilterStarts();
Level max_level = levelize_->maxLevel();
// Search always_to_endpoint to search from exisiting arrivals at
// fanin startpoints to reach -thru/-to endpoints.
arrival_visitor_->init(true);
// Iterate until data arrivals at all latches stop changing.
for (int pass = 1; pass == 1 || (thru_latches && havePendingLatchOutputs()) ; pass++) {
if (thru_latches)
enqueuePendingLatchOutputs();
debugPrint(debug_, "search", 1, "find arrivals pass %d", pass);
int arrival_count = arrival_iter_->visitParallel(max_level,
arrival_visitor_);
debugPrint(debug_, "search", 1, "found %d arrivals", arrival_count);
}
arrivals_exist_ = true;
}
VertexSeq
Search::filteredEndpoints()
{
VertexSeq ends;
for (Vertex *vertex : *filtered_arrivals_) {
if (isEndpoint(vertex))
ends.push_back(vertex);
}
return ends;
}
class SeedFaninsThruHierPin : public HierPinThruVisitor
{
public:
SeedFaninsThruHierPin(Graph *graph,
Search *search);
protected:
virtual void visit(const Pin *drvr,
const Pin *load);
Graph *graph_;
Search *search_;
};
SeedFaninsThruHierPin::SeedFaninsThruHierPin(Graph *graph,
Search *search) :
HierPinThruVisitor(),
graph_(graph),
search_(search)
{
}
void
SeedFaninsThruHierPin::visit(const Pin *drvr,
const Pin *)
{
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(drvr, vertex, bidirect_drvr_vertex);
search_->seedArrival(vertex);
if (bidirect_drvr_vertex)
search_->seedArrival(bidirect_drvr_vertex);
}
void
Search::seedFilterStarts()
{
ExceptionPt *first_pt = filter_->firstPt();
if (first_pt) {
PinSet first_pins(network_);
first_pt->allPins(network_, &first_pins);
for (const Pin *pin : first_pins) {
if (network_->isHierarchical(pin)) {
SeedFaninsThruHierPin visitor(graph_, this);
visitDrvrLoadsThruHierPin(pin, network_, &visitor);
}
else {
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
if (vertex)
seedArrival(vertex);
if (bidirect_drvr_vertex)
seedArrival(bidirect_drvr_vertex);
}
}
}
}
////////////////////////////////////////////////////////////////
void
Search::deleteVertexBefore(Vertex *vertex)
{
if (arrivals_exist_) {
deletePaths(vertex);
arrival_iter_->deleteVertexBefore(vertex);
invalid_arrivals_->erase(vertex);
filtered_arrivals_->erase(vertex);
}
if (requireds_exist_) {
required_iter_->deleteVertexBefore(vertex);
invalid_requireds_->erase(vertex);
invalid_tns_->erase(vertex);
}
if (endpoints_)
endpoints_->erase(vertex);
if (invalid_endpoints_)
invalid_endpoints_->erase(vertex);
}
bool
Search::arrivalsValid()
{
return arrivals_exist_
&& invalid_arrivals_->empty();
}
void
Search::arrivalsInvalid()
{
if (arrivals_exist_) {
debugPrint(debug_, "search", 1, "arrivals invalid");
// Delete paths to make sure no state is left over.
// For example, set_disable_timing strands a vertex, which means
// the search won't revisit it to clear the previous arrival.
deletePaths();
deleteTags();
genclks_->clear();
deleteFilter();
arrivals_at_endpoints_exist_ = false;
arrivals_seeded_ = false;
requireds_exist_ = false;
requireds_seeded_ = false;
clk_arrivals_valid_ = false;
arrival_iter_->clear();
required_iter_->clear();
// No need to keep track of incremental updates any more.
invalid_arrivals_->clear();
invalid_requireds_->clear();
tns_exists_ = false;
clearWorstSlack();
invalid_tns_->clear();
}
}
void
Search::requiredsInvalid()
{
debugPrint(debug_, "search", 1, "requireds invalid");
requireds_exist_ = false;
requireds_seeded_ = false;
invalid_requireds_->clear();
tns_exists_ = false;
clearWorstSlack();
invalid_tns_->clear();
}
void
Search::arrivalInvalid(Vertex *vertex)
{
if (arrivals_exist_) {
debugPrint(debug_, "search", 2, "arrival invalid %s",
vertex->name(sdc_network_));
if (!arrival_iter_->inQueue(vertex)) {
// Lock for StaDelayCalcObserver called by delay calc threads.
UniqueLock lock(invalid_arrivals_lock_);
invalid_arrivals_->insert(vertex);
}
tnsInvalid(vertex);
}
}
void
Search::arrivalInvalidDelete(Vertex *vertex)
{
arrivalInvalid(vertex);
vertex->deletePaths();
}
void
Search::levelChangedBefore(Vertex *vertex)
{
if (arrivals_exist_) {
arrival_iter_->remove(vertex);
required_iter_->remove(vertex);
search_->arrivalInvalid(vertex);
search_->requiredInvalid(vertex);
}
}
void
Search::arrivalInvalid(const Pin *pin)
{
if (graph_) {
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
arrivalInvalid(vertex);
if (bidirect_drvr_vertex)
arrivalInvalid(bidirect_drvr_vertex);
}
}
void
Search::requiredInvalid(const Instance *inst)
{
if (graph_) {
InstancePinIterator *pin_iter = network_->pinIterator(inst);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
requiredInvalid(pin);
}
delete pin_iter;
}
}
void
Search::requiredInvalid(const Pin *pin)
{
if (graph_) {
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
requiredInvalid(vertex);
if (bidirect_drvr_vertex)
requiredInvalid(bidirect_drvr_vertex);
}
}
void
Search::requiredInvalid(Vertex *vertex)
{
if (requireds_exist_) {
debugPrint(debug_, "search", 2, "required invalid %s",
vertex->name(sdc_network_));
if (!required_iter_->inQueue(vertex)) {
// Lock for StaDelayCalcObserver called by delay calc threads.
UniqueLock lock(invalid_arrivals_lock_);
invalid_requireds_->insert(vertex);
}
tnsInvalid(vertex);
}
}
////////////////////////////////////////////////////////////////
void
Search::findClkArrivals()
{
if (!clk_arrivals_valid_) {
genclks_->ensureInsertionDelays();
Stats stats(debug_, report_);
debugPrint(debug_, "search", 1, "find clk arrivals");
arrival_iter_->clear();
seedClkVertexArrivals();
ClkArrivalSearchPred search_clk(this);
arrival_visitor_->init(false, &search_clk);
arrival_iter_->visitParallel(levelize_->maxLevel(), arrival_visitor_);
arrivals_exist_ = true;
stats.report("Find clk arrivals");
}
clk_arrivals_valid_ = true;
}
void
Search::seedClkVertexArrivals()
{
PinSet clk_pins(network_);
findClkVertexPins(clk_pins);
for (const Pin *pin : clk_pins) {
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
seedClkVertexArrivals(pin, vertex);
if (bidirect_drvr_vertex)
seedClkVertexArrivals(pin, bidirect_drvr_vertex);
}
}
void
Search::seedClkVertexArrivals(const Pin *pin,
Vertex *vertex)
{
TagGroupBldr tag_bldr(true, this);
tag_bldr.init(vertex);
genclks_->copyGenClkSrcPaths(vertex, &tag_bldr);
seedClkArrivals(pin, vertex, &tag_bldr);
setVertexArrivals(vertex, &tag_bldr);
}
Arrival
Search::clockInsertion(const Clock *clk,
const Pin *pin,
const RiseFall *rf,
const MinMax *min_max,
const EarlyLate *early_late,
const PathAnalysisPt *path_ap) const
{
float insert;
bool exists;
sdc_->clockInsertion(clk, pin, rf, min_max, early_late, insert, exists);
if (exists)
return insert;
else if (clk->isGeneratedWithPropagatedMaster())
return genclks_->insertionDelay(clk, pin, rf, early_late, path_ap);
else
return 0.0;
}
////////////////////////////////////////////////////////////////
void
Search::visitStartpoints(VertexVisitor *visitor)
{
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)->isAnyInput()) {
Vertex *vertex = graph_->pinDrvrVertex(pin);
visitor->visit(vertex);
}
}
delete pin_iter;
for (auto iter : sdc_->inputDelayPinMap()) {
const Pin *pin = iter.first;
// Already hit these.
if (!network_->isTopLevelPort(pin)) {
Vertex *vertex = graph_->pinDrvrVertex(pin);
if (vertex)
visitor->visit(vertex);
}
}
for (const Clock *clk : sdc_->clks()) {
for (const Pin *pin : clk->leafPins()) {
// Already hit these.
if (!network_->isTopLevelPort(pin)) {
Vertex *vertex = graph_->pinDrvrVertex(pin);
visitor->visit(vertex);
}
}
}
// Register clk pins.
for (Vertex *vertex : *graph_->regClkVertices())
visitor->visit(vertex);
const PinSet &startpoints = sdc_->pathDelayInternalStartpoints();
if (!startpoints.empty()) {
for (const Pin *pin : startpoints) {
Vertex *vertex = graph_->pinDrvrVertex(pin);
visitor->visit(vertex);
}
}
}
void
Search::visitEndpoints(VertexVisitor *visitor)
{
for (Vertex *end : *endpoints()) {
Pin *pin = end->pin();
// Filter register clock pins (fails on set_max_delay -from clk_src).
if (!network_->isRegClkPin(pin)
|| sdc_->isPathDelayInternalEndpoint(pin))
visitor->visit(end);
}
}
////////////////////////////////////////////////////////////////
void
Search::findAllArrivals()
{
findAllArrivals(true);
}
void
Search::findAllArrivals(bool thru_latches)
{
arrival_visitor_->init(false);
// Iterate until data arrivals at all latches stop changing.
for (int pass = 1; pass == 1 || (thru_latches && havePendingLatchOutputs()); pass++) {
enqueuePendingLatchOutputs();
debugPrint(debug_, "search", 1, "find arrivals pass %d", pass);
findArrivals1(levelize_->maxLevel());
}
}
bool
Search::havePendingLatchOutputs()
{
return !pending_latch_outputs_->empty();
}
void
Search::clearPendingLatchOutputs()
{
pending_latch_outputs_->clear();
}
void
Search::enqueuePendingLatchOutputs()
{
for (Vertex *latch_vertex : *pending_latch_outputs_)
arrival_iter_->enqueue(latch_vertex);
clearPendingLatchOutputs();
}
void
Search::findArrivals()
{
findArrivals(levelize_->maxLevel());
}
void
Search::findArrivals(Level level)
{