Skip to content

Commit bc7e193

Browse files
committed
grt: more readability in cugr
Signed-off-by: Matt Liberty <[email protected]>
1 parent 9f8fcfe commit bc7e193

File tree

5 files changed

+70
-71
lines changed

5 files changed

+70
-71
lines changed

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

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ void CUGR::updateOverflowNets(std::vector<int>& netIndices)
5858
netIndices.push_back(net->getIndex());
5959
}
6060
}
61-
logger_->report(
62-
"{} / {} gr_nets_ have overflows.", netIndices.size(), gr_nets_.size());
61+
const int num_nets = gr_nets_.size();
62+
logger_->report("{} / {} nets have overflow.", netIndices.size(), num_nets);
6363
}
6464

6565
void CUGR::patternRoute(std::vector<int>& netIndices)
@@ -195,46 +195,48 @@ NetRouteMap CUGR::getRoutes()
195195
odb::dbNet* db_net = net->getDbNet();
196196
GRoute& route = routes[db_net];
197197

198-
const int half_gcell_size = design_->getGridlineSize() / 2;
198+
const int half_gcell = design_->getGridlineSize() / 2;
199199

200200
auto& routing_tree = net->getRoutingTree();
201-
if (routing_tree) {
202-
GRTreeNode::preorder(
203-
routing_tree, [&](const std::shared_ptr<GRTreeNode>& node) {
204-
for (const auto& child : node->getChildren()) {
205-
if (node->getLayerIdx() == child->getLayerIdx()) {
206-
auto [min_x, max_x] = std::minmax({node->x(), child->x()});
207-
auto [min_y, max_y] = std::minmax({node->y(), child->y()});
208-
GSegment segment(
209-
grid_graph_->getGridline(0, min_x) + half_gcell_size,
210-
grid_graph_->getGridline(1, min_y) + half_gcell_size,
211-
node->getLayerIdx() + 1,
212-
grid_graph_->getGridline(0, max_x) + half_gcell_size,
213-
grid_graph_->getGridline(1, max_y) + half_gcell_size,
214-
child->getLayerIdx() + 1,
215-
false);
216-
route.push_back(segment);
217-
} else {
218-
const int bottom_layer
219-
= std::min(node->getLayerIdx(), child->getLayerIdx());
220-
const int top_layer
221-
= std::max(node->getLayerIdx(), child->getLayerIdx());
222-
for (int layer_idx = bottom_layer; layer_idx < top_layer;
223-
layer_idx++) {
224-
GSegment segment(
225-
grid_graph_->getGridline(0, node->x()) + half_gcell_size,
226-
grid_graph_->getGridline(1, node->y()) + half_gcell_size,
227-
layer_idx + 1,
228-
grid_graph_->getGridline(0, node->x()) + half_gcell_size,
229-
grid_graph_->getGridline(1, node->y()) + half_gcell_size,
230-
layer_idx + 2,
231-
true);
232-
route.push_back(segment);
233-
}
201+
if (!routing_tree) {
202+
continue;
203+
}
204+
GRTreeNode::preorder(
205+
routing_tree, [&](const std::shared_ptr<GRTreeNode>& node) {
206+
for (const auto& child : node->getChildren()) {
207+
if (node->getLayerIdx() == child->getLayerIdx()) {
208+
auto [min_x, max_x] = std::minmax({node->x(), child->x()});
209+
auto [min_y, max_y] = std::minmax({node->y(), child->y()});
210+
211+
// convert to dbu
212+
min_x = grid_graph_->getGridline(0, min_x) + half_gcell;
213+
min_y = grid_graph_->getGridline(1, min_y) + half_gcell;
214+
max_x = grid_graph_->getGridline(0, max_x) + half_gcell;
215+
max_y = grid_graph_->getGridline(1, max_y) + half_gcell;
216+
217+
route.emplace_back(min_x,
218+
min_y,
219+
node->getLayerIdx() + 1,
220+
max_x,
221+
max_y,
222+
child->getLayerIdx() + 1,
223+
false);
224+
} else {
225+
const auto [bottom_layer, top_layer]
226+
= std::minmax({node->getLayerIdx(), child->getLayerIdx()});
227+
for (int layer_idx = bottom_layer; layer_idx < top_layer;
228+
layer_idx++) {
229+
const int x
230+
= grid_graph_->getGridline(0, node->x()) + half_gcell;
231+
const int y
232+
= grid_graph_->getGridline(1, node->y()) + half_gcell;
233+
234+
route.emplace_back(
235+
x, y, layer_idx + 1, x, y, layer_idx + 2, true);
234236
}
235237
}
236-
});
237-
}
238+
}
239+
});
238240
}
239241

240242
return routes;
@@ -270,7 +272,7 @@ void CUGR::getGuides(const GRNet* net,
270272
std::max(node->x(), child->x()),
271273
std::max(node->y(), child->y())));
272274
} else {
273-
int maxLayerIndex
275+
const int maxLayerIndex
274276
= std::max(node->getLayerIdx(), child->getLayerIdx());
275277
for (int layerIdx
276278
= std::min(node->getLayerIdx(), child->getLayerIdx());
@@ -284,7 +286,7 @@ void CUGR::getGuides(const GRNet* net,
284286

285287
auto getSpareResource = [&](const GRPoint& point) {
286288
double resource = std::numeric_limits<double>::max();
287-
int direction = grid_graph_->getLayerDirection(point.getLayerIdx());
289+
const int direction = grid_graph_->getLayerDirection(point.getLayerIdx());
288290
if (point[direction] + 1 < grid_graph_->getSize(direction)) {
289291
resource = std::min(
290292
resource,
@@ -336,15 +338,16 @@ void CUGR::getGuides(const GRNet* net,
336338
for (const auto& child : node->getChildren()) {
337339
if (node->getLayerIdx() == child->getLayerIdx()) {
338340
double wire_patch_threshold = constants_.wire_patch_threshold;
339-
int direction = grid_graph_->getLayerDirection(node->getLayerIdx());
340-
int l = std::min((*node)[direction], (*child)[direction]);
341-
int h = std::max((*node)[direction], (*child)[direction]);
342-
int r = (*node)[1 - direction];
341+
const int direction
342+
= grid_graph_->getLayerDirection(node->getLayerIdx());
343+
const int l = std::min((*node)[direction], (*child)[direction]);
344+
const int h = std::max((*node)[direction], (*child)[direction]);
345+
const int r = (*node)[1 - direction];
343346
for (int c = l; c <= h; c++) {
344347
bool patched = false;
345-
GRPoint point = (direction == MetalLayer::H
346-
? GRPoint(node->getLayerIdx(), c, r)
347-
: GRPoint(node->getLayerIdx(), r, c));
348+
const GRPoint point = (direction == MetalLayer::H
349+
? GRPoint(node->getLayerIdx(), c, r)
350+
: GRPoint(node->getLayerIdx(), r, c));
348351
if (getSpareResource(point) < wire_patch_threshold) {
349352
for (int layerIndex = node->getLayerIdx() - 1;
350353
layerIndex <= node->getLayerIdx() + 1;
@@ -389,15 +392,15 @@ void CUGR::printStatistics() const
389392
net->getRoutingTree(), [&](const std::shared_ptr<GRTreeNode>& node) {
390393
for (const auto& child : node->getChildren()) {
391394
if (node->getLayerIdx() == child->getLayerIdx()) {
392-
int direction
395+
const int direction
393396
= grid_graph_->getLayerDirection(node->getLayerIdx());
394-
int l = std::min((*node)[direction], (*child)[direction]);
395-
int h = std::max((*node)[direction], (*child)[direction]);
396-
int r = (*node)[1 - direction];
397+
const int l = std::min((*node)[direction], (*child)[direction]);
398+
const int h = std::max((*node)[direction], (*child)[direction]);
399+
const int r = (*node)[1 - direction];
397400
for (int c = l; c < h; c++) {
398401
wireLength += grid_graph_->getEdgeLength(direction, c);
399-
int x = direction == MetalLayer::H ? c : r;
400-
int y = direction == MetalLayer::H ? r : c;
402+
const int x = direction == MetalLayer::H ? c : r;
403+
const int y = direction == MetalLayer::H ? r : c;
401404
wireUsage[node->getLayerIdx()][x][y] += 1;
402405
}
403406
} else {
@@ -415,17 +418,17 @@ void CUGR::printStatistics() const
415418
for (int layerIndex = constants_.min_routing_layer;
416419
layerIndex < grid_graph_->getNumLayers();
417420
layerIndex++) {
418-
int direction = grid_graph_->getLayerDirection(layerIndex);
421+
const int direction = grid_graph_->getLayerDirection(layerIndex);
419422
for (int x = 0; x < grid_graph_->getSize(0) - 1 + direction; x++) {
420423
for (int y = 0; y < grid_graph_->getSize(1) - direction; y++) {
421-
CapacityT resource
424+
const CapacityT resource
422425
= grid_graph_->getEdge(layerIndex, x, y).getResource();
423426
if (resource < minResource) {
424427
minResource = resource;
425428
bottleneck = {layerIndex, x, y};
426429
}
427-
CapacityT usage = wireUsage[layerIndex][x][y];
428-
CapacityT capacity
430+
const CapacityT usage = wireUsage[layerIndex][x][y];
431+
const CapacityT capacity
429432
= std::max(grid_graph_->getEdge(layerIndex, x, y).capacity, 0.0);
430433
if (usage > 0.0 && usage > capacity) {
431434
overflow += usage - capacity;

src/grt/src/cugr/src/Design.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void Design::readNetlist()
102102
}
103103
}
104104

105-
pins.emplace_back(pin_count, db_bterm, pin_shapes, true);
105+
pins.emplace_back(pin_count, db_bterm, pin_shapes);
106106
pin_count++;
107107
}
108108

@@ -125,7 +125,7 @@ void Design::readNetlist()
125125
}
126126
}
127127

128-
pins.emplace_back(pin_count, db_iterm, pin_shapes, false);
128+
pins.emplace_back(pin_count, db_iterm, pin_shapes);
129129
pin_count++;
130130
}
131131
nets_.emplace_back(net_index, db_net, pins);

src/grt/src/cugr/src/Netlist.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ namespace grt {
1313

1414
CUGRPin::CUGRPin(const int index,
1515
odb::dbITerm* iterm,
16-
const std::vector<BoxOnLayer>& pin_shapes,
17-
const bool is_port)
18-
: index_(index), iterm(iterm), pin_shapes_(pin_shapes), is_port_(is_port)
16+
const std::vector<BoxOnLayer>& pin_shapes)
17+
: iterm(iterm), pin_shapes_(pin_shapes), index_(index), is_port_(false)
1918
{
2019
}
2120

2221
CUGRPin::CUGRPin(const int index,
2322
odb::dbBTerm* bterm,
24-
const std::vector<BoxOnLayer>& pin_shapes,
25-
const bool is_port)
26-
: index_(index), bterm(bterm), pin_shapes_(pin_shapes), is_port_(is_port)
23+
const std::vector<BoxOnLayer>& pin_shapes)
24+
: bterm(bterm), pin_shapes_(pin_shapes), index_(index), is_port_(true)
2725
{
2826
}
2927

src/grt/src/cugr/src/Netlist.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ class CUGRPin
1616
public:
1717
CUGRPin(int index,
1818
odb::dbITerm* iterm,
19-
const std::vector<BoxOnLayer>& pin_shapes,
20-
bool is_port);
19+
const std::vector<BoxOnLayer>& pin_shapes);
2120
CUGRPin(int index,
2221
odb::dbBTerm* bterm,
23-
const std::vector<BoxOnLayer>& pin_shapes,
24-
bool is_port);
22+
const std::vector<BoxOnLayer>& pin_shapes);
2523

2624
int getIndex() const { return index_; }
2725
odb::dbITerm* getITerm() const;
@@ -31,13 +29,13 @@ class CUGRPin
3129
std::string getName() const;
3230

3331
private:
34-
const int index_;
3532
union
3633
{
3734
odb::dbITerm* iterm;
3835
odb::dbBTerm* bterm;
3936
};
4037
std::vector<BoxOnLayer> pin_shapes_;
38+
const int index_;
4139
const bool is_port_;
4240
};
4341

src/grt/test/clock_route_cugr.ok

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ num of nets : 15
2626
num of special nets: 0
2727
gcell grid: 38 x 38 x 6
2828
stage 1: pattern routing
29-
0 / 15 gr_nets_ have overflows.
29+
0 / 15 nets have overflow.
3030
routing statistics
3131
wire length (metric): 2918
3232
total via count: 169

0 commit comments

Comments
 (0)