Skip to content

Commit 8a5493f

Browse files
authored
Merge pull request #10578 from sparsh-karna/grt-cugr-delete-net-handling
grt: add incremental deleted-net cleanup for CUGR
2 parents 185a2c2 + 6fbeac3 commit 8a5493f

7 files changed

Lines changed: 182 additions & 89 deletions

File tree

src/grt/src/GlobalRouter.cpp

Lines changed: 81 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,10 +1594,9 @@ bool GlobalRouter::pinPositionsChanged(Net* net)
15941594
bool GlobalRouter::newPinOnGrid(Net* net, std::multiset<RoutePt>& last_pos)
15951595
{
15961596
for (const Pin& pin : net->getPins()) {
1597-
if (last_pos.find(RoutePt(pin.getOnGridPosition().getX(),
1598-
pin.getOnGridPosition().getY(),
1599-
pin.getConnectionLayer()))
1600-
== last_pos.end()) {
1597+
if (!last_pos.contains(RoutePt(pin.getOnGridPosition().getX(),
1598+
pin.getOnGridPosition().getY(),
1599+
pin.getConnectionLayer()))) {
16011600
return true;
16021601
}
16031602
}
@@ -2560,7 +2559,7 @@ void GlobalRouter::readGuides(const char* file_name)
25602559
continue;
25612560
}
25622561

2563-
if (db_net_map_.find(net) == db_net_map_.end()) {
2562+
if (!db_net_map_.contains(net)) {
25642563
logger_->warn(GRT,
25652564
250,
25662565
"Net {} has guides but is not routed by the global "
@@ -2783,7 +2782,7 @@ void GlobalRouter::addImplicitVias(GRoute& route)
27832782
// present but not metal3) signals a missing intermediate segment, a
27842783
// different problem we do not paper over here.
27852784
if (prev_layer != -1 && layer == prev_layer + 1
2786-
&& existing_vias.count({point.first, point.second, prev_layer})
2785+
&& existing_vias.contains({point.first, point.second, prev_layer})
27872786
== 0) {
27882787
bridges.emplace_back(point.first,
27892788
point.second,
@@ -2926,12 +2925,12 @@ void GlobalRouter::fillTileSizeMaps(
29262925
{
29272926
for (const auto& [net, guides] : net_guides) {
29282927
for (const auto& guide : guides) {
2929-
if (tile_size_x_map.find(guide.second.dx()) == tile_size_x_map.end()) {
2928+
if (!tile_size_x_map.contains(guide.second.dx())) {
29302929
tile_size_x_map[guide.second.dx()] = 1;
29312930
} else {
29322931
tile_size_x_map[guide.second.dx()]++;
29332932
}
2934-
if (tile_size_y_map.find(guide.second.dy()) == tile_size_y_map.end()) {
2933+
if (!tile_size_y_map.contains(guide.second.dy())) {
29352934
tile_size_y_map[guide.second.dy()] = 1;
29362935
} else {
29372936
tile_size_y_map[guide.second.dy()]++;
@@ -3503,8 +3502,7 @@ void GlobalRouter::connectPadPins(NetRouteMap& routes)
35033502
odb::dbNet* db_net = net_route.first;
35043503
GRoute& route = net_route.second;
35053504
Net* net = getNet(db_net);
3506-
if (pad_pins_connections_.find(db_net) != pad_pins_connections_.end()
3507-
&& net->getNumPins() > 1) {
3505+
if (pad_pins_connections_.contains(db_net) && net->getNumPins() > 1) {
35083506
for (GSegment& segment : pad_pins_connections_[db_net]) {
35093507
route.push_back(segment);
35103508
}
@@ -3690,7 +3688,7 @@ float GlobalRouter::estimatePathResistance(odb::dbObject* pin1,
36903688
logger_->error(GRT, 81, "Invalid pin type. Expected Iterm or Bterm.");
36913689
}
36923690

3693-
if (routes_.find(db_net) == routes_.end()) {
3691+
if (!routes_.contains(db_net)) {
36943692
logger_->error(
36953693
GRT, 82, "Didn't find a route for net {}", db_net->getName());
36963694
}
@@ -3762,7 +3760,7 @@ float GlobalRouter::estimatePathResistance(odb::dbObject* pin1,
37623760
}
37633761

37643762
for (const RoutePt& neighbor : adj[curr]) {
3765-
if (visited.find(neighbor) == visited.end()) {
3763+
if (!visited.contains(neighbor)) {
37663764
visited.insert(neighbor);
37673765
parent[neighbor] = curr;
37683766
q.push(neighbor);
@@ -3930,7 +3928,7 @@ float GlobalRouter::estimatePathResistance(odb::dbObject* pin1,
39303928
}
39313929

39323930
for (const RoutePt& neighbor : adj[curr]) {
3933-
if (visited.find(neighbor) == visited.end()) {
3931+
if (!visited.contains(neighbor)) {
39343932
visited.insert(neighbor);
39353933
parent[neighbor] = curr;
39363934
q.push(neighbor);
@@ -4324,7 +4322,7 @@ static void getViaDims(
43244322
prl_up = -1;
43254323
width_down = -1;
43264324
prl_down = -1;
4327-
if (default_vias.find(tech_layer) != default_vias.end()) {
4325+
if (default_vias.contains(tech_layer)) {
43284326
for (auto box : default_vias[tech_layer]->getBoxes()) {
43294327
if (box->getTechLayer() == tech_layer) {
43304328
width_up = std::min(box->getDX(), box->getDY());
@@ -4333,7 +4331,7 @@ static void getViaDims(
43334331
}
43344332
}
43354333
}
4336-
if (default_vias.find(bottom_layer) != default_vias.end()) {
4334+
if (default_vias.contains(bottom_layer)) {
43374335
for (auto box : default_vias[bottom_layer]->getBoxes()) {
43384336
if (box->getTechLayer() == tech_layer) {
43394337
width_down = std::min(box->getDX(), box->getDY());
@@ -4610,7 +4608,7 @@ Net* GlobalRouter::addNet(odb::dbNet* db_net)
46104608
if (!db_net->getSigType().isSupply() && !db_net->isSpecial()
46114609
&& db_net->getSWires().empty() && !db_net->isConnectedByAbutment()) {
46124610
Net* net = new Net(db_net, db_net->getWire() != nullptr);
4613-
if (db_net_map_.find(db_net) != db_net_map_.end()) {
4611+
if (db_net_map_.contains(db_net)) {
46144612
delete db_net_map_[db_net];
46154613
}
46164614
db_net_map_[db_net] = net;
@@ -4622,64 +4620,72 @@ Net* GlobalRouter::addNet(odb::dbNet* db_net)
46224620

46234621
void GlobalRouter::removeNet(odb::dbNet* db_net)
46244622
{
4625-
auto it = db_net_map_.find(db_net);
4626-
if (it == db_net_map_.end() || it->second == nullptr) {
4623+
if (db_net == nullptr) {
46274624
return;
46284625
}
4629-
Net* deleted_net = it->second;
4630-
4631-
if (deleted_net->isMergedNet()) {
4632-
Net* preserved_net = db_net_map_[deleted_net->getMergedNet()];
4633-
if (preserved_net->areSegmentsRestored()
4634-
&& deleted_net->areSegmentsRestored()) {
4635-
// Both preserved and deleted nets have segments restored from ODB. Do
4636-
// nothing to 3D resources, as the resources used by the deleted net were
4637-
// included in the preserved net.
4638-
// clearNetRoute releases sttrees usage (no-op for restored nets) but
4639-
// keeps db_net in db_net_id_map_; deleteNet then removes the stale entry
4640-
// so future nets at the same pointer address find no mapping.
4641-
fastroute_->clearNetRoute(db_net);
4642-
fastroute_->deleteNet(db_net);
4643-
} else if (preserved_net->areSegmentsRestored()) {
4644-
// If preserved net has segments restored from ODB, it won't have routing
4645-
// data inside FastRouteCore. Instead of merging the deleted net into
4646-
// preserved net, we just remove it from FastRouteCore and account for its
4647-
// resources manually with updateNetResources.
4648-
// clearNetRoute releases the tree usage but keeps db_net in
4649-
// db_net_id_map_, so updateNetResources can look up the correct
4650-
// edge_cost. deleteNet then removes the net from the map.
4651-
fastroute_->clearNetRoute(db_net);
4652-
updateNetResources(deleted_net, false);
4653-
fastroute_->deleteNet(db_net);
4654-
} else if (deleted_net->areSegmentsRestored()) {
4655-
// If deleted net has segments restored from ODB, we need to mark the
4656-
// preserved net as having segments restore to ensure proper handling of
4657-
// the capacities used by the deleted net.
4658-
// Remove usage from the preserved net.
4659-
fastroute_->clearNetRoute(preserved_net->getDbNet());
4660-
fastroute_->clearNetRoute(db_net);
4661-
// Remove usage from the deleted net.
4662-
updateNetResources(deleted_net, true);
4663-
fastroute_->deleteNet(db_net);
4664-
preserved_net->setAreSegmentsRestored(true);
4665-
// Include usage of the merged net.
4666-
updateNetResources(preserved_net, false);
4667-
} else {
4668-
fastroute_->mergeNet(db_net, preserved_net->getDbNet());
4669-
}
4626+
4627+
if (use_cugr_) {
4628+
cugr_->removeNet(db_net);
46704629
} else {
4671-
if (deleted_net->areSegmentsRestored()) {
4672-
fastroute_->clearNetRoute(db_net);
4673-
updateNetResources(deleted_net, true);
4674-
fastroute_->deleteNet(db_net);
4630+
auto it = db_net_map_.find(db_net);
4631+
if (it == db_net_map_.end() || it->second == nullptr) {
4632+
return;
4633+
}
4634+
Net* deleted_net = it->second;
4635+
4636+
if (deleted_net->isMergedNet()) {
4637+
Net* preserved_net = db_net_map_[deleted_net->getMergedNet()];
4638+
if (preserved_net->areSegmentsRestored()
4639+
&& deleted_net->areSegmentsRestored()) {
4640+
// Both preserved and deleted nets have segments restored from ODB. Do
4641+
// nothing to 3D resources, as the resources used by the deleted net
4642+
// were included in the preserved net. clearNetRoute releases sttrees
4643+
// usage (no-op for restored nets) but keeps db_net in db_net_id_map_;
4644+
// deleteNet then removes the stale entry so future nets at the same
4645+
// pointer address find no mapping.
4646+
fastroute_->clearNetRoute(db_net);
4647+
fastroute_->deleteNet(db_net);
4648+
} else if (preserved_net->areSegmentsRestored()) {
4649+
// If preserved net has segments restored from ODB, it won't have
4650+
// routing data inside FastRouteCore. Instead of merging the deleted net
4651+
// into preserved net, we just remove it from FastRouteCore and account
4652+
// for its resources manually with updateNetResources. clearNetRoute
4653+
// releases the tree usage but keeps db_net in db_net_id_map_, so
4654+
// updateNetResources can look up the correct edge_cost. deleteNet then
4655+
// removes the net from the map.
4656+
fastroute_->clearNetRoute(db_net);
4657+
updateNetResources(deleted_net, false);
4658+
fastroute_->deleteNet(db_net);
4659+
} else if (deleted_net->areSegmentsRestored()) {
4660+
// If deleted net has segments restored from ODB, we need to mark the
4661+
// preserved net as having segments restore to ensure proper handling of
4662+
// the capacities used by the deleted net.
4663+
// Remove usage from the preserved net.
4664+
fastroute_->clearNetRoute(preserved_net->getDbNet());
4665+
fastroute_->clearNetRoute(db_net);
4666+
// Remove usage from the deleted net.
4667+
updateNetResources(deleted_net, true);
4668+
fastroute_->deleteNet(db_net);
4669+
preserved_net->setAreSegmentsRestored(true);
4670+
// Include usage of the merged net.
4671+
updateNetResources(preserved_net, false);
4672+
} else {
4673+
fastroute_->mergeNet(db_net, preserved_net->getDbNet());
4674+
}
46754675
} else {
4676-
fastroute_->removeNet(db_net);
4676+
if (deleted_net->areSegmentsRestored()) {
4677+
fastroute_->clearNetRoute(db_net);
4678+
updateNetResources(deleted_net, true);
4679+
fastroute_->deleteNet(db_net);
4680+
} else {
4681+
fastroute_->removeNet(db_net);
4682+
}
46774683
}
4684+
delete deleted_net;
4685+
db_net_map_.erase(db_net);
4686+
dirty_nets_.erase(db_net);
4687+
routes_.erase(db_net);
46784688
}
4679-
delete deleted_net;
4680-
db_net_map_.erase(db_net);
4681-
dirty_nets_.erase(db_net);
4682-
routes_.erase(db_net);
46834689
}
46844690

46854691
void GlobalRouter::updateNetPins(Net* net)
@@ -5023,22 +5029,22 @@ bool GlobalRouter::layerIsBlocked(
50235029

50245030
// if layer is max or min, then all obs the nearest layer are added
50255031
if (layer == getMaxRoutingLayer()
5026-
&& macro_obs_per_layer.find(layer - 1) != macro_obs_per_layer.end()) {
5032+
&& macro_obs_per_layer.contains(layer - 1)) {
50275033
extended_obs = macro_obs_per_layer.at(layer - 1);
50285034
}
50295035
if (layer == getMinRoutingLayer()
5030-
&& macro_obs_per_layer.find(layer + 1) != macro_obs_per_layer.end()) {
5036+
&& macro_obs_per_layer.contains(layer + 1)) {
50315037
extended_obs = macro_obs_per_layer.at(layer + 1);
50325038
}
50335039

50345040
std::vector<odb::Rect> upper_obs;
50355041
std::vector<odb::Rect> lower_obs;
50365042

50375043
// Get Rect vector to layer + 1 and layer - 1
5038-
if (macro_obs_per_layer.find(layer + 1) != macro_obs_per_layer.end()) {
5044+
if (macro_obs_per_layer.contains(layer + 1)) {
50395045
upper_obs = macro_obs_per_layer.at(layer + 1);
50405046
}
5041-
if (macro_obs_per_layer.find(layer - 1) != macro_obs_per_layer.end()) {
5047+
if (macro_obs_per_layer.contains(layer - 1)) {
50425048
lower_obs = macro_obs_per_layer.at(layer - 1);
50435049
}
50445050

@@ -5940,7 +5946,7 @@ void GlobalRouter::reportNetWireLength(odb::dbNet* net,
59405946

59415947
block_ = db_->getChip()->getBlock();
59425948
if (global_route) {
5943-
if (routes_.find(net) == routes_.end()) {
5949+
if (!routes_.contains(net)) {
59445950
logger_->warn(
59455951
GRT, 241, "Net {} does not have global route.", net->getName());
59465952
return;
@@ -6315,8 +6321,7 @@ void GlobalRouter::getCongestionNets(odb::PtrSet<odb::dbNet>& congestion_nets)
63156321
odb::Point& position = itr.first;
63166322
bool& is_horizontal = itr.second;
63176323
// Find nets with horizontal wires on congestion areas
6318-
if (is_horizontal
6319-
&& h_nets_in_pos_.find(position) != h_nets_in_pos_.end()) {
6324+
if (is_horizontal && h_nets_in_pos_.contains(position)) {
63206325
for (odb::dbNet* db_net : h_nets_in_pos_.at(position)) {
63216326
// Avoid modifying supply nets
63226327
if (!db_net->getSigType().isSupply()) {
@@ -6325,8 +6330,7 @@ void GlobalRouter::getCongestionNets(odb::PtrSet<odb::dbNet>& congestion_nets)
63256330
}
63266331
}
63276332
// Find nets with vertical wires on congestion areas
6328-
if (!is_horizontal
6329-
&& v_nets_in_pos_.find(position) != v_nets_in_pos_.end()) {
6333+
if (!is_horizontal && v_nets_in_pos_.contains(position)) {
63306334
for (odb::dbNet* db_net : v_nets_in_pos_.at(position)) {
63316335
// Avoid modifying supply nets
63326336
if (!db_net->getSigType().isSupply()) {

src/grt/src/cugr/include/CUGR.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <memory>
66
#include <set>
77
#include <string>
8+
#include <unordered_map>
89
#include <utility>
910
#include <vector>
1011

@@ -98,6 +99,7 @@ class CUGR
9899
}
99100
void addDirtyNet(odb::dbNet* net);
100101
void updateNet(odb::dbNet* net);
102+
void removeNet(odb::dbNet* net);
101103
void routeIncremental();
102104

103105
const std::vector<int>& getOriginalResources() const;
@@ -208,7 +210,7 @@ class CUGR
208210
std::unique_ptr<GridGraph> grid_graph_;
209211
std::vector<int> net_indices_;
210212
std::vector<std::unique_ptr<GRNet>> gr_nets_;
211-
odb::PtrMap<odb::dbNet, GRNet*> db_net_map_;
213+
std::unordered_map<odb::dbNet*, GRNet*> db_net_map_;
212214

213215
odb::dbDatabase* db_;
214216
utl::Logger* logger_;

0 commit comments

Comments
 (0)