Skip to content

Commit 2ef7fd0

Browse files
authored
Merge pull request #8269 from The-OpenROAD-Project-staging/cugr-refactor
grt: make x/y private in PointT in cugr
2 parents d4a4962 + c14a0cf commit 2ef7fd0

File tree

8 files changed

+155
-138
lines changed

8 files changed

+155
-138
lines changed

src/grt/src/cugr/include/geo.h

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,59 @@ namespace grt {
1616
class PointT
1717
{
1818
public:
19-
int x, y;
20-
PointT(int xx = std::numeric_limits<int>::max(),
21-
int yy = std::numeric_limits<int>::max())
22-
: x(xx), y(yy)
19+
PointT(int x = std::numeric_limits<int>::max(),
20+
int y = std::numeric_limits<int>::max())
21+
: x_(x), y_(y)
2322
{
2423
}
2524
bool IsValid() { return *this != PointT(); }
2625

26+
int x() const { return x_; }
27+
int y() const { return y_; }
28+
2729
// Operators
2830
const int& operator[](const unsigned d) const
2931
{
3032
assert(d == 0 || d == 1);
31-
return (d == 0 ? x : y);
33+
return (d == 0 ? x_ : y_);
3234
}
3335
int& operator[](const unsigned d)
3436
{
3537
assert(d == 0 || d == 1);
36-
return (d == 0 ? x : y);
38+
return (d == 0 ? x_ : y_);
39+
}
40+
PointT operator+(const PointT& rhs)
41+
{
42+
return PointT(x_ + rhs.x_, y_ + rhs.y_);
3743
}
38-
PointT operator+(const PointT& rhs) { return PointT(x + rhs.x, y + rhs.y); }
39-
PointT operator/(int divisor) { return PointT(x / divisor, y / divisor); }
44+
PointT operator/(int divisor) { return PointT(x_ / divisor, y_ / divisor); }
4045
PointT& operator+=(const PointT& rhs)
4146
{
42-
x += rhs.x;
43-
y += rhs.y;
47+
x_ += rhs.x_;
48+
y_ += rhs.y_;
4449
return *this;
4550
}
4651
PointT& operator-=(const PointT& rhs)
4752
{
48-
x -= rhs.x;
49-
y -= rhs.y;
53+
x_ -= rhs.x_;
54+
y_ -= rhs.y_;
5055
return *this;
5156
}
52-
bool operator==(const PointT& rhs) const { return x == rhs.x && y == rhs.y; }
57+
bool operator==(const PointT& rhs) const
58+
{
59+
return x_ == rhs.x_ && y_ == rhs.y_;
60+
}
5361
bool operator!=(const PointT& rhs) const { return !(*this == rhs); }
5462

5563
friend std::ostream& operator<<(std::ostream& os, const PointT& pt)
5664
{
57-
os << "(" << pt.x << ", " << pt.y << ")";
65+
os << "(" << pt.x_ << ", " << pt.y_ << ")";
5866
return os;
5967
}
68+
69+
private:
70+
int x_;
71+
int y_;
6072
};
6173

6274
// Interval template
@@ -228,7 +240,7 @@ class BoxT
228240
x.Set(xVal);
229241
y.Set(yVal);
230242
}
231-
void Set(const PointT& pt) { Set(pt.x, pt.y); }
243+
void Set(const PointT& pt) { Set(pt.x(), pt.y()); }
232244
void Set(int lx, int ly, int hx, int hy)
233245
{
234246
x.Set(lx, hx);
@@ -241,7 +253,7 @@ class BoxT
241253
}
242254
void Set(const PointT& low, const PointT& high)
243255
{
244-
Set(low.x, low.y, high.x, high.y);
256+
Set(low.x(), low.y(), high.x(), high.y());
245257
}
246258
void Set(const BoxT& box) { Set(box.x, box.y); }
247259

@@ -282,8 +294,8 @@ class BoxT
282294
x.FastUpdate(xVal);
283295
y.FastUpdate(yVal);
284296
}
285-
void Update(const PointT& pt) { Update(pt.x, pt.y); }
286-
void FastUpdate(const PointT& pt) { FastUpdate(pt.x, pt.y); }
297+
void Update(const PointT& pt) { Update(pt.x(), pt.y()); }
298+
void FastUpdate(const PointT& pt) { FastUpdate(pt.x(), pt.y()); }
287299

288300
// Geometric Query/Update
289301
BoxT UnionWith(const BoxT& rhs) const
@@ -304,15 +316,15 @@ class BoxT
304316
} // tighter
305317
bool Contain(const PointT& pt) const
306318
{
307-
return x.Contain(pt.x) && y.Contain(pt.y);
319+
return x.Contain(pt.x()) && y.Contain(pt.y());
308320
}
309321
bool StrictlyContain(const PointT& pt) const
310322
{
311-
return x.StrictlyContain(pt.x) && y.StrictlyContain(pt.y);
323+
return x.StrictlyContain(pt.x()) && y.StrictlyContain(pt.y());
312324
}
313325
PointT GetNearestPointTo(const PointT& pt)
314326
{
315-
return {x.GetNearestPointTo(pt.x), y.GetNearestPointTo(pt.y)};
327+
return {x.GetNearestPointTo(pt.x()), y.GetNearestPointTo(pt.y())};
316328
}
317329
BoxT GetNearestPointsTo(BoxT val) const
318330
{
@@ -321,8 +333,8 @@ class BoxT
321333

322334
void ShiftBy(const PointT& rhs)
323335
{
324-
x.ShiftBy(rhs.x);
325-
y.ShiftBy(rhs.y);
336+
x.ShiftBy(rhs.x());
337+
y.ShiftBy(rhs.y());
326338
}
327339

328340
bool operator==(const BoxT& rhs) const

src/grt/src/cugr/src/CUGR.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ NetRouteMap CUGR::getRoutes()
204204
routing_tree, [&](const std::shared_ptr<GRTreeNode>& node) {
205205
for (const auto& child : node->children) {
206206
if (node->getLayerIdx() == child->getLayerIdx()) {
207-
auto [min_x, max_x] = std::minmax(node->x, child->x);
208-
auto [min_y, max_y] = std::minmax(node->y, child->y);
207+
auto [min_x, max_x] = std::minmax({node->x(), child->x()});
208+
auto [min_y, max_y] = std::minmax({node->y(), child->y()});
209209
GSegment segment(
210210
grid_graph_->getGridline(0, min_x) + half_gcell_size,
211211
grid_graph_->getGridline(1, min_y) + half_gcell_size,
@@ -223,11 +223,11 @@ NetRouteMap CUGR::getRoutes()
223223
for (int layer_idx = bottom_layer; layer_idx < top_layer;
224224
layer_idx++) {
225225
GSegment segment(
226-
grid_graph_->getGridline(0, node->x) + half_gcell_size,
227-
grid_graph_->getGridline(1, node->y) + half_gcell_size,
226+
grid_graph_->getGridline(0, node->x()) + half_gcell_size,
227+
grid_graph_->getGridline(1, node->y()) + half_gcell_size,
228228
layer_idx + 1,
229-
grid_graph_->getGridline(0, node->x) + half_gcell_size,
230-
grid_graph_->getGridline(1, node->y) + half_gcell_size,
229+
grid_graph_->getGridline(0, node->x()) + half_gcell_size,
230+
grid_graph_->getGridline(1, node->y()) + half_gcell_size,
231231
layer_idx + 2,
232232
true);
233233
route.push_back(segment);
@@ -266,18 +266,18 @@ void CUGR::getGuides(const GRNet* net,
266266
for (const auto& child : node->children) {
267267
if (node->getLayerIdx() == child->getLayerIdx()) {
268268
guides.emplace_back(node->getLayerIdx(),
269-
BoxT(std::min(node->x, child->x),
270-
std::min(node->y, child->y),
271-
std::max(node->x, child->x),
272-
std::max(node->y, child->y)));
269+
BoxT(std::min(node->x(), child->x()),
270+
std::min(node->y(), child->y()),
271+
std::max(node->x(), child->x()),
272+
std::max(node->y(), child->y())));
273273
} else {
274274
int maxLayerIndex
275275
= std::max(node->getLayerIdx(), child->getLayerIdx());
276276
for (int layerIdx
277277
= std::min(node->getLayerIdx(), child->getLayerIdx());
278278
layerIdx <= maxLayerIndex;
279279
layerIdx++) {
280-
guides.emplace_back(layerIdx, BoxT(node->x, node->y));
280+
guides.emplace_back(layerIdx, BoxT(node->x(), node->y()));
281281
}
282282
}
283283
}
@@ -287,18 +287,18 @@ void CUGR::getGuides(const GRNet* net,
287287
double resource = std::numeric_limits<double>::max();
288288
unsigned direction = grid_graph_->getLayerDirection(point.getLayerIdx());
289289
if (point[direction] + 1 < grid_graph_->getSize(direction)) {
290-
resource
291-
= std::min(resource,
292-
grid_graph_->getEdge(point.getLayerIdx(), point.x, point.y)
293-
.getResource());
290+
resource = std::min(
291+
resource,
292+
grid_graph_->getEdge(point.getLayerIdx(), point.x(), point.y())
293+
.getResource());
294294
}
295295
if (point[direction] > 0) {
296296
GRPoint lower = point;
297297
lower[direction] -= 1;
298-
resource
299-
= std::min(resource,
300-
grid_graph_->getEdge(lower.getLayerIdx(), point.x, point.y)
301-
.getResource());
298+
resource = std::min(
299+
resource,
300+
grid_graph_->getEdge(lower.getLayerIdx(), point.x(), point.y())
301+
.getResource());
302302
}
303303
return resource;
304304
};
@@ -309,7 +309,7 @@ void CUGR::getGuides(const GRNet* net,
309309
for (auto& gpt : gpts) {
310310
if (gpt.getLayerIdx() < constants_.min_routing_layer) {
311311
int padding = 0;
312-
if (getSpareResource({constants_.min_routing_layer, gpt.x, gpt.y})
312+
if (getSpareResource({constants_.min_routing_layer, gpt.x(), gpt.y()})
313313
< constants_.pin_patch_threshold) {
314314
padding = constants_.pin_patch_padding;
315315
}
@@ -318,10 +318,11 @@ void CUGR::getGuides(const GRNet* net,
318318
layerIdx++) {
319319
guides.emplace_back(
320320
layerIdx,
321-
BoxT(std::max(gpt.x - padding, 0),
322-
std::max(gpt.y - padding, 0),
323-
std::min(gpt.x + padding, (int) grid_graph_->getSize(0) - 1),
324-
std::min(gpt.y + padding,
321+
BoxT(std::max(gpt.x() - padding, 0),
322+
std::max(gpt.y() - padding, 0),
323+
std::min(gpt.x() + padding,
324+
(int) grid_graph_->getSize(0) - 1),
325+
std::min(gpt.y() + padding,
325326
(int) grid_graph_->getSize(1) - 1)));
326327
area_of_pin_patches_ += (guides.back().second.x.range() + 1)
327328
* (guides.back().second.y.range() + 1);
@@ -354,8 +355,9 @@ void CUGR::getGuides(const GRNet* net,
354355
|| layerIndex >= grid_graph_->getNumLayers()) {
355356
continue;
356357
}
357-
if (getSpareResource({layerIndex, point.x, point.y}) >= 1.0) {
358-
guides.emplace_back(layerIndex, BoxT(point.x, point.y));
358+
if (getSpareResource({layerIndex, point.x(), point.y()})
359+
>= 1.0) {
360+
guides.emplace_back(layerIndex, BoxT(point.x(), point.y()));
359361
area_of_wire_patches_ += 1;
360362
patched = true;
361363
}

src/grt/src/cugr/src/GRTree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GRPoint : public PointT
1414
GRPoint(int l, int _x, int _y) : PointT(_x, _y), layer_idx_(l) {}
1515
friend std::ostream& operator<<(std::ostream& os, const GRPoint& pt)
1616
{
17-
os << "(" << pt.layer_idx_ << ", " << pt.x << ", " << pt.y << ")";
17+
os << "(" << pt.layer_idx_ << ", " << pt.x() << ", " << pt.y() << ")";
1818
return os;
1919
}
2020
int getLayerIdx() const { return layer_idx_; }

0 commit comments

Comments
 (0)