@@ -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
6565void 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;
0 commit comments