Skip to content

Commit 044f647

Browse files
committed
refactor: Use PtrSet and PtrMap aliases in ifp and pdn modules
- Refactored InitFloorplan (ifp) and PdnGen (pdn) C++ APIs and implementations to use odb::PtrSet and odb::PtrMap instead of raw std::set/std::map with ODBPtrLess. - Updated Python SWIG interfaces (InitFloorplan-py.i and PdnGen-py.i) to include PtrSetMap.h. - Used SWIG %apply directives to map odb::PtrSet and odb::PtrMap to the instantiated std::set/std::map templates, ensuring proper Python typemaps and full backwards compatibility. Signed-off-by: Drew Lewis <cannada@google.com>
1 parent 0b6f5a8 commit 044f647

6 files changed

Lines changed: 61 additions & 59 deletions

File tree

src/ifp/include/ifp/InitFloorplan.hh

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,27 @@ class InitFloorplan
4343
// utilization is in [0, 100]%
4444
// The base_site determines the single-height rows. For hybrid rows it is
4545
// a site containing a row pattern.
46-
void initFloorplan(
47-
double utilization,
48-
double aspect_ratio,
49-
int core_space_bottom,
50-
int core_space_top,
51-
int core_space_left,
52-
int core_space_right,
53-
odb::dbSite* base_site,
54-
const std::vector<odb::dbSite*>& additional_sites = {},
55-
RowParity row_parity = RowParity::kNone,
56-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites = {},
57-
int gap = std::numeric_limits<std::int32_t>::min());
46+
void initFloorplan(double utilization,
47+
double aspect_ratio,
48+
int core_space_bottom,
49+
int core_space_top,
50+
int core_space_left,
51+
int core_space_right,
52+
odb::dbSite* base_site,
53+
const std::vector<odb::dbSite*>& additional_sites = {},
54+
RowParity row_parity = RowParity::kNone,
55+
const odb::PtrSet<odb::dbSite>& flipped_sites = {},
56+
int gap = std::numeric_limits<std::int32_t>::min());
5857

5958
// The base_site determines the single-height rows. For hybrid rows it is
6059
// a site containing a row pattern.
61-
void initFloorplan(
62-
const odb::Rect& die,
63-
const odb::Rect& core,
64-
odb::dbSite* base_site,
65-
const std::vector<odb::dbSite*>& additional_sites = {},
66-
RowParity row_parity = RowParity::kNone,
67-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites = {},
68-
int gap = std::numeric_limits<std::int32_t>::min());
60+
void initFloorplan(const odb::Rect& die,
61+
const odb::Rect& core,
62+
odb::dbSite* base_site,
63+
const std::vector<odb::dbSite*>& additional_sites = {},
64+
RowParity row_parity = RowParity::kNone,
65+
const odb::PtrSet<odb::dbSite>& flipped_sites = {},
66+
int gap = std::numeric_limits<std::int32_t>::min());
6967

7068
void insertTiecells(odb::dbMTerm* tie_term,
7169
const std::string& prefix = "TIEOFF_");
@@ -87,35 +85,33 @@ class InitFloorplan
8785
// The base_site determines the single-height rows. For hybrid rows it is
8886
// a site containing a row pattern. core space is the padding on each side
8987
// to inset the rows.
90-
void makeRowsWithSpacing(
91-
int core_space_bottom,
92-
int core_space_top,
93-
int core_space_left,
94-
int core_space_right,
95-
odb::dbSite* base_site,
96-
const std::vector<odb::dbSite*>& additional_sites = {},
97-
RowParity row_parity = RowParity::kNone,
98-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites = {},
99-
int gap = std::numeric_limits<std::int32_t>::min());
88+
void makeRowsWithSpacing(int core_space_bottom,
89+
int core_space_top,
90+
int core_space_left,
91+
int core_space_right,
92+
odb::dbSite* base_site,
93+
const std::vector<odb::dbSite*>& additional_sites
94+
= {},
95+
RowParity row_parity = RowParity::kNone,
96+
const odb::PtrSet<odb::dbSite>& flipped_sites = {},
97+
int gap = std::numeric_limits<std::int32_t>::min());
10098

10199
// The base_site determines the single-height rows. For hybrid rows it is
102100
// a site containing a row pattern.
103101
void makeRows(const odb::Rect& core,
104102
odb::dbSite* base_site,
105103
const std::vector<odb::dbSite*>& additional_sites = {},
106104
RowParity row_parity = RowParity::kNone,
107-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites
108-
= {},
105+
const odb::PtrSet<odb::dbSite>& flipped_sites = {},
109106
int gap = std::numeric_limits<std::int32_t>::min());
110107

111108
// Create rows for a polygon core area using true polygon-aware generation
112-
void makePolygonRows(
113-
const odb::Polygon& core_polygon,
114-
odb::dbSite* base_site,
115-
const std::vector<odb::dbSite*>& additional_sites = {},
116-
RowParity row_parity = RowParity::kNone,
117-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites = {},
118-
int gap = std::numeric_limits<std::int32_t>::min());
109+
void makePolygonRows(const odb::Polygon& core_polygon,
110+
odb::dbSite* base_site,
111+
const std::vector<odb::dbSite*>& additional_sites = {},
112+
RowParity row_parity = RowParity::kNone,
113+
const odb::PtrSet<odb::dbSite>& flipped_sites = {},
114+
int gap = std::numeric_limits<std::int32_t>::min());
119115

120116
void makeTracks();
121117
void makeTracks(odb::dbTechLayer* layer,

src/ifp/src/InitFloorplan-py.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "odb/PtrSetMap.h"
77
%}
88

9+
%include "odb/PtrSetMap.h"
10+
911
%include "../../Exception-py.i"
1012

1113
%include <std_string.i>
@@ -46,4 +48,6 @@ namespace std {
4648
%template(site_set) std::set<odb::dbSite*, odb::ODBPtrLess>;
4749
}
4850

51+
%apply const std::set<odb::dbSite*, odb::ODBPtrLess>& { const odb::PtrSet<odb::dbSite>& };
52+
4953
%include "ifp/InitFloorplan.hh"

src/ifp/src/InitFloorplan.cc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void InitFloorplan::initFloorplan(
104104
odb::dbSite* base_site,
105105
const std::vector<odb::dbSite*>& additional_sites,
106106
RowParity row_parity,
107-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites,
107+
const odb::PtrSet<odb::dbSite>& flipped_sites,
108108
const int gap)
109109
{
110110
checkGap(gap);
@@ -134,7 +134,7 @@ void InitFloorplan::initFloorplan(
134134
odb::dbSite* base_site,
135135
const std::vector<odb::dbSite*>& additional_sites,
136136
RowParity row_parity,
137-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites,
137+
const odb::PtrSet<odb::dbSite>& flipped_sites,
138138
const int gap)
139139
{
140140
checkGap(gap);
@@ -263,7 +263,7 @@ void InitFloorplan::makePolygonRows(
263263
odb::dbSite* base_site,
264264
const std::vector<odb::dbSite*>& additional_sites,
265265
RowParity row_parity,
266-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites,
266+
const odb::PtrSet<odb::dbSite>& flipped_sites,
267267
const int gap)
268268
{
269269
checkGap(gap);
@@ -405,7 +405,7 @@ void InitFloorplan::makeRowsWithSpacing(
405405
odb::dbSite* base_site,
406406
const std::vector<odb::dbSite*>& additional_sites,
407407
RowParity row_parity,
408-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites,
408+
const odb::PtrSet<odb::dbSite>& flipped_sites,
409409
const int gap)
410410
{
411411
checkGap(gap);
@@ -440,13 +440,12 @@ void InitFloorplan::makeRowsWithSpacing(
440440
gap);
441441
}
442442

443-
void InitFloorplan::makeRows(
444-
const odb::Rect& core,
445-
odb::dbSite* base_site,
446-
const std::vector<odb::dbSite*>& additional_sites,
447-
RowParity row_parity,
448-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites,
449-
const int gap)
443+
void InitFloorplan::makeRows(const odb::Rect& core,
444+
odb::dbSite* base_site,
445+
const std::vector<odb::dbSite*>& additional_sites,
446+
RowParity row_parity,
447+
const odb::PtrSet<odb::dbSite>& flipped_sites,
448+
const int gap)
450449
{
451450
checkGap(gap);
452451

@@ -711,7 +710,7 @@ void InitFloorplan::makeUniformRows(
711710
const SitesByName& sites_by_name,
712711
const odb::Rect& core,
713712
RowParity row_parity,
714-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites)
713+
const odb::PtrSet<odb::dbSite>& flipped_sites)
715714
{
716715
const int core_dx = core.dx();
717716
const int core_dy = core.dy();
@@ -1152,7 +1151,7 @@ void InitFloorplan::makePolygonRowsScanline(
11521151
odb::dbSite* base_site,
11531152
const SitesByName& sites_by_name,
11541153
RowParity row_parity,
1155-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites,
1154+
const odb::PtrSet<odb::dbSite>& flipped_sites,
11561155
const int gap)
11571156
{
11581157
// Get the bounding box for the polygon
@@ -1290,7 +1289,7 @@ void InitFloorplan::makeUniformRowsPolygon(
12901289
const odb::Polygon& core_polygon,
12911290
const odb::Rect& core_bbox,
12921291
RowParity row_parity,
1293-
const std::set<odb::dbSite*, odb::ODBPtrLess>& flipped_sites)
1292+
const odb::PtrSet<odb::dbSite>& flipped_sites)
12941293
{
12951294
const uint32_t site_dx = site->getWidth();
12961295
const uint32_t site_dy = site->getHeight();

src/pdn/include/pdn/PdnGen.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ class PdnGen
149149
int max_rows,
150150
int max_columns,
151151
const std::vector<odb::dbTechLayer*>& ongrid,
152-
const std::map<odb::dbTechLayer*, std::pair<int, bool>, odb::ODBPtrLess>&
153-
split_cuts,
152+
const odb::PtrMap<odb::dbTechLayer, std::pair<int, bool>>& split_cuts,
154153
const std::string& dont_use_vias);
155154

156155
void writeToDb(bool add_pins, const std::string& report_file = "") const;
@@ -163,7 +162,7 @@ class PdnGen
163162

164163
void checkSetup() const;
165164

166-
void repairVias(const std::set<odb::dbNet*, odb::ODBPtrLess>& nets);
165+
void repairVias(const odb::PtrSet<odb::dbNet>& nets);
167166

168167
void createSrouteWires(const char* net,
169168
const char* outer_net,

src/pdn/src/PdnGen-py.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using namespace pdn;
1515
%}
1616

17+
%include "odb/PtrSetMap.h"
18+
1719
%include <std_vector.i>
1820
%include <std_array.i>
1921
%include <std_map.i>
@@ -45,5 +47,8 @@ namespace std {
4547
%template(net_set) std::set<odb::dbNet*, odb::ODBPtrLess>;
4648
}
4749

50+
%apply const std::map<odb::dbTechLayer*, std::pair<int, bool>, odb::ODBPtrLess>& { const odb::PtrMap<odb::dbTechLayer, std::pair<int, bool>>& };
51+
%apply const std::set<odb::dbNet*, odb::ODBPtrLess>& { const odb::PtrSet<odb::dbNet>& };
52+
4853
%include "../../Exception-py.i"
4954
%include "pdn/PdnGen.hh"

src/pdn/src/PdnGen.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,7 @@ void PdnGen::makeConnect(
669669
int max_rows,
670670
int max_columns,
671671
const std::vector<odb::dbTechLayer*>& ongrid,
672-
const std::map<odb::dbTechLayer*, std::pair<int, bool>, odb::ODBPtrLess>&
673-
split_cuts,
672+
const odb::PtrMap<odb::dbTechLayer, std::pair<int, bool>>& split_cuts,
674673
const std::string& dont_use_vias)
675674
{
676675
auto con = std::make_unique<Connect>(grid, layer0, layer1);
@@ -1001,7 +1000,7 @@ void PdnGen::checkSetup() const
10011000
}
10021001
}
10031002

1004-
void PdnGen::repairVias(const std::set<odb::dbNet*, odb::ODBPtrLess>& nets)
1003+
void PdnGen::repairVias(const odb::PtrSet<odb::dbNet>& nets)
10051004
{
10061005
ViaRepair repair(logger_, nets);
10071006
repair.repair();

0 commit comments

Comments
 (0)