forked from The-OpenROAD-Project/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Genclks.cc
1303 lines (1179 loc) · 35 KB
/
Genclks.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) 2020, 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 "Genclks.hh"
#include "Stats.hh"
#include "Debug.hh"
#include "Report.hh"
#include "Network.hh"
#include "PortDirection.hh"
#include "Graph.hh"
#include "Sdc.hh"
#include "ExceptionPath.hh"
#include "Clock.hh"
#include "StaState.hh"
#include "SearchPred.hh"
#include "Bfs.hh"
#include "TagGroup.hh"
#include "Corner.hh"
#include "PathAnalysisPt.hh"
#include "Levelize.hh"
#include "PathVertexRep.hh"
#include "Search.hh"
namespace sta {
using std::max;
class GenclkInfo
{
public:
GenclkInfo(Clock *gclk,
Level gclk_level,
VertexSet *fanins,
FilterPath *src_filter);
~GenclkInfo();
EdgeSet *fdbkEdges() const { return fdbk_edges_; }
VertexSet *fanins() const { return fanins_; }
Level gclkLevel() const { return gclk_level_; }
FilterPath *srcFilter() const { return src_filter_; }
FilterPath *pllFilter() const { return pll_filter_; }
void setPllFilter(FilterPath *pll_filter);
void setLatchFdbkEdges(EdgeSet *fdbk_edges);
bool foundLatchFdbkEdges() const { return found_latch_fdbk_edges_; }
void setFoundLatchFdbkEdges(bool found);
protected:
DISALLOW_COPY_AND_ASSIGN(GenclkInfo);
Clock *gclk_;
Level gclk_level_;
VertexSet *fanins_;
EdgeSet *fdbk_edges_;
bool found_latch_fdbk_edges_;
FilterPath *src_filter_;
FilterPath *pll_filter_;
};
GenclkInfo::GenclkInfo(Clock *gclk,
Level gclk_level,
VertexSet *fanins,
FilterPath *src_filter) :
gclk_(gclk),
gclk_level_(gclk_level),
fanins_(fanins),
fdbk_edges_(nullptr),
found_latch_fdbk_edges_(false),
src_filter_(src_filter),
pll_filter_(nullptr)
{
}
GenclkInfo::~GenclkInfo()
{
delete fanins_;
delete fdbk_edges_;
delete src_filter_;
delete pll_filter_;
}
void
GenclkInfo::setPllFilter(FilterPath *pll_filter)
{
pll_filter_ = pll_filter;
}
void
GenclkInfo::setLatchFdbkEdges(EdgeSet *fdbk_edges)
{
fdbk_edges_ = fdbk_edges;
}
void
GenclkInfo::setFoundLatchFdbkEdges(bool found)
{
found_latch_fdbk_edges_ = found;
}
////////////////////////////////////////////////////////////////
Genclks::Genclks(StaState *sta) :
StaState(sta),
found_insertion_delays_(false)
{
}
Genclks::~Genclks()
{
genclk_info_map_.deleteContentsClear();
clearSrcPaths();
}
void
Genclks::clear()
{
found_insertion_delays_ = false;
genclk_info_map_.deleteContentsClear();
clearSrcPaths();
}
VertexSet *
Genclks::fanins(const Clock *clk)
{
GenclkInfo *genclk_info = genclkInfo(clk);
return genclk_info->fanins();
}
Vertex *
Genclks::srcPathVertex(const Pin *pin) const
{
bool is_bidirect = network_->direction(pin)->isBidirect();
// Insertion delay is to the driver vertex for clks defined on
// bidirect pins.
if (is_bidirect && network_->isLeaf(pin))
return graph_->pinDrvrVertex(pin);
else
// Insertion delay is to the load vertex for clks defined on
// bidirect ports.
return graph_->pinLoadVertex(pin);
}
Level
Genclks::clkPinMaxLevel(Clock *clk) const
{
Level max_level = 0;
for (Pin *pin : clk->leafPins()) {
Vertex *vertex = srcPathVertex(pin);
max_level = max(max_level, vertex->level());
}
return max_level;
}
class ClockPinMaxLevelLess
{
public:
explicit ClockPinMaxLevelLess(const Genclks *genclks);
bool operator()(Clock *clk1,
Clock *clk2) const;
protected:
const Genclks *genclks_;
};
ClockPinMaxLevelLess::ClockPinMaxLevelLess(const Genclks *genclks) :
genclks_(genclks)
{
}
bool
ClockPinMaxLevelLess::operator()(Clock *clk1,
Clock *clk2) const
{
return genclks_->clkPinMaxLevel(clk1) < genclks_->clkPinMaxLevel(clk2);
}
// Generated clock source paths.
// The path between the source clock and generated clock is used
// to find the insertion delay (source latency) when the clock is
// propagated and for reporting path type "full_clock_expanded".
void
Genclks::ensureInsertionDelays()
{
if (!found_insertion_delays_) {
Stats stats(debug_);
debugPrint0(debug_, "genclk", 1, "find generated clk insertion delays\n");
ClockSeq gclks;
for (auto clk : sdc_->clks()) {
if (clk->isGenerated()) {
checkMaster(clk);
gclks.push_back(clk);
}
}
clearSrcPaths();
// Generated clocks derived from a generated clock inherit its
// insertion delay, so sort the clocks by source pin level.
sort(gclks, ClockPinMaxLevelLess(this));
ClockSeq::Iterator gclk_iter(gclks);
while (gclk_iter.hasNext()) {
Clock *gclk = gclk_iter.next();
if (gclk->masterClk()) {
findInsertionDelays(gclk);
if (gclk->pllOut())
findPllDelays(gclk);
recordSrcPaths(gclk);
}
}
stats.report("Find generated clk insertion delays");
found_insertion_delays_ = true;
}
}
// Similar to ClkTreeSearchPred but ignore constants.
class GenClkMasterSearchPred : public SearchPred
{
public:
explicit GenClkMasterSearchPred(const StaState *sta);
virtual bool searchFrom(const Vertex *from_vertex);
virtual bool searchThru(Edge *edge);
virtual bool searchTo(const Vertex *to_vertex);
protected:
const StaState *sta_;
private:
DISALLOW_COPY_AND_ASSIGN(GenClkMasterSearchPred);
};
GenClkMasterSearchPred::GenClkMasterSearchPred(const StaState *sta) :
SearchPred(),
sta_(sta)
{
}
bool
GenClkMasterSearchPred::searchFrom(const Vertex *from_vertex)
{
return !from_vertex->isDisabledConstraint();
}
bool
GenClkMasterSearchPred::searchThru(Edge *edge)
{
const Sdc *sdc = sta_->sdc();
TimingRole *role = edge->role();
// Propagate clocks through constants.
return !(edge->isDisabledLoop()
|| edge->isDisabledConstraint()
// Constants disable edge cond expression.
|| edge->isDisabledCond()
|| sdc->isDisabledCondDefault(edge)
// Register/latch preset/clr edges are disabled by default.
|| (!sdc->presetClrArcsEnabled()
&& role == TimingRole::regSetClr())
|| (edge->isBidirectInstPath()
&& !sdc->bidirectInstPathsEnabled())
|| (edge->isBidirectNetPath()
&& !sdc->bidirectNetPathsEnabled()));
}
bool
GenClkMasterSearchPred::searchTo(const Vertex *)
{
return true;
}
void
Genclks::checkMaster(Clock *gclk)
{
ensureMaster(gclk);
if (gclk->masterClk() == nullptr)
report_->warn("no master clock found for generated clock %s.\n",
gclk->name());
}
void
Genclks::ensureMaster(Clock *gclk)
{
Clock *master_clk = gclk->masterClk();
if (master_clk == nullptr) {
int master_clk_count = 0;
bool found_master = false;
if (gclk->pllOut()) {
// Search backward from generated clock source pin to a clock pin.
GenClkMasterSearchPred pred(this);
BfsBkwdIterator iter(BfsIndex::other, &pred, this);
seedSrcPins(gclk, iter);
while (iter.hasNext()) {
Vertex *vertex = iter.next();
Pin *pin = vertex->pin();
if (sdc_->isLeafPinClock(pin)) {
ClockSet *master_clks = sdc_->findLeafPinClocks(pin);
if (master_clks) {
ClockSet::Iterator master_iter(master_clks);
while (master_iter.hasNext()) {
master_clk = master_iter.next();
// Master source pin can actually be a clock source pin.
if (master_clk != gclk) {
gclk->setInferedMasterClk(master_clk);
debugPrint2(debug_, "genclk", 2, " %s master clk %s\n",
gclk->name(),
master_clk->name());
found_master = true;
master_clk_count++;
}
}
}
}
if (found_master)
break;
iter.enqueueAdjacentVertices(vertex);
}
if (master_clk_count > 1)
report_->error("generated clock %s is in the fanout of multiple clocks.\n",
gclk->name());
}
else {
Pin *src_pin = gclk->srcPin();
ClockSet *master_clks = sdc_->findClocks(src_pin);
ClockSet::Iterator master_iter(master_clks);
if (master_iter.hasNext()) {
while (master_iter.hasNext()) {
master_clk = master_iter.next();
// Master source pin can actually be a clock source pin.
if (master_clk != gclk) {
gclk->setInferedMasterClk(master_clk);
debugPrint2(debug_, "genclk", 2, " %s master clk %s\n",
gclk->name(),
master_clk->name());
found_master = true;
master_clk_count++;
}
}
}
if (!found_master) {
// Search backward from generated clock source pin to a clock pin.
GenClkMasterSearchPred pred(this);
BfsBkwdIterator iter(BfsIndex::other, &pred, this);
seedSrcPins(gclk, iter);
while (iter.hasNext()) {
Vertex *vertex = iter.next();
Pin *pin = vertex->pin();
if (sdc_->isLeafPinClock(pin)) {
ClockSet *master_clks = sdc_->findLeafPinClocks(pin);
if (master_clks) {
ClockSet::Iterator master_iter(master_clks);
if (master_iter.hasNext()) {
master_clk = master_iter.next();
// Master source pin can actually be a clock source pin.
if (master_clk != gclk) {
gclk->setInferedMasterClk(master_clk);
debugPrint2(debug_, "genclk", 2, " %s master clk %s\n",
gclk->name(),
master_clk->name());
master_clk_count++;
break;
}
}
}
}
iter.enqueueAdjacentVertices(vertex);
}
}
if (master_clk_count > 1)
report_->error("generated clock %s pin %s is in the fanout of multiple clocks.\n",
gclk->name(),
network_->pathName(src_pin));
}
}
}
void
Genclks::seedSrcPins(Clock *clk,
BfsBkwdIterator &iter)
{
VertexSet src_vertices;
clk->srcPinVertices(src_vertices, network_, graph_);
VertexSet::Iterator vertex_iter(src_vertices);
while (vertex_iter.hasNext()) {
Vertex *vertex = vertex_iter.next();
iter.enqueue(vertex);
}
}
////////////////////////////////////////////////////////////////
// Similar to ClkTreeSearchPred but
// search thru constants
// respect generated clock combinational attribute
// search thru disabled loop arcs
class GenClkFaninSrchPred : public GenClkMasterSearchPred
{
public:
explicit GenClkFaninSrchPred(Clock *gclk,
const StaState *sta);
virtual bool searchFrom(const Vertex *from_vertex);
virtual bool searchThru(Edge *edge);
virtual bool searchTo(const Vertex *to_vertex);
private:
DISALLOW_COPY_AND_ASSIGN(GenClkFaninSrchPred);
bool combinational_;
};
GenClkFaninSrchPred::GenClkFaninSrchPred(Clock *gclk,
const StaState *sta) :
GenClkMasterSearchPred(sta),
combinational_(gclk->combinational())
{
}
bool
GenClkFaninSrchPred::searchFrom(const Vertex *from_vertex)
{
return !from_vertex->isDisabledConstraint();
}
bool
GenClkFaninSrchPred::searchThru(Edge *edge)
{
const TimingRole *role = edge->role();
return GenClkMasterSearchPred::searchThru(edge)
&& (role == TimingRole::combinational()
|| role == TimingRole::wire()
|| !combinational_);
}
bool
GenClkFaninSrchPred::searchTo(const Vertex *)
{
return true;
}
void
Genclks::findFanin(Clock *gclk,
// Return value.
VertexSet *fanins)
{
// Search backward from generated clock source pin to a clock pin.
GenClkFaninSrchPred srch_pred(gclk, this);
BfsBkwdIterator iter(BfsIndex::other, &srch_pred, this);
seedClkVertices(gclk, iter, fanins);
while (iter.hasNext()) {
Vertex *vertex = iter.next();
if (!fanins->hasKey(vertex)) {
fanins->insert(vertex);
debugPrint2(debug_, "genclk", 2, "gen clk %s fanin %s\n",
gclk->name(), vertex->name(sdc_network_));
iter.enqueueAdjacentVertices(vertex);
}
}
}
void
Genclks::seedClkVertices(Clock *clk,
BfsBkwdIterator &iter,
VertexSet *fanins)
{
for (Pin *pin : clk->leafPins()) {
Vertex *vertex, *bidirect_drvr_vertex;
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
fanins->insert(vertex);
iter.enqueueAdjacentVertices(vertex);
if (bidirect_drvr_vertex) {
fanins->insert(bidirect_drvr_vertex);
iter.enqueueAdjacentVertices(bidirect_drvr_vertex);
}
}
}
////////////////////////////////////////////////////////////////
class GenClkInsertionSearchPred : public SearchPred0, public DynLoopSrchPred
{
public:
GenClkInsertionSearchPred(Clock *gclk,
TagGroupBldr *tag_bldr,
GenclkInfo *genclk_info,
const StaState *sta);
virtual bool searchThru(Edge *edge);
virtual bool searchTo(const Vertex *to_vertex);
private:
DISALLOW_COPY_AND_ASSIGN(GenClkInsertionSearchPred);
bool isNonGeneratedClkPin(const Pin *pin) const;
Clock *gclk_;
GenclkInfo *genclk_info_;
};
GenClkInsertionSearchPred::GenClkInsertionSearchPred(Clock *gclk,
TagGroupBldr *tag_bldr,
GenclkInfo *genclk_info,
const StaState *sta) :
SearchPred0(sta),
DynLoopSrchPred(tag_bldr),
gclk_(gclk),
genclk_info_(genclk_info)
{
}
bool
GenClkInsertionSearchPred::searchThru(Edge *edge)
{
const Graph *graph = sta_->graph();
const Sdc *sdc = sta_->sdc();
Search *search = sta_->search();
const TimingRole *role = edge->role();
EdgeSet *fdbk_edges = genclk_info_->fdbkEdges();
return SearchPred0::searchThru(edge)
&& !role->isTimingCheck()
&& (sdc->clkThruTristateEnabled()
|| !(role == TimingRole::tristateEnable()
|| role == TimingRole::tristateDisable()))
&& !(fdbk_edges && fdbk_edges->hasKey(edge))
&& loopEnabled(edge, sdc, graph, search);
}
bool
GenClkInsertionSearchPred::searchTo(const Vertex *to_vertex)
{
Pin *to_pin = to_vertex->pin();
return SearchPred0::searchTo(to_vertex)
// Propagate through other generated clock roots but not regular
// clock roots.
&& !(!gclk_->leafPins().hasKey(to_pin)
&& isNonGeneratedClkPin(to_pin))
&& genclk_info_->fanins()->hasKey(const_cast<Vertex*>(to_vertex));
}
bool
GenClkInsertionSearchPred::isNonGeneratedClkPin(const Pin *pin) const
{
const Sdc *sdc = sta_->sdc();
ClockSet *clks = sdc->findLeafPinClocks(pin);
if (clks) {
ClockSet::Iterator clk_iter(clks);
while (clk_iter.hasNext()) {
const Clock *clk = clk_iter.next();
if (!clk->isGenerated())
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////
void
Genclks::findInsertionDelays(Clock *gclk)
{
debugPrint1(debug_, "genclk", 2, "find gen clk %s insertion\n",
gclk->name());
GenclkInfo *genclk_info = makeGenclkInfo(gclk);
FilterPath *src_filter = genclk_info->srcFilter();
GenClkInsertionSearchPred srch_pred(gclk, nullptr, genclk_info, this);
BfsFwdIterator insert_iter(BfsIndex::other, &srch_pred, this);
seedSrcPins(gclk, src_filter, insert_iter);
// Propagate arrivals to generated clk root pin level.
findSrcArrivals(gclk, insert_iter, genclk_info);
// Unregister the filter so that it is not triggered by other searches.
// The exception itself has to stick around because the source path
// tags reference it.
sdc_->unrecordException(src_filter);
}
GenclkInfo *
Genclks::makeGenclkInfo(Clock *gclk)
{
FilterPath *src_filter = makeSrcFilter(gclk);
Level gclk_level = clkPinMaxLevel(gclk);
VertexSet *fanins = new VertexSet;
findFanin(gclk, fanins);
GenclkInfo *genclk_info = new GenclkInfo(gclk, gclk_level, fanins,
src_filter);
genclk_info_map_.insert(gclk, genclk_info);
return genclk_info;
}
GenclkInfo *
Genclks::genclkInfo(const Clock *gclk) const
{
return genclk_info_map_.findKey(const_cast<Clock*>(gclk));
}
FilterPath *
Genclks::srcFilter(Clock *gclk)
{
GenclkInfo *genclk_info = genclk_info_map_.findKey(gclk);
if (genclk_info)
return genclk_info->srcFilter();
else
return nullptr;
}
EdgeSet *
Genclks::latchFdbkEdges(const Clock *clk)
{
GenclkInfo *genclk_info = genclkInfo(clk);
return genclk_info->fdbkEdges();
}
void
Genclks::findLatchFdbkEdges(const Clock *clk)
{
GenclkInfo *genclk_info = genclkInfo(clk);
if (!genclk_info->foundLatchFdbkEdges())
findLatchFdbkEdges(clk, genclk_info);
}
// Generated clock insertion delays propagate through latch D->Q.
// This exposes loops through latches that are not discovered and
// flagged by levelization. Find these loops with a depth first
// search from the master clock source pins and record them to prevent
// the clock insertion search from searching through them.
//
// Because this is relatively expensive to search and it is rare to
// find latches in the clock network it is only called when a latch
// D to Q edge is encountered in the BFS arrival search.
void
Genclks::findLatchFdbkEdges(const Clock *gclk,
GenclkInfo *genclk_info)
{
Level gclk_level = genclk_info->gclkLevel();
EdgeSet *fdbk_edges = nullptr;
for (Pin *pin : gclk->masterClk()->leafPins()) {
Vertex *vertex = graph_->pinDrvrVertex(pin);
VertexSet path_vertices;
VertexSet visited_vertices;
SearchPred1 srch_pred(this);
findLatchFdbkEdges(vertex, gclk_level, srch_pred, path_vertices,
visited_vertices, fdbk_edges);
}
genclk_info->setLatchFdbkEdges(fdbk_edges);
genclk_info->setFoundLatchFdbkEdges(true);
}
void
Genclks::findLatchFdbkEdges(Vertex *from_vertex,
Level gclk_level,
SearchPred &srch_pred,
VertexSet &path_vertices,
VertexSet &visited_vertices,
EdgeSet *&fdbk_edges)
{
if (!visited_vertices.hasKey(from_vertex)) {
visited_vertices.insert(from_vertex);
path_vertices.insert(from_vertex);
VertexOutEdgeIterator edge_iter(from_vertex, graph_);
while (edge_iter.hasNext()) {
Edge *edge = edge_iter.next();
Vertex *to_vertex = edge->to(graph_);
if (path_vertices.hasKey(to_vertex)) {
debugPrint2(debug_, "genclk", 2, " found feedback edge %s -> %s\n",
from_vertex->name(sdc_network_),
to_vertex->name(sdc_network_));
if (fdbk_edges == nullptr)
fdbk_edges = new EdgeSet;
fdbk_edges->insert(edge);
}
else if (srch_pred.searchThru(edge)
&& srch_pred.searchTo(to_vertex)
&& to_vertex->level() <= gclk_level)
findLatchFdbkEdges(to_vertex, gclk_level, srch_pred,
path_vertices, visited_vertices, fdbk_edges);
}
path_vertices.erase(from_vertex);
}
}
FilterPath *
Genclks::makeSrcFilter(Clock *gclk)
{
ClockSet *from_clks = new ClockSet;
from_clks->insert(gclk->masterClk());
const RiseFallBoth *rf = RiseFallBoth::riseFall();
ExceptionFrom *from = sdc_->makeExceptionFrom(nullptr,from_clks,nullptr,rf);
PinSet *thru_pins = new PinSet;
thru_pins->insert(gclk->srcPin());
ExceptionThru *thru = sdc_->makeExceptionThru(thru_pins,nullptr,nullptr,rf);
ExceptionThruSeq *thrus = new ExceptionThruSeq;
thrus->push_back(thru);
ClockSet *to_clks = new ClockSet;
to_clks->insert(gclk);
ExceptionTo *to = sdc_->makeExceptionTo(nullptr, to_clks, nullptr, rf, rf);
return sdc_->makeFilterPath(from, thrus, to);
}
void
Genclks::seedSrcPins(Clock *gclk,
FilterPath *src_filter,
BfsFwdIterator &insert_iter)
{
Clock *master_clk = gclk->masterClk();
for (Pin *master_pin : master_clk->leafPins()) {
Vertex *vertex = graph_->pinDrvrVertex(master_pin);
debugPrint1(debug_, "genclk", 2, " seed src pin %s\n",
network_->pathName(master_pin));
TagGroupBldr tag_bldr(true, this);
tag_bldr.init(vertex);
copyGenClkSrcPaths(vertex, &tag_bldr);
for (auto path_ap : corners_->pathAnalysisPts()) {
const MinMax *min_max = path_ap->pathMinMax();
const EarlyLate *early_late = min_max;
for (auto tr : RiseFall::range()) {
Tag *tag = makeTag(gclk, master_clk, master_pin, tr, src_filter,
path_ap);
Arrival insert = search_->clockInsertion(master_clk, master_pin, tr,
min_max, early_late, path_ap);
tag_bldr.setArrival(tag, insert, nullptr);
}
}
search_->setVertexArrivals(vertex, &tag_bldr);
insert_iter.enqueueAdjacentVertices(vertex);
}
}
Tag *
Genclks::makeTag(const Clock *gclk,
const Clock *master_clk,
const Pin *master_pin,
const RiseFall *master_rf,
FilterPath *src_filter,
const PathAnalysisPt *path_ap)
{
ExceptionState *state = src_filter->firstState();
// If the src pin is one of the master pins the filter is active
// from the get go.
if (master_pin == gclk->srcPin())
state = state->nextState();
ExceptionStateSet *states = new ExceptionStateSet;
states->insert(state);
ClkInfo *clk_info = search_->findClkInfo(master_clk->edge(master_rf),
master_pin, true, nullptr, true,
nullptr, 0.0, 0.0, nullptr,
path_ap, nullptr);
return search_->findTag(master_rf, path_ap, clk_info, false, nullptr, false,
states, true);
}
class GenClkArrivalSearchPred : public EvalPred
{
public:
GenClkArrivalSearchPred(Clock *gclk,
const StaState *sta);
bool searchThru(Edge *edge);
virtual bool searchTo(const Vertex *to_vertex);
private:
DISALLOW_COPY_AND_ASSIGN(GenClkArrivalSearchPred);
bool combinational_;
};
GenClkArrivalSearchPred::GenClkArrivalSearchPred(Clock *gclk,
const StaState *sta) :
EvalPred(sta),
combinational_(gclk->combinational())
{
}
bool
GenClkArrivalSearchPred::searchThru(Edge *edge)
{
const Sdc *sdc = sta_->sdc();
const TimingRole *role = edge->role();
return EvalPred::searchThru(edge)
&& (role == TimingRole::combinational()
|| role->isWire()
|| !combinational_)
&& (sdc->clkThruTristateEnabled()
|| !(role == TimingRole::tristateEnable()
|| role == TimingRole::tristateDisable()));
}
// Override EvalPred::searchTo to search to generated clock pin.
bool
GenClkArrivalSearchPred::searchTo(const Vertex *to_vertex)
{
return SearchPred0::searchTo(to_vertex);
}
class GenclkSrcArrivalVisitor : public ArrivalVisitor
{
public:
GenclkSrcArrivalVisitor(Clock *gclk,
BfsFwdIterator *insert_iter,
GenclkInfo *genclk_info,
const StaState *sta);
virtual VertexVisitor *copy();
virtual void visit(Vertex *vertex);
protected:
GenclkSrcArrivalVisitor(Clock *gclk,
BfsFwdIterator *insert_iter,
GenclkInfo *genclk_info,
bool always_to_endpoints,
SearchPred *pred,
const StaState *sta);
Clock *gclk_;
BfsFwdIterator *insert_iter_;
GenclkInfo *genclk_info_;
GenClkInsertionSearchPred srch_pred_;
};
GenclkSrcArrivalVisitor::GenclkSrcArrivalVisitor(Clock *gclk,
BfsFwdIterator *insert_iter,
GenclkInfo *genclk_info,
const StaState *sta):
ArrivalVisitor(sta),
gclk_(gclk),
insert_iter_(insert_iter),
genclk_info_(genclk_info),
srch_pred_(gclk_, tag_bldr_, genclk_info, sta)
{
}
// Copy constructor.
GenclkSrcArrivalVisitor::GenclkSrcArrivalVisitor(Clock *gclk,
BfsFwdIterator *insert_iter,
GenclkInfo *genclk_info,
bool always_to_endpoints,
SearchPred *pred,
const StaState *sta) :
ArrivalVisitor(always_to_endpoints, pred, sta),
gclk_(gclk),
insert_iter_(insert_iter),
genclk_info_(genclk_info),
srch_pred_(gclk, tag_bldr_, genclk_info, sta)
{
}
VertexVisitor *
GenclkSrcArrivalVisitor::copy()
{
return new GenclkSrcArrivalVisitor(gclk_, insert_iter_, genclk_info_,
always_to_endpoints_, pred_, sta_);
}
void
GenclkSrcArrivalVisitor::visit(Vertex *vertex)
{
const Debug *debug = sta_->debug();
const Network *sdc_network = sta_->sdcNetwork();
const Graph *graph = sta_->graph();
Search *search = sta_->search();
Genclks *genclks = search->genclks();
debugPrint1(debug, "genclk", 2, "find gen clk insert arrival %s\n",
vertex->name(sdc_network));
tag_bldr_->init(vertex);
has_fanin_one_ = graph->hasFaninOne(vertex);
genclks->copyGenClkSrcPaths(vertex, tag_bldr_);
visitFaninPaths(vertex);
// Propagate beyond the clock tree to reach generated clk roots.
insert_iter_->enqueueAdjacentVertices(vertex, &srch_pred_);
search->setVertexArrivals(vertex, tag_bldr_);
}
void
Genclks::findSrcArrivals(Clock *gclk,
BfsFwdIterator &insert_iter,
GenclkInfo *genclk_info)
{
GenClkArrivalSearchPred eval_pred(gclk, this);
GenclkSrcArrivalVisitor arrival_visitor(gclk, &insert_iter,
genclk_info, this);
arrival_visitor.init(true, &eval_pred);
// This cannot restrict the search level because loops in the clock tree
// can circle back to the generated clock src pin.
// Parallel visit is slightly slower (at last check).
insert_iter.visit(levelize_->maxLevel(), &arrival_visitor);
}
// Copy existing generated clock source paths from vertex to tag_bldr.
void
Genclks::copyGenClkSrcPaths(Vertex *vertex,
TagGroupBldr *tag_bldr)
{
Arrival *arrivals = graph_->arrivals(vertex);
if (arrivals) {
PathVertexRep *prev_paths = graph_->prevPaths(vertex);
TagGroup *tag_group = search_->tagGroup(vertex);
ArrivalMap::Iterator arrival_iter(tag_group->arrivalMap());
while (arrival_iter.hasNext()) {
Tag *tag;
int arrival_index;
arrival_iter.next(tag, arrival_index);
if (tag->isGenClkSrcPath()) {
Arrival arrival = arrivals[arrival_index];
PathVertexRep *prev_path = prev_paths
? &prev_paths[arrival_index]
: nullptr;
tag_bldr->setArrival(tag, arrival, prev_path);
}
}
}
}
////////////////////////////////////////////////////////////////
void
Genclks::clearSrcPaths()
{
genclk_src_paths_.deleteArrayContents();
genclk_src_paths_.clear();
}
int
Genclks::srcPathIndex(const RiseFall *clk_rf,
const PathAnalysisPt *path_ap) const
{
return path_ap->index() * RiseFall::index_count + clk_rf->index();
}
void
Genclks::recordSrcPaths(Clock *gclk)
{
int path_count = RiseFall::index_count
* corners_->pathAnalysisPtCount();
bool divide_by_1 = gclk->isDivideByOneCombinational();
bool invert = gclk->invert();
bool has_edges = gclk->edges() != nullptr;
for (Pin *gclk_pin : gclk->leafPins()) {
PathVertexRep *src_paths = new PathVertexRep[path_count];
genclk_src_paths_.insert(ClockPinPair(gclk, gclk_pin), src_paths);
Vertex *gclk_vertex = srcPathVertex(gclk_pin);
bool found_src_paths = false;
VertexPathIterator path_iter(gclk_vertex, this);
while (path_iter.hasNext()) {
PathVertex *path = path_iter.next();
ClockEdge *src_clk_edge = path->clkEdge(this);
if (src_clk_edge
&& matchesSrcFilter(path, gclk)) {
const EarlyLate *early_late = path->minMax(this);
RiseFall *src_clk_rf = src_clk_edge->transition();
const RiseFall *rf = path->transition(this);
bool inverting_path = (rf != src_clk_rf);
const PathAnalysisPt *path_ap = path->pathAnalysisPt(this);
int path_index = srcPathIndex(rf, path_ap);
PathVertexRep &src_path = src_paths[path_index];
if ((!divide_by_1
|| (inverting_path == invert))
&& (!has_edges
|| src_clk_rf == gclk->masterClkEdgeTr(rf))
&& (src_path.isNull()
|| delayGreater(path->arrival(this),
src_path.arrival(this),
early_late,
this))) {
debugPrint4(debug_, "genclk", 2, " %s insertion %s %s %s\n",
network_->pathName(gclk_pin),
early_late->asString(),
rf->asString(),
delayAsString(path->arrival(this), this));
src_path.init(path, this);
found_src_paths = true;
}
}
}
if (!found_src_paths
// Don't warn if the master clock is ideal.
&& gclk->masterClk()
&& gclk->masterClk()->isPropagated())
report_->warn("generated clock %s source pin %s missing paths from master clock %s.\n",
gclk->name(),
network_->pathName(gclk_pin),
gclk->masterClk()->name());
}
}
bool
Genclks::matchesSrcFilter(Path *path,
const Clock *gclk) const
{
Tag *tag = path->tag(this);