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 | ###############################################################################
# Copyright (c) 2022-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform. As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose. Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
# @plugin
# Check Connectivity to IP Cells
# @namespace
# CheckOneLoad
# @section
# Analyze the Loaded Database
# @description
# Loop over all output pins of all instances of the given start cell list
# and check that each output pin only connects to one instance of the
# given IP cell list.
# @files
# cust22/checkOneLoad.tcl
# @tag
# zdb gui
###############################################################################
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc CheckOneLoad:Init {argc argv} {
global CheckOneLoad
##
# Initialize global variables.
#
set CheckOneLoad(showWidget) 0
set CheckOneLoad(startCells) {}
set CheckOneLoad(ipCells) {}
set CheckOneLoad(excludeCells) {}
set CheckOneLoad(startCellCount) 0
set CheckOneLoad(ipCellCount) 0
set CheckOneLoad(excludeCellCount) 0
set CheckOneLoad(violationCount) ""
set CheckOneLoad(useExtractAPI) false
set CheckOneLoad(name) "Check One Load"
##
# Add menu entries.
#
gui menu checkbutton {"Userware" "Check One Load"} \
[list CheckOneLoad:_toggle] CheckOneLoad(showWidget)
##
# Process command line options of this script.
#
for {set i 0} {$i < $argc} {incr i} {
set option [lindex $argv $i]
set value [lindex $argv [incr i]]
if {($i >= $argc) || ($value eq "")} {
error "missing value for '$option'."
}
switch -- $option {
"-start" {
CheckOneLoad:_readStartCellList $value
}
"-target" {
CheckOneLoad:_readIPList $value
}
"-exclude" {
CheckOneLoad:_readExcludeCellList $value
}
default {
error "Unknown option '$option'."
}
}
}
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc CheckOneLoad:Finit {} {
global CheckOneLoad
##
# Undo modifications of the GUI.
#
gui window removeCustomWidget CheckOneLoad(name)
gui menu removeEntry {"Userware" "Check One Load"}
}
# -----------------------------------------------------------------------------
# _readStartCellList -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_readStartCellList {{fname ""}} {
global CheckOneLoad
if {$fname eq ""} {
set fname [gui window fileDialog openFiles "Open Start Cell List" \
{{"Text Files" .txt}}]
}
if {$fname eq ""} {
return
}
array set startCells {}
array set startCellPorts {}
set in [open $fname "r"]
while {![eof $in]} {
set line [string trim [gets $in]]
if {($line eq "") || [string match "#*" $line]} {
continue
}
set cellName [lindex $line 0]
set portDefinition [lrange $line 1 end]
foreach {dir portList} [lrange $line 1 end] {
if {$dir ni {"-input" "-output"}} {
error "Bad direction '$dir' (-input or -output expected)."
}
set startCells($cellName) 1
if {![info exists startCellPorts($dir:$cellName)]} {
set startCellPorts($dir:$cellName) {}
}
lappend startCellPorts($dir:$cellName) {*}$portList
}
}
close $in
set CheckOneLoad(startCells) {}
set CheckOneLoad(startCellCount) 0
foreach cellName [array names startCells] {
lappend CheckOneLoad(startCells) $cellName
set CheckOneLoad(startCell:$cellName) {}
foreach dir {-input -output} {
set portList {}
if {[info exists startCellPorts($dir:$cellName)]} {
set portList $startCellPorts($dir:$cellName)
}
lappend CheckOneLoad(startCell:$cellName) [lsort -unique $portList]
}
incr CheckOneLoad(startCellCount)
}
}
# -----------------------------------------------------------------------------
# _readIPList -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_readIPList {{fname ""}} {
global CheckOneLoad
if {$fname eq ""} {
set fname [gui window fileDialog openFiles "Open IP List" \
{{"Text Files" .txt}}]
}
if {$fname eq ""} {
return
}
set ipCells {}
set in [open $fname "r"]
while {![eof $in]} {
set line [string trim [gets $in]]
if {($line ne "") && (![string match "#*" $line])} {
lappend ipCells $line
}
}
close $in
set CheckOneLoad(ipCells) [lsort -unique $ipCells]
set CheckOneLoad(ipCellCount) [llength $CheckOneLoad(ipCells)]
}
# -----------------------------------------------------------------------------
# _readExcludeCellList -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_readExcludeCellList {{fname ""}} {
global CheckOneLoad
if {$fname eq ""} {
set fname [gui window fileDialog openFiles "Open Exclude Cell List" \
{{"Text Files" .txt}}]
}
if {$fname eq ""} {
return
}
set excludeCells {*dummy*}
set in [open $fname "r"]
while {![eof $in]} {
set line [string trim [gets $in]]
if {($line ne "") && (![string match "#*" $line])} {
lappend excludeCells $line
}
}
close $in
set CheckOneLoad(excludeCells) [lsort -unique $excludeCells]
set CheckOneLoad(excludeCellCount) [llength $CheckOneLoad(excludeCells)]
}
# -----------------------------------------------------------------------------
# _isInitialized -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_isInitialized {} {
global CheckOneLoad
if {[llength $CheckOneLoad(startCells)] == 0} {
zmessage print ERR "The start cell list is not loaded."
return false
}
if {[llength $CheckOneLoad(ipCells)] == 0} {
zmessage print ERR "The IP cell list is not loaded."
return false
}
if {[gui database get] eq ""} {
zmessage print ERR "No design database loaded."
return false
}
return true
}
# -----------------------------------------------------------------------------
# _start -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_start {} {
global CheckOneLoad
if {![CheckOneLoad:_isInitialized]} {
return
}
##
# Clear the result list.
#
set resultList $CheckOneLoad(customWidget).right.result
set CheckOneLoad(violationCount) 0
$resultList delete [$resultList children {}]
set db [gui database get]
CheckOneLoad:_flagCells $db
set step 2
set index 0
zprogress begin
foreach dir {-input -output} {
zprogress push "Calculate $dir Result" [expr {1.0 / $step}]
CheckOneLoad:_calculate $db $dir $index
if {[zprogress pop]} {
break
}
incr step -1
incr index
}
zprogress end
}
# -----------------------------------------------------------------------------
# _flagCells -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_flagCells {db} {
global CheckOneLoad
set total [$db report objCount -cell]
set c 0
$db foreach cell cell {
if {[zprogress update "" [incr c] $total]} {
break
}
$db flag $cell clear red
$db flag $cell clear green
set name [$db oid oname $cell]
set rtlName [$db attr $cell getValue "RTL_Name"]
if {$rtlName ne ""} {
set name $rtlName
}
if {$name in $CheckOneLoad(startCells)} {
$db flag $cell set green
}
foreach excludeCellPattern $CheckOneLoad(excludeCells) {
if {[string match $excludeCellPattern $name]} {
$db flag $cell set red
break
}
}
}
}
# -----------------------------------------------------------------------------
# _getStartPinList -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_getStartPinList {db dirIndex} {
global CheckOneLoad
set top [$db get_top_design]
array set _cellInstTable {}
$db flat foreach instOfCell green $top inst {
set cell [$db oid cname $inst]
lappend _cellInstTable($cell) $inst
}
array set startPinTable {}
foreach {cell instList} [array get _cellInstTable] {
set portList [lindex $CheckOneLoad(startCell:$cell) $dirIndex]
foreach inst $instList {
set pinList {}
$db foreach pinBus $inst pinBus {
lappend pinList $pinBus
}
$db foreach pin $inst pin {
lappend pinList $pin
}
foreach pin $pinList {
foreach portName $portList {
set pinName [$db oid pname $pin]
if {[string match $portName $pinName]} {
if {[$db oid type $pin] eq "pinBus"} {
$db foreach pin $pin member {
set startPinTable($member) $member
}
} else {
set startPinTable($pin) $pin
}
break
}
}
}
}
}
set result {}
foreach {key pin} [array get startPinTable] {
lappend result $pin
}
return $result
}
# -----------------------------------------------------------------------------
# _extractCone -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_extractCone {db dir startPin targetCells excludeCells} {
global CheckOneLoad
set command [list $db]
if {$CheckOneLoad(useExtractAPI)} {
lappend command extract new -resLimit 1
} else {
lappend command cone -shortestPath
}
lappend command [string range $dir 0 end-3]
lappend command -checkArcs
if {$CheckOneLoad(useExtractAPI)} {
lappend command -diveEmpty
} else {
lappend command -emptyModAsPrim
}
foreach targetCell $targetCells {
lappend command -targetCell $targetCell
}
foreach excludeCell $excludeCells {
lappend command -excludeCell $excludeCell
}
lappend command -excludeFlaggedCell green
lappend command -excludeFlaggedCell red
if {$CheckOneLoad(useExtractAPI)} {
lappend command [list $startPin]
set ext [{*}$command]
if {[catch {set res [$ext paths]}]} {
set res {}
}
$ext free
set res [lindex $res 0]
} else {
lappend command $startPin
if {[catch {set res [{*}$command]}]} {
set res {}
}
}
return $res
}
# -----------------------------------------------------------------------------
# _calculate -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_calculate {db dir index} {
global CheckOneLoad
set startPinList [CheckOneLoad:_getStartPinList $db $index]
set resultList $CheckOneLoad(customWidget).right.result
set ipCells {}
foreach ip [lsort -unique $CheckOneLoad(ipCells)] {
set cell [$db search cell $ip]
if {![$db oid isnull $cell]} {
lappend ipCells $ip
}
}
set i 0
set total [llength $startPinList]
set loopLimit [llength $ipCells]
set totalBegTime [zos currentRuntime -ns]
zmessage print DBG "Process $total start pins"
foreach startPin $startPinList {
zmessage print DBG "Start path extraction $i from: $startPin"
zprogress push "" [expr {[incr i] / double($total)}]
set l 0
set reachableTargets {}
set result {}
while {true} {
if {[incr l] > $loopLimit} {
break
}
set targetCells {}
set excludeCells {}
foreach ip $ipCells {
if {$ip in $reachableTargets} {
lappend excludeCells $ip
} else {
lappend targetCells $ip
}
}
if {$targetCells == {}} {
break
}
set res [CheckOneLoad:_extractCone $db \
$dir \
$startPin \
$targetCells \
$excludeCells]
if {$res == {}} {
break
} else {
lappend result $res
set targetPin [lindex $res end]
set targetCell [$db oid cname $targetPin]
lappend reachableTargets $targetCell
}
if {[llength $reachableTargets] > 1} {
set label [incr CheckOneLoad(violationCount)]
append label ": (" $dir ") " [$db oid print $startPin]
zmessage print DBG "Add result: $label"
set id [$resultList insert {} end \
-text $label \
-values [list $startPin $result]]
foreach res $result {
set targetPin [lindex $res end]
$resultList insert $id end \
-text [$db oid print $targetPin] \
-values [list $targetPin]
}
break
}
}
if {[zprogress pop]} {
break
}
}
set totalEndTime [zos currentRuntime -ns]
set totalRunTime [expr {($totalEndTime-$totalBegTime) / double(1000000000)}]
zmessage print DBG [format "Finish calculation in %.2fs" $totalRunTime]
}
# -----------------------------------------------------------------------------
# _showResult -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_showResult {w} {
set item [$w focus]
set values [$w item $item -values]
set parent [$w parent $item]
set targetPin {}
set db [gui database get]
if {$parent != {}} {
set targetPin [lindex $values 0]
set values [$w item $parent -values]
}
set startPin [lindex $values 0]
set result [lindex $values 1]
$db flathilight [$db get_top_design] deleteAll
$db flathilight $startPin set 1
$db flathilight [$db oid convertTo inst $startPin] set 1
set memList [list $startPin]
set coneList {}
foreach res $result {
set targetPin [lindex $res end]
$db flathilight $targetPin set 0
$db flathilight [$db oid convertTo inst $targetPin] set 0
lappend memList $targetPin
lappend coneList {*}$res
}
gui window show Mem
gui window show Cone
gui mem clear
gui mem append $memList
gui cone load $coneList
gui cone zoom fullfit
if {$parent != {}} {
gui goto [list $targetPin]
}
}
# -----------------------------------------------------------------------------
# _create -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_create {w} {
global CheckOneLoad
ttk::frame $w.left
ttk::button $w.left.start \
-text "Load Start Cells" \
-command [list CheckOneLoad:_readStartCellList]
ttk::button $w.left.ip \
-text "Load IP List" \
-command [list CheckOneLoad:_readIPList]
ttk::button $w.left.exclude \
-text "Load Exclude Cell List" \
-command [list CheckOneLoad:_readExcludeCellList]
ttk::button $w.left.analyze \
-text "Analyze the Design" \
-command [list CheckOneLoad:_start]
ttk::label $w.left.startCount -textvariable CheckOneLoad(startCellCount)
ttk::label $w.left.ipCount -textvariable CheckOneLoad(ipCellCount)
ttk::label $w.left.excludeCount -textvariable CheckOneLoad(excludeCellCount)
ttk::label $w.left.violations -textvariable CheckOneLoad(violationCount)
grid $w.left.start -row 0 -column 0 -padx 10 -pady 4 -sticky we
grid $w.left.startCount -row 0 -column 1 -padx 10 -pady 4 -sticky e
grid $w.left.ip -row 1 -column 0 -padx 10 -pady 4 -sticky we
grid $w.left.ipCount -row 1 -column 1 -padx 10 -pady 4 -sticky e
grid $w.left.exclude -row 2 -column 0 -padx 10 -pady 4 -sticky we
grid $w.left.excludeCount -row 2 -column 1 -padx 10 -pady 4 -sticky e
grid $w.left.analyze -row 3 -column 0 -padx 10 -pady 4 -sticky we
grid $w.left.violations -row 3 -column 1 -padx 10 -pady 4 -sticky e
ttk::frame $w.right
ttk::treeview $w.right.result
gui window autoscroll $w.right $w.right.result -direction y
bind $w.right.result <Double-1> [list CheckOneLoad:_showResult %W]
grid $w.left -row 0 -column 0 -sticky ns
grid $w.right -row 0 -column 1 -sticky news
grid rowconfigure $w 0 -weight 1
grid columnconfigure $w 1 -weight 1
}
# -----------------------------------------------------------------------------
# _toggle -
# -----------------------------------------------------------------------------
#
proc CheckOneLoad:_toggle {} {
global CheckOneLoad
if {$CheckOneLoad(showWidget)} {
set CheckOneLoad(customWidget) \
[gui window insertCustomWidget $CheckOneLoad(name)]
CheckOneLoad:_create $CheckOneLoad(customWidget)
} else {
gui window removeCustomWidget $CheckOneLoad(name)
}
}
# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
CheckOneLoad:Init $argc $argv
|