Skip to content

Commit 2653a3e

Browse files
authored
Merge pull request #7994 from The-OpenROAD-Project-staging/grt-fr-refactoring
Grt fr refactoring
2 parents 6aba20d + 31dfcdd commit 2653a3e

File tree

4 files changed

+69
-202
lines changed

4 files changed

+69
-202
lines changed

src/grt/src/fastroute/include/DataType.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string>
99
#include <vector>
1010

11+
#include "odb/geom.h"
1112
#include "utl/Logger.h"
1213

1314
namespace odb {
@@ -48,7 +49,7 @@ enum class EdgeDirection
4849
struct Segment // A Segment is a 2-pin connection
4950
{
5051
Segment(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int8_t cost)
51-
: x1(x1), y1(y1), x2(x2), y2(y2), cost(cost)
52+
: x1(x1), y1(y1), x2(x2), y2(y2), cost(cost), xFirst(false), HVH(false)
5253
{
5354
}
5455
const int16_t x1, y1, x2, y2; // coordinates of two endpoints (x1 <= x2)
@@ -78,6 +79,7 @@ struct FrNet // A Net is a set of connected MazePoints
7879
const std::vector<int>& getPinX() const { return pin_x_; }
7980
const std::vector<int>& getPinY() const { return pin_y_; }
8081
const std::vector<int>& getPinL() const { return pin_l_; }
82+
odb::Rect getPinBBox() const;
8183

8284
void addPin(int x, int y, int layer);
8385
void reset(odb::dbNet* db_net,

src/grt/src/fastroute/src/FastRoute.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,4 +1620,18 @@ void FrNet::reset(odb::dbNet* db_net,
16201620
pin_l_.clear();
16211621
}
16221622

1623+
odb::Rect FrNet::getPinBBox() const
1624+
{
1625+
odb::Rect rect;
1626+
rect.mergeInit();
1627+
1628+
const int deg = getNumPins();
1629+
for (int i = 0; i < deg; i++) {
1630+
const int x = getPinX(i);
1631+
const int y = getPinY(i);
1632+
rect.merge({x, y});
1633+
}
1634+
return rect;
1635+
}
1636+
16231637
} // namespace grt

src/grt/src/fastroute/src/RSMT.cpp

Lines changed: 48 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Pnt
1919
int o;
2020
};
2121

22-
int orderx(const Pnt* a, const Pnt* b)
22+
static int orderx(const Pnt* a, const Pnt* b)
2323
{
2424
return a->x < b->x;
2525
}
@@ -138,79 +138,34 @@ void FastRouteCore::fluteNormal(const int netID,
138138

139139
if (d == 2) {
140140
t.deg = 2;
141-
t.length = abs(x[0] - x[1]) + abs(y[0] - y[1]);
141+
t.length = std::abs(x[0] - x[1]) + std::abs(y[0] - y[1]);
142142
t.branch.resize(2);
143-
t.branch[0].x = x[0];
144-
t.branch[0].y = y[0];
145-
t.branch[0].n = 1;
146-
t.branch[1].x = x[1];
147-
t.branch[1].y = y[1];
148-
t.branch[1].n = 1;
143+
t.branch[0] = {x[0], y[0], 1};
144+
t.branch[1] = {x[1], y[1], 1};
149145
} else if (d == 3) {
150146
t.deg = 3;
151-
int x_max, x_min, x_mid;
152-
if (x[0] < x[1]) {
153-
if (x[0] < x[2]) {
154-
x_min = x[0];
155-
std::tie(x_mid, x_max) = std::minmax(x[1], x[2]);
156-
} else {
157-
x_min = x[2];
158-
x_mid = x[0];
159-
x_max = x[1];
160-
}
161-
} else {
162-
if (x[0] < x[2]) {
163-
x_min = x[1];
164-
x_mid = x[0];
165-
x_max = x[2];
166-
} else {
167-
std::tie(x_min, x_mid) = std::minmax(x[1], x[2]);
168-
x_max = x[0];
169-
}
170-
}
171-
int y_max, y_min, y_mid;
172-
if (y[0] < y[1]) {
173-
if (y[0] < y[2]) {
174-
y_min = y[0];
175-
std::tie(y_mid, y_max) = std::minmax(y[1], y[2]);
176-
} else {
177-
y_min = y[2];
178-
y_mid = y[0];
179-
y_max = y[1];
180-
}
181-
} else {
182-
if (y[0] < y[2]) {
183-
y_min = y[1];
184-
y_mid = y[0];
185-
y_max = y[2];
186-
} else {
187-
std::tie(y_min, y_mid) = std::minmax(y[1], y[2]);
188-
y_max = y[0];
189-
}
190-
}
147+
auto sort = [](const std::vector<int>& v) {
148+
std::array<int, 3> tmp{v[0], v[1], v[2]};
149+
std::sort(tmp.begin(), tmp.end());
150+
return tmp;
151+
};
152+
auto [x_min, x_mid, x_max] = sort(x);
153+
auto [y_min, y_mid, y_max] = sort(y);
191154

192155
t.length = abs(x_max - x_min) + abs(y_max - y_min);
193156
t.branch.resize(4);
194-
t.branch[0].x = x[0];
195-
t.branch[0].y = y[0];
196-
t.branch[0].n = 3;
197-
t.branch[1].x = x[1];
198-
t.branch[1].y = y[1];
199-
t.branch[1].n = 3;
200-
t.branch[2].x = x[2];
201-
t.branch[2].y = y[2];
202-
t.branch[2].n = 3;
203-
t.branch[3].x = x_mid;
204-
t.branch[3].y = y_mid;
205-
t.branch[3].n = 3;
157+
t.branch[0] = {x[0], y[0], 3};
158+
t.branch[1] = {x[1], y[1], 3};
159+
t.branch[2] = {x[2], y[2], 3};
160+
t.branch[3] = {x_mid, y_mid, 3};
206161
} else {
207162
std::vector<int> xs(d);
208163
std::vector<int> ys(d);
209164

210165
std::vector<int> tmp_xs(d);
211166
std::vector<int> tmp_ys(d);
212167
std::vector<int> s(d);
213-
Pnt* pt = new Pnt[d];
168+
std::vector<Pnt> pt(d);
214169
std::vector<Pnt*> ptp(d);
215170

216171
for (int i = 0; i < d; i++) {
@@ -284,8 +239,6 @@ void FastRouteCore::fluteNormal(const int netID,
284239
branch.x /= 100;
285240
branch.y /= ((int) (100 * coeffV));
286241
}
287-
288-
delete[] pt;
289242
}
290243
}
291244

@@ -303,69 +256,24 @@ void FastRouteCore::fluteCongest(const int netID,
303256
t.deg = 2;
304257
t.length = abs(x[0] - x[1]) + abs(y[0] - y[1]);
305258
t.branch.resize(2);
306-
t.branch[0].x = x[0];
307-
t.branch[0].y = y[0];
308-
t.branch[0].n = 1;
309-
t.branch[1].x = x[1];
310-
t.branch[1].y = y[1];
311-
t.branch[1].n = 1;
259+
t.branch[0] = {x[0], y[0], 1};
260+
t.branch[1] = {x[1], y[1], 1};
312261
} else if (d == 3) {
313262
t.deg = 3;
314-
int x_max, x_min, x_mid;
315-
if (x[0] < x[1]) {
316-
if (x[0] < x[2]) {
317-
x_min = x[0];
318-
std::tie(x_mid, x_max) = std::minmax(x[1], x[2]);
319-
} else {
320-
x_min = x[2];
321-
x_mid = x[0];
322-
x_max = x[1];
323-
}
324-
} else {
325-
if (x[0] < x[2]) {
326-
x_min = x[1];
327-
x_mid = x[0];
328-
x_max = x[2];
329-
} else {
330-
std::tie(x_min, x_mid) = std::minmax(x[1], x[2]);
331-
x_max = x[0];
332-
}
333-
}
334-
int y_max, y_min, y_mid;
335-
if (y[0] < y[1]) {
336-
if (y[0] < y[2]) {
337-
y_min = y[0];
338-
std::tie(y_mid, y_max) = std::minmax(y[1], y[2]);
339-
} else {
340-
y_min = y[2];
341-
y_mid = y[0];
342-
y_max = y[1];
343-
}
344-
} else {
345-
if (y[0] < y[2]) {
346-
y_min = y[1];
347-
y_mid = y[0];
348-
y_max = y[2];
349-
} else {
350-
std::tie(y_min, y_mid) = std::minmax(y[1], y[2]);
351-
y_max = y[0];
352-
}
353-
}
263+
auto sort = [](const std::vector<int>& v) {
264+
std::array<int, 3> tmp{v[0], v[1], v[2]};
265+
std::sort(tmp.begin(), tmp.end());
266+
return tmp;
267+
};
268+
auto [x_min, x_mid, x_max] = sort(x);
269+
auto [y_min, y_mid, y_max] = sort(y);
354270

355271
t.length = abs(x_max - x_min) + abs(y_max - y_min);
356272
t.branch.resize(4);
357-
t.branch[0].x = x[0];
358-
t.branch[0].y = y[0];
359-
t.branch[0].n = 3;
360-
t.branch[1].x = x[1];
361-
t.branch[1].y = y[1];
362-
t.branch[1].n = 3;
363-
t.branch[2].x = x[2];
364-
t.branch[2].y = y[2];
365-
t.branch[2].n = 3;
366-
t.branch[3].x = x_mid;
367-
t.branch[3].y = y_mid;
368-
t.branch[3].n = 3;
273+
t.branch[0] = {x[0], y[0], 3};
274+
t.branch[1] = {x[1], y[1], 3};
275+
t.branch[2] = {x[2], y[2], 3};
276+
t.branch[3] = {x_mid, y_mid, 3};
369277
} else {
370278
std::vector<int> xs(d);
371279
std::vector<int> ys(d);
@@ -478,105 +386,48 @@ bool FastRouteCore::netCongestion(const int netID)
478386

479387
bool FastRouteCore::VTreeSuite(const int netID)
480388
{
481-
int xmax = 0;
482-
int ymax = 0;
483-
int xmin = BIG_INT;
484-
int ymin = BIG_INT;
485-
486-
const int deg = nets_[netID]->getNumPins();
487-
for (int i = 0; i < deg; i++) {
488-
if (xmin > nets_[netID]->getPinX(i)) {
489-
xmin = nets_[netID]->getPinX(i);
490-
}
491-
if (xmax < nets_[netID]->getPinX(i)) {
492-
xmax = nets_[netID]->getPinX(i);
493-
}
494-
if (ymin > nets_[netID]->getPinY(i)) {
495-
ymin = nets_[netID]->getPinY(i);
496-
}
497-
if (ymax < nets_[netID]->getPinY(i)) {
498-
ymax = nets_[netID]->getPinY(i);
499-
}
500-
}
501-
502-
return (ymax - ymin) > 3 * (xmax - xmin);
389+
const odb::Rect bbox = nets_[netID]->getPinBBox();
390+
return bbox.dy() > 3 * bbox.dx();
503391
}
504392

505393
bool FastRouteCore::HTreeSuite(const int netID)
506394
{
507-
int xmax = 0;
508-
int ymax = 0;
509-
int xmin = BIG_INT;
510-
int ymin = BIG_INT;
511-
512-
const int deg = nets_[netID]->getNumPins();
513-
for (int i = 0; i < deg; i++) {
514-
if (xmin > nets_[netID]->getPinX(i)) {
515-
xmin = nets_[netID]->getPinX(i);
516-
}
517-
if (xmax < nets_[netID]->getPinX(i)) {
518-
xmax = nets_[netID]->getPinX(i);
519-
}
520-
if (ymin > nets_[netID]->getPinY(i)) {
521-
ymin = nets_[netID]->getPinY(i);
522-
}
523-
if (ymax < nets_[netID]->getPinY(i)) {
524-
ymax = nets_[netID]->getPinY(i);
525-
}
526-
}
527-
528-
return 5 * (ymax - ymin) < (xmax - xmin);
395+
const odb::Rect bbox = nets_[netID]->getPinBBox();
396+
return 5 * bbox.dy() < bbox.dx();
529397
}
530398

531399
float FastRouteCore::coeffADJ(const int netID)
532400
{
533-
const int deg = nets_[netID]->getNumPins();
534-
int xmax = 0;
535-
int ymax = 0;
536-
int xmin = BIG_INT;
537-
int ymin = BIG_INT;
538-
539-
for (int i = 0; i < deg; i++) {
540-
if (xmin > nets_[netID]->getPinX(i)) {
541-
xmin = nets_[netID]->getPinX(i);
542-
}
543-
if (xmax < nets_[netID]->getPinX(i)) {
544-
xmax = nets_[netID]->getPinX(i);
545-
}
546-
if (ymin > nets_[netID]->getPinY(i)) {
547-
ymin = nets_[netID]->getPinY(i);
548-
}
549-
if (ymax < nets_[netID]->getPinY(i)) {
550-
ymax = nets_[netID]->getPinY(i);
551-
}
552-
}
401+
const odb::Rect bbox = nets_[netID]->getPinBBox();
553402

554403
int Hcap = 0;
555404
int Vcap = 0;
556405
float Husage = 0;
557406
float Vusage = 0;
558407
float coef;
559-
if (xmin == xmax) {
560-
for (int j = ymin; j < ymax; j++) {
561-
Vcap += getEdgeCapacity(nets_[netID], xmin, j, EdgeDirection::Vertical);
562-
Vusage += graph2d_.getEstUsageV(xmin, j);
408+
if (bbox.dx() == 0) {
409+
for (int j = bbox.yMin(); j < bbox.yMax(); j++) {
410+
Vcap += getEdgeCapacity(
411+
nets_[netID], bbox.xMin(), j, EdgeDirection::Vertical);
412+
Vusage += graph2d_.getEstUsageV(bbox.xMin(), j);
563413
}
564414
coef = 1;
565-
} else if (ymin == ymax) {
566-
for (int i = xmin; i < xmax; i++) {
567-
Hcap += getEdgeCapacity(nets_[netID], i, ymin, EdgeDirection::Horizontal);
568-
Husage += graph2d_.getEstUsageH(i, ymin);
415+
} else if (bbox.dy() == 0) {
416+
for (int i = bbox.xMin(); i < bbox.xMax(); i++) {
417+
Hcap += getEdgeCapacity(
418+
nets_[netID], i, bbox.yMin(), EdgeDirection::Horizontal);
419+
Husage += graph2d_.getEstUsageH(i, bbox.yMin());
569420
}
570421
coef = 1;
571422
} else {
572-
for (int j = ymin; j <= ymax; j++) {
573-
for (int i = xmin; i < xmax; i++) {
423+
for (int j = bbox.yMin(); j <= bbox.yMax(); j++) {
424+
for (int i = bbox.xMin(); i < bbox.xMax(); i++) {
574425
Hcap += getEdgeCapacity(nets_[netID], i, j, EdgeDirection::Horizontal);
575426
Husage += graph2d_.getEstUsageH(i, j);
576427
}
577428
}
578-
for (int j = ymin; j < ymax; j++) {
579-
for (int i = xmin; i <= xmax; i++) {
429+
for (int j = bbox.yMin(); j < bbox.yMax(); j++) {
430+
for (int i = bbox.xMin(); i <= bbox.xMax(); i++) {
580431
Vcap += getEdgeCapacity(nets_[netID], i, j, EdgeDirection::Vertical);
581432
Vusage += graph2d_.getEstUsageV(i, j);
582433
}

src/grt/src/fastroute/src/RipUp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ bool FastRouteCore::newRipupCheck(const TreeEdge* treeedge,
191191
for (int i = 0; i < treeedge->route.routelen; i++) {
192192
if (grids[i].x == grids[i + 1].x) { // a vertical edge
193193
const int ymin = std::min(grids[i].y, grids[i + 1].y);
194-
if (graph2d_.getUsageRedV(grids[i].x, ymin)
195-
>= v_capacity_ - ripup_threshold) {
194+
if (graph2d_.getUsageRedV(grids[i].x, ymin) - v_capacity_
195+
< ripup_threshold) {
196196
needRipup = true;
197197
break;
198198
}
199199
} else if (grids[i].y == grids[i + 1].y) { // a horizontal edge
200200
const int xmin = std::min(grids[i].x, grids[i + 1].x);
201-
if (graph2d_.getUsageRedH(xmin, grids[i].y)
202-
>= h_capacity_ - ripup_threshold) {
201+
if (graph2d_.getUsageRedH(xmin, grids[i].y) - h_capacity_
202+
< ripup_threshold) {
203203
needRipup = true;
204204
break;
205205
}

0 commit comments

Comments
 (0)