-
Notifications
You must be signed in to change notification settings - Fork 946
Expand file tree
/
Copy pathdbBlock.cpp
More file actions
4054 lines (3477 loc) · 109 KB
/
Copy pathdbBlock.cpp
File metadata and controls
4054 lines (3477 loc) · 109 KB
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
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2019-2025, The OpenROAD Authors
#include "dbBlock.h"
#include <string.h> // NOLINT(modernize-deprecated-headers): for strdup()
#include <unistd.h>
#include <algorithm>
#include <cassert>
#include <cerrno>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <ios>
#include <iterator>
#include <list>
#include <map>
#include <optional>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "dbAccessPoint.h"
#include "dbBPin.h"
#include "dbBPinItr.h"
#include "dbBTerm.h"
#include "dbBTermItr.h"
#include "dbBlockItr.h"
#include "dbBlockage.h"
#include "dbBox.h"
#include "dbBoxItr.h"
#include "dbBusPort.h"
#include "dbCCSeg.h"
#include "dbCCSegItr.h"
#include "dbCapNode.h"
#include "dbCapNodeItr.h"
#include "dbChip.h"
#include "dbCommon.h"
#include "dbCore.h"
#include "dbDatabase.h"
#include "dbDft.h"
#include "dbFill.h"
#include "dbGCellGrid.h"
#include "dbGlobalConnect.h"
#include "dbGroup.h"
#include "dbGroupGroundNetItr.h"
#include "dbGroupInstItr.h"
#include "dbGroupItr.h"
#include "dbGroupModInstItr.h"
#include "dbGroupPowerNetItr.h"
#include "dbGuide.h"
#include "dbGuideItr.h"
#include "dbHashTable.h"
#include "dbHashTable.hpp"
#include "dbHier.h"
#include "dbITerm.h"
#include "dbITermItr.h"
#include "dbInst.h"
#include "dbInstHdr.h"
#include "dbIntHashTable.h"
#include "dbIntHashTable.hpp"
#include "dbIsolation.h"
#include "dbJournal.h"
#include "dbLevelShifter.h"
#include "dbLogicPort.h"
#include "dbMarkerCategory.h"
#include "dbModBTerm.h"
#include "dbModITerm.h"
#include "dbModInst.h"
#include "dbModNet.h"
#include "dbModule.h"
#include "dbModuleInstItr.h"
#include "dbModuleModBTermItr.h"
#include "dbModuleModInstItr.h"
#include "dbModuleModInstModITermItr.h"
#include "dbModuleModNetBTermItr.h"
#include "dbModuleModNetITermItr.h"
#include "dbModuleModNetItr.h"
#include "dbModuleModNetModBTermItr.h"
#include "dbModuleModNetModITermItr.h"
#include "dbNameCache.h"
#include "dbNet.h"
#include "dbNetTrack.h"
#include "dbNetTrackItr.h"
#include "dbObstruction.h"
#include "dbPagedVector.h"
#include "dbPowerDomain.h"
#include "dbPowerSwitch.h"
#include "dbProperty.h"
#include "dbPropertyItr.h"
#include "dbRSeg.h"
#include "dbRSegItr.h"
#include "dbRegion.h"
#include "dbRegionGroupItr.h"
#include "dbRegionInstItr.h"
#include "dbRow.h"
#include "dbSBox.h"
#include "dbSBoxItr.h"
#include "dbSWire.h"
#include "dbSWireItr.h"
#include "dbScanInst.h"
#include "dbScanListScanInstItr.h"
#include "dbTable.h"
#include "dbTech.h"
#include "dbTechLayer.h"
#include "dbTechLayerRule.h"
#include "dbTechNonDefaultRule.h"
#include "dbTrackGrid.h"
#include "dbVia.h"
#include "dbWire.h"
#include "odb/db.h"
#include "odb/dbBlockCallBackObj.h"
#include "odb/dbExtControl.h"
#include "odb/dbObject.h"
#include "odb/dbSet.h"
#include "odb/dbShape.h"
#include "odb/dbStream.h"
#include "odb/dbTypes.h"
#include "odb/defout.h"
#include "odb/geom.h"
#include "odb/geom_boost.h"
#include "odb/isotropy.h"
#include "odb/lefout.h"
#include "odb/poly_decomp.h"
#include "utl/Logger.h"
namespace odb {
struct OldTransform
{
int orient;
int originX;
int originY;
int sizeX;
int sizeY;
};
static void unlink_child_from_parent(_dbBlock* child, _dbBlock* parent);
// TODO: Bounding box updates...
template class dbTable<_dbBlock>;
template class dbHashTable<_dbNet>;
template class dbHashTable<_dbInst>;
template class dbIntHashTable<_dbInstHdr>;
template class dbHashTable<_dbBTerm>;
template class dbHashTable<_dbMarkerCategory>;
_dbBlock::_dbBlock(_dbDatabase* db)
{
flags_.valid_bbox = 0;
flags_.spare_bits = 0;
def_units_ = 100;
dbu_per_micron_ = 1000;
hier_delimiter_ = '/';
left_bus_delimiter_ = 0;
right_bus_delimiter_ = 0;
num_ext_corners_ = 0;
corners_per_block_ = 0;
corner_name_list_ = nullptr;
name_ = nullptr;
die_area_ = Rect(0, 0, 0, 0);
core_area_ = Rect(0, 0, 0, 0);
max_cap_node_id_ = 0;
max_rseg_id_ = 0;
max_cc_seg_id_ = 0;
min_routing_layer_ = 2;
max_routing_layer_ = -1;
min_layer_for_clock_ = -1;
max_layer_for_clock_ = -2;
currentCcAdjOrder_ = 0;
bterm_tbl_ = new dbTable<_dbBTerm>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbBTermObj);
iterm_tbl_ = new dbTable<_dbITerm, 1024>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbITermObj);
net_tbl_ = new dbTable<_dbNet>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbNetObj);
inst_hdr_tbl_ = new dbTable<_dbInstHdr>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbInstHdrObj);
inst_tbl_ = new dbTable<_dbInst>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbInstObj);
scan_inst_tbl_ = new dbTable<_dbScanInst>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbScanInstObj);
module_tbl_ = new dbTable<_dbModule>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbModuleObj);
modinst_tbl_ = new dbTable<_dbModInst>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbModInstObj);
modbterm_tbl_ = new dbTable<_dbModBTerm>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbModBTermObj);
moditerm_tbl_ = new dbTable<_dbModITerm>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbModITermObj);
modnet_tbl_ = new dbTable<_dbModNet>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbModNetObj);
busport_tbl_ = new dbTable<_dbBusPort>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbBusPortObj);
powerdomain_tbl_ = new dbTable<_dbPowerDomain>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbPowerDomainObj);
logicport_tbl_ = new dbTable<_dbLogicPort>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbLogicPortObj);
powerswitch_tbl_ = new dbTable<_dbPowerSwitch>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbPowerSwitchObj);
isolation_tbl_ = new dbTable<_dbIsolation>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbIsolationObj);
levelshifter_tbl_ = new dbTable<_dbLevelShifter>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbLevelShifterObj);
group_tbl_ = new dbTable<_dbGroup>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbGroupObj);
ap_tbl_ = new dbTable<_dbAccessPoint>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbAccessPointObj);
global_connect_tbl_ = new dbTable<_dbGlobalConnect>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbGlobalConnectObj);
guide_tbl_ = new dbTable<_dbGuide>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbGuideObj);
net_tracks_tbl_ = new dbTable<_dbNetTrack>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbNetTrackObj);
box_tbl_ = new dbTable<_dbBox, 1024>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbBoxObj);
via_tbl_ = new dbTable<_dbVia, 1024>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbViaObj);
gcell_grid_tbl_ = new dbTable<_dbGCellGrid>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbGCellGridObj);
track_grid_tbl_ = new dbTable<_dbTrackGrid>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbTrackGridObj);
obstruction_tbl_ = new dbTable<_dbObstruction>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbObstructionObj);
blockage_tbl_ = new dbTable<_dbBlockage>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbBlockageObj);
wire_tbl_ = new dbTable<_dbWire>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbWireObj);
swire_tbl_ = new dbTable<_dbSWire>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbSWireObj);
sbox_tbl_ = new dbTable<_dbSBox>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbSBoxObj);
row_tbl_ = new dbTable<_dbRow>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbRowObj);
fill_tbl_ = new dbTable<_dbFill>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbFillObj);
region_tbl_ = new dbTable<_dbRegion, 32>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbRegionObj);
hier_tbl_ = new dbTable<_dbHier, 16>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbHierObj);
bpin_tbl_ = new dbTable<_dbBPin>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbBPinObj);
non_default_rule_tbl_ = new dbTable<_dbTechNonDefaultRule, 16>(
db,
this,
(GetObjTbl_t) &_dbBlock::getObjectTable,
dbTechNonDefaultRuleObj);
layer_rule_tbl_ = new dbTable<_dbTechLayerRule, 16>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbTechLayerRuleObj);
prop_tbl_ = new dbTable<_dbProperty>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbPropertyObj);
name_cache_
= new _dbNameCache(db, this, (GetObjTbl_t) &_dbBlock::getObjectTable);
r_val_tbl_ = new dbPagedVector<float, 4096, 12>();
r_val_tbl_->push_back(0.0);
c_val_tbl_ = new dbPagedVector<float, 4096, 12>();
c_val_tbl_->push_back(0.0);
cc_val_tbl_ = new dbPagedVector<float, 4096, 12>();
cc_val_tbl_->push_back(0.0);
cap_node_tbl_ = new dbTable<_dbCapNode, 4096>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbCapNodeObj);
// We need to allocate the first cap-node (id == 1) to resolve a problem with
// the extraction code (Hopefully this is temporary)
cap_node_tbl_->create();
r_seg_tbl_ = new dbTable<_dbRSeg, 4096>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbRSegObj);
cc_seg_tbl_ = new dbTable<_dbCCSeg, 4096>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbCCSegObj);
ext_control_ = new dbExtControl();
dft_tbl_ = new dbTable<_dbDft, 4096>(
db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbDftObj);
_dbDft* dft_ptr = dft_tbl_->create();
dft_ptr->initialize();
dft_ = dft_ptr->getId();
net_hash_.setTable(net_tbl_);
inst_hash_.setTable(inst_tbl_);
module_hash_.setTable(module_tbl_);
modinst_hash_.setTable(modinst_tbl_);
powerdomain_hash_.setTable(powerdomain_tbl_);
logicport_hash_.setTable(logicport_tbl_);
powerswitch_hash_.setTable(powerswitch_tbl_);
isolation_hash_.setTable(isolation_tbl_);
levelshifter_hash_.setTable(levelshifter_tbl_);
group_hash_.setTable(group_tbl_);
inst_hdr_hash_.setTable(inst_hdr_tbl_);
bterm_hash_.setTable(bterm_tbl_);
net_bterm_itr_ = new dbNetBTermItr(bterm_tbl_);
net_iterm_itr_ = new dbNetITermItr(iterm_tbl_);
inst_iterm_itr_ = new dbInstITermItr(iterm_tbl_);
scan_list_scan_inst_itr_ = new dbScanListScanInstItr(scan_inst_tbl_);
box_itr_ = new dbBoxItr<1024>(box_tbl_, nullptr, false);
swire_itr_ = new dbSWireItr(swire_tbl_);
sbox_itr_ = new dbSBoxItr(sbox_tbl_);
cap_node_itr_ = new dbCapNodeItr(cap_node_tbl_);
r_seg_itr_ = new dbRSegItr(r_seg_tbl_);
cc_seg_itr_ = new dbCCSegItr(cc_seg_tbl_);
region_inst_itr_ = new dbRegionInstItr(inst_tbl_);
module_inst_itr_ = new dbModuleInstItr(inst_tbl_);
module_modinst_itr_ = new dbModuleModInstItr(modinst_tbl_);
module_modinstmoditerm_itr_ = new dbModuleModInstModITermItr(moditerm_tbl_);
module_modbterm_itr_ = new dbModuleModBTermItr(modbterm_tbl_);
module_modnet_itr_ = new dbModuleModNetItr(modnet_tbl_);
module_modnet_modbterm_itr_ = new dbModuleModNetModBTermItr(modbterm_tbl_);
module_modnet_moditerm_itr_ = new dbModuleModNetModITermItr(moditerm_tbl_);
module_modnet_iterm_itr_ = new dbModuleModNetITermItr(iterm_tbl_);
module_modnet_bterm_itr_ = new dbModuleModNetBTermItr(bterm_tbl_);
region_group_itr_ = new dbRegionGroupItr(group_tbl_);
group_itr_ = new dbGroupItr(group_tbl_);
guide_itr_ = new dbGuideItr(guide_tbl_);
net_track_itr_ = new dbNetTrackItr(net_tracks_tbl_);
group_inst_itr_ = new dbGroupInstItr(inst_tbl_);
group_modinst_itr_ = new dbGroupModInstItr(modinst_tbl_);
group_power_net_itr_ = new dbGroupPowerNetItr(net_tbl_);
group_ground_net_itr_ = new dbGroupGroundNetItr(net_tbl_);
bpin_itr_ = new dbBPinItr(bpin_tbl_);
prop_itr_ = new dbPropertyItr(prop_tbl_);
num_ext_dbs_ = 1;
search_db_ = nullptr;
extmi_ = nullptr;
journal_ = nullptr;
}
_dbBlock::~_dbBlock()
{
if (name_) {
free((void*) name_);
}
free(corner_name_list_);
delete bterm_tbl_;
delete iterm_tbl_;
delete net_tbl_;
delete inst_hdr_tbl_;
delete inst_tbl_;
delete scan_inst_tbl_;
delete module_tbl_;
delete modinst_tbl_;
delete modbterm_tbl_;
delete moditerm_tbl_;
delete modnet_tbl_;
delete busport_tbl_;
delete powerdomain_tbl_;
delete logicport_tbl_;
delete powerswitch_tbl_;
delete isolation_tbl_;
delete levelshifter_tbl_;
delete group_tbl_;
delete ap_tbl_;
delete global_connect_tbl_;
delete guide_tbl_;
delete net_tracks_tbl_;
delete box_tbl_;
delete via_tbl_;
delete gcell_grid_tbl_;
delete track_grid_tbl_;
delete obstruction_tbl_;
delete blockage_tbl_;
delete wire_tbl_;
delete swire_tbl_;
delete sbox_tbl_;
delete row_tbl_;
delete fill_tbl_;
delete region_tbl_;
delete hier_tbl_;
delete bpin_tbl_;
delete non_default_rule_tbl_;
delete layer_rule_tbl_;
delete prop_tbl_;
delete name_cache_;
delete r_val_tbl_;
delete c_val_tbl_;
delete cc_val_tbl_;
delete cap_node_tbl_;
delete r_seg_tbl_;
delete cc_seg_tbl_;
delete ext_control_;
delete net_bterm_itr_;
delete net_iterm_itr_;
delete inst_iterm_itr_;
delete scan_list_scan_inst_itr_;
delete box_itr_;
delete swire_itr_;
delete sbox_itr_;
delete cap_node_itr_;
delete r_seg_itr_;
delete cc_seg_itr_;
delete region_inst_itr_;
delete module_inst_itr_;
delete module_modinst_itr_;
delete module_modinstmoditerm_itr_;
delete module_modbterm_itr_;
delete module_modnet_itr_;
delete module_modnet_modbterm_itr_;
delete module_modnet_moditerm_itr_;
delete module_modnet_iterm_itr_;
delete module_modnet_bterm_itr_;
delete region_group_itr_;
delete group_itr_;
delete guide_itr_;
delete net_track_itr_;
delete group_inst_itr_;
delete group_modinst_itr_;
delete group_power_net_itr_;
delete group_ground_net_itr_;
delete bpin_itr_;
delete prop_itr_;
delete dft_tbl_;
while (!callbacks_.empty()) {
auto _cbitr = callbacks_.begin();
(*_cbitr)->removeOwner();
}
delete journal_;
}
void dbBlock::clear()
{
_dbBlock* block = (_dbBlock*) this;
_dbDatabase* db = block->getDatabase();
_dbBlock* parent = (_dbBlock*) getParent();
_dbChip* chip = (_dbChip*) getChip();
// save a copy of the name
char* name = safe_strdup(block->name_);
// save a copy of the delimiter
char delimiter = block->hier_delimiter_;
std::list<dbBlockCallBackObj*> callbacks;
// save callbacks
callbacks.swap(block->callbacks_);
// unlink the child from the parent
if (parent) {
unlink_child_from_parent(block, parent);
}
// destroy the block contents
block->~_dbBlock();
// call in-place new to create new block
new (block) _dbBlock(db);
// initialize the
block->initialize(chip, parent, name, delimiter);
// restore callbacks
block->callbacks_.swap(callbacks);
free((void*) name);
if (block->journal_) {
delete block->journal_;
block->journal_ = nullptr;
}
}
void _dbBlock::initialize(_dbChip* chip,
_dbBlock* parent,
const char* name,
char delimiter)
{
name_ = safe_strdup(name);
_dbBox* box = box_tbl_->create();
box->flags_.owner_type = dbBoxOwner::BLOCK;
box->owner_ = getOID();
box->shape_.rect.reset(INT_MAX, INT_MAX, INT_MIN, INT_MIN);
bbox_ = box->getOID();
chip_ = chip->getOID();
hier_delimiter_ = delimiter;
// create top module
_dbModule* _top = (_dbModule*) dbModule::create((dbBlock*) this, name);
top_module_ = _top->getOID();
if (parent) {
def_units_ = parent->def_units_;
dbu_per_micron_ = parent->dbu_per_micron_;
parent_ = parent->getOID();
parent->children_.push_back(getOID());
num_ext_corners_ = parent->num_ext_corners_;
corners_per_block_ = parent->corners_per_block_;
}
}
dbObjectTable* _dbBlock::getObjectTable(dbObjectType type)
{
switch (type) {
case dbInstHdrObj:
return inst_hdr_tbl_;
case dbInstObj:
return inst_tbl_;
case dbModuleObj:
return module_tbl_;
case dbModInstObj:
return modinst_tbl_;
case dbPowerDomainObj:
return powerdomain_tbl_;
case dbLogicPortObj:
return logicport_tbl_;
case dbPowerSwitchObj:
return powerswitch_tbl_;
case dbIsolationObj:
return isolation_tbl_;
case dbLevelShifterObj:
return levelshifter_tbl_;
case dbGroupObj:
return group_tbl_;
case dbAccessPointObj:
return ap_tbl_;
case dbGlobalConnectObj:
return global_connect_tbl_;
case dbGuideObj:
return guide_tbl_;
case dbNetTrackObj:
return net_tracks_tbl_;
case dbNetObj:
return net_tbl_;
case dbBTermObj:
return bterm_tbl_;
case dbITermObj:
return iterm_tbl_;
case dbBoxObj:
return box_tbl_;
case dbViaObj:
return via_tbl_;
case dbGCellGridObj:
return gcell_grid_tbl_;
case dbTrackGridObj:
return track_grid_tbl_;
case dbObstructionObj:
return obstruction_tbl_;
case dbBlockageObj:
return blockage_tbl_;
case dbWireObj:
return wire_tbl_;
case dbSWireObj:
return swire_tbl_;
case dbSBoxObj:
return sbox_tbl_;
case dbCapNodeObj:
return cap_node_tbl_;
case dbRSegObj:
return r_seg_tbl_;
case dbCCSegObj:
return cc_seg_tbl_;
case dbRowObj:
return row_tbl_;
case dbFillObj:
return fill_tbl_;
case dbRegionObj:
return region_tbl_;
case dbHierObj:
return hier_tbl_;
case dbBPinObj:
return bpin_tbl_;
case dbTechNonDefaultRuleObj:
return non_default_rule_tbl_;
case dbTechLayerRuleObj:
return layer_rule_tbl_;
case dbPropertyObj:
return prop_tbl_;
case dbDftObj:
return dft_tbl_;
default:
break;
}
return getTable()->getObjectTable(type);
}
dbOStream& operator<<(dbOStream& stream, const _dbBTermGroup& obj)
{
stream << obj.bterms;
stream << obj.order;
return stream;
}
dbIStream& operator>>(dbIStream& stream, _dbBTermGroup& obj)
{
stream >> obj.bterms;
stream >> obj.order;
return stream;
}
dbOStream& operator<<(dbOStream& stream, const _dbBTermTopLayerGrid& obj)
{
stream << obj.layer;
stream << obj.x_step;
stream << obj.y_step;
stream << obj.region;
stream << obj.pin_width;
stream << obj.pin_height;
stream << obj.keepout;
return stream;
}
dbIStream& operator>>(dbIStream& stream, _dbBTermTopLayerGrid& obj)
{
stream >> obj.layer;
stream >> obj.x_step;
stream >> obj.y_step;
stream >> obj.region;
stream >> obj.pin_width;
stream >> obj.pin_height;
stream >> obj.keepout;
return stream;
}
dbOStream& operator<<(dbOStream& stream, const _dbBlock& block)
{
std::list<dbBlockCallBackObj*>::const_iterator cbitr;
for (cbitr = block.callbacks_.begin(); cbitr != block.callbacks_.end();
++cbitr) {
(**cbitr)().inDbBlockStreamOutBefore(
(dbBlock*) &block); // client ECO initialization - payam
}
dbOStreamScope scope(stream, "dbBlock");
stream << block.def_units_;
stream << block.dbu_per_micron_;
stream << block.hier_delimiter_;
stream << block.left_bus_delimiter_;
stream << block.right_bus_delimiter_;
stream << block.num_ext_corners_;
stream << block.corners_per_block_;
stream << block.corner_name_list_;
stream << block.name_;
stream << block.die_area_;
stream << block.core_area_;
stream << block.blocked_regions_for_pins_;
stream << block.chip_;
stream << block.bbox_;
stream << block.parent_;
stream << block.next_block_;
stream << block.gcell_grid_;
stream << block.parent_block_;
stream << block.parent_inst_;
stream << block.top_module_;
stream << block.net_hash_;
stream << block.inst_hash_;
stream << block.module_hash_;
stream << block.modinst_hash_;
stream << block.powerdomain_hash_;
stream << block.logicport_hash_;
stream << block.powerswitch_hash_;
stream << block.isolation_hash_;
stream << block.levelshifter_hash_;
stream << block.group_hash_;
stream << block.inst_hdr_hash_;
stream << block.bterm_hash_;
stream << block.max_cap_node_id_;
stream << block.max_rseg_id_;
stream << block.max_cc_seg_id_;
stream << block.children_;
stream << block.component_mask_shift_;
stream << block.currentCcAdjOrder_;
stream << *block.bterm_tbl_;
stream << *block.iterm_tbl_;
stream << *block.net_tbl_;
stream << *block.inst_hdr_tbl_;
stream << *block.module_tbl_;
stream << *block.inst_tbl_;
stream << *block.scan_inst_tbl_;
stream << *block.modinst_tbl_;
stream << *block.modbterm_tbl_;
stream << *block.busport_tbl_;
stream << *block.moditerm_tbl_;
stream << *block.modnet_tbl_;
stream << *block.powerdomain_tbl_;
stream << *block.logicport_tbl_;
stream << *block.powerswitch_tbl_;
stream << *block.isolation_tbl_;
stream << *block.levelshifter_tbl_;
stream << *block.group_tbl_;
stream << *block.ap_tbl_;
stream << *block.global_connect_tbl_;
stream << *block.guide_tbl_;
stream << *block.net_tracks_tbl_;
stream << *block.box_tbl_;
stream << *block.via_tbl_;
stream << *block.gcell_grid_tbl_;
stream << *block.track_grid_tbl_;
stream << *block.obstruction_tbl_;
stream << *block.blockage_tbl_;
stream << *block.wire_tbl_;
stream << *block.swire_tbl_;
stream << *block.sbox_tbl_;
stream << *block.row_tbl_;
stream << *block.fill_tbl_;
stream << *block.region_tbl_;
stream << *block.hier_tbl_;
stream << *block.bpin_tbl_;
stream << *block.non_default_rule_tbl_;
stream << *block.layer_rule_tbl_;
stream << *block.prop_tbl_;
stream << *block.name_cache_;
stream << *block.r_val_tbl_;
stream << *block.c_val_tbl_;
stream << *block.cc_val_tbl_;
stream << NamedTable("cap_node_tbl", block.cap_node_tbl_);
stream << NamedTable("r_seg_tbl", block.r_seg_tbl_);
stream << NamedTable("cc_seg_tbl", block.cc_seg_tbl_);
stream << *block.ext_control_;
stream << block.dft_;
stream << *block.dft_tbl_;
stream << block.min_routing_layer_;
stream << block.max_routing_layer_;
stream << block.min_layer_for_clock_;
stream << block.max_layer_for_clock_;
stream << block.bterm_groups_;
stream << block.bterm_top_layer_grid_;
stream << block.inst_scan_inst_map_;
stream << block.unique_net_index_;
stream << block.unique_inst_index_;
//---------------------------------------------------------- stream out
// properties
// TOM
dbObjectTable* table = block.getTable();
dbId<_dbProperty> propList = table->getPropList(block.getOID());
stream << propList;
// TOM
//----------------------------------------------------------
for (cbitr = block.callbacks_.begin(); cbitr != block.callbacks_.end();
++cbitr) {
(*cbitr)->inDbBlockStreamOutAfter((dbBlock*) &block);
}
return stream;
}
/**
* @brief Rebuilds the name-to-ID hash maps for hierarchical objects within
* their respective modules.
*
* This function is used during database loading (operator>>) to restore the
* fast-lookup hashes that were stored in the ODB.
*
* @tparam T The public ODB object type (e.g., dbInst, dbModNet).
* @tparam T_impl The internal implementation type (e.g., _dbInst, _dbModNet).
* @param block The database block containing the objects.
* @param table The internal database table storing the object implementations.
* @param module_field Member pointer to the field storing the parent module ID
* (e.g., &_dbInst::module_ or &_dbModInst::parent_).
* @param hash_field Member pointer to the hash map member in _dbModule where
* the object ID should be stored.
*/
template <typename T, typename T_impl>
static void rebuildModuleHash(
_dbBlock& block,
dbTable<T_impl>* table,
dbId<_dbModule> T_impl::*module_field,
std::unordered_map<std::string, dbId<T_impl>> _dbModule::*hash_field)
{
dbSet<T> items((dbBlock*) &block, table);
for (T* obj : items) {
T_impl* _obj = (T_impl*) obj;
dbId<_dbModule> mid = _obj->*module_field;
if (mid == 0) {
mid = block.top_module_;
}
_dbModule* module = block.module_tbl_->getPtr(mid);
if (module && _obj->name_) {
(module->*hash_field)[_obj->name_] = _obj->getId();
}
}
}
dbIStream& operator>>(dbIStream& stream, _dbBlock& block)
{
_dbDatabase* db = block.getImpl()->getDatabase();
stream >> block.def_units_;
stream >> block.dbu_per_micron_;
stream >> block.hier_delimiter_;
stream >> block.left_bus_delimiter_;
stream >> block.right_bus_delimiter_;
stream >> block.num_ext_corners_;
stream >> block.corners_per_block_;
stream >> block.corner_name_list_;
stream >> block.name_;
if (db->isSchema(kSchemaDieAreaIsPolygon)) {
stream >> block.die_area_;
} else {
Rect rect;
stream >> rect;
block.die_area_ = rect;
}
if (db->isSchema(kSchemaCoreAreaIsPolygon)) {
stream >> block.core_area_;
}
if (db->isSchema(kSchemaDbBlockBlockedRegionsForPins)) {
stream >> block.blocked_regions_for_pins_;
}
// In the older schema we can't set the tech here, we handle this later in
// dbDatabase.
dbId<_dbTech> old_db_tech;
if (db->isSchema(kSchemaBlockTech) && !db->isSchema(kSchemaChipTech)) {
stream >> old_db_tech;
}
stream >> block.chip_;
stream >> block.bbox_;
stream >> block.parent_;
stream >> block.next_block_;
stream >> block.gcell_grid_;
stream >> block.parent_block_;
stream >> block.parent_inst_;
stream >> block.top_module_;
stream >> block.net_hash_;
stream >> block.inst_hash_;
stream >> block.module_hash_;
stream >> block.modinst_hash_;
if (db->isSchema(kSchemaUpdateHierarchy)) {
if (!db->isSchema(kSchemaDbRemoveHash)) {
dbHashTable<_dbModBTerm> unused_modbterm_hash;
dbHashTable<_dbModITerm> unused_moditerm_hash;
dbHashTable<_dbModNet> unused_modnet_hash;
dbHashTable<_dbBusPort> unused_busport_hash;
stream >> unused_modbterm_hash;
stream >> unused_moditerm_hash;
stream >> unused_modnet_hash;
stream >> unused_busport_hash;
}
}
stream >> block.powerdomain_hash_;
stream >> block.logicport_hash_;
stream >> block.powerswitch_hash_;
stream >> block.isolation_hash_;
if (db->isSchema(kSchemaLevelShifter)) {
stream >> block.levelshifter_hash_;
}
stream >> block.group_hash_;
stream >> block.inst_hdr_hash_;
stream >> block.bterm_hash_;
stream >> block.max_cap_node_id_;
stream >> block.max_rseg_id_;
stream >> block.max_cc_seg_id_;
if (!db->isSchema(kSchemaBlockExtModelIndex)) {
int ignore_minExtModelIndex;
int ignore_maxExtModelIndex;
stream >> ignore_minExtModelIndex;
stream >> ignore_maxExtModelIndex;
}
stream >> block.children_;
if (db->isSchema(kSchemaBlockComponentMaskShift)) {
stream >> block.component_mask_shift_;
}
stream >> block.currentCcAdjOrder_;
stream >> *block.bterm_tbl_;
stream >> *block.iterm_tbl_;
stream >> *block.net_tbl_;
stream >> *block.inst_hdr_tbl_;
if (db->isSchema(kSchemaDbRemoveHash)) {
stream >> *block.module_tbl_;
stream >> *block.inst_tbl_;
} else {
stream >> *block.inst_tbl_;
stream >> *block.module_tbl_;
}
if (db->isSchema(kSchemaDbRemoveHash)) {
// Construct dbinst_hash_
rebuildModuleHash<dbInst>(
block, block.inst_tbl_, &_dbInst::module_, &_dbModule::dbinst_hash_);
}
if (db->isSchema(kSchemaBlockOwnsScanInsts)) {
stream >> *block.scan_inst_tbl_;
}
stream >> *block.modinst_tbl_;
if (db->isSchema(kSchemaDbRemoveHash)) {