Skip to content

Commit ef3454b

Browse files
committed
grt: change AccessPointMap to AccessPointSet
The (x,y) key is already part of the AccessPoint so no need to repeat it when a custom equal_to works. Signed-off-by: Matt Liberty <[email protected]>
1 parent 2192a08 commit ef3454b

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

src/grt/src/cugr/src/GridGraph.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ CostT GridGraph::getViaCost(const int layer_index, const PointT loc) const
352352
return cost;
353353
}
354354

355-
GridGraph::AccessPointMap GridGraph::selectAccessPoints(const GRNet* net) const
355+
AccessPointSet GridGraph::selectAccessPoints(const GRNet* net) const
356356
{
357-
PointHash hasher(y_size_);
358-
AccessPointMap selected_access_points(0, hasher);
357+
AccessPointHash hasher(y_size_);
358+
AccessPointSet selected_access_points(0, hasher);
359359
// cell hash (2d) -> access point, fixed layer interval
360360
selected_access_points.reserve(net->getNumPins());
361361
const auto& boundingBox = net->getBoundingBox();
@@ -393,11 +393,9 @@ GridGraph::AccessPointMap GridGraph::selectAccessPoints(const GRNet* net) const
393393
logger_->warn(utl::GRT, 274, "pin is hard to access.");
394394
}
395395
const PointT selectedPoint = accessPoints[bestIndex];
396-
const PointT key{selectedPoint.x(), selectedPoint.y()};
397-
if (selected_access_points.find(key) == selected_access_points.end()) {
398-
selected_access_points.emplace(key, AccessPoint{selectedPoint, {}});
399-
}
400-
IntervalT& fixedLayerInterval = selected_access_points[key].layers;
396+
const AccessPoint ap{selectedPoint, {}};
397+
auto it = selected_access_points.emplace(ap).first;
398+
IntervalT& fixedLayerInterval = it->layers;
401399
for (const auto& point : accessPoints) {
402400
if (point.x() == selectedPoint.x() && point.y() == selectedPoint.y()) {
403401
fixedLayerInterval.Update(point.getLayerIdx());
@@ -406,7 +404,7 @@ GridGraph::AccessPointMap GridGraph::selectAccessPoints(const GRNet* net) const
406404
}
407405
// Extend the fixed layers to 2 layers higher to facilitate track switching
408406
for (auto& accessPoint : selected_access_points) {
409-
IntervalT& fixedLayers = accessPoint.second.layers;
407+
IntervalT& fixedLayers = accessPoint.layers;
410408
fixedLayers.SetHigh(
411409
std::min(fixedLayers.high() + 2, (int) getNumLayers() - 1));
412410
}

src/grt/src/cugr/src/GridGraph.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,38 @@ class GRNet;
2121
template <typename Type>
2222
class GridGraphView;
2323

24-
class PointHash
24+
struct AccessPoint
25+
{
26+
PointT point;
27+
IntervalT layers;
28+
};
29+
30+
// Only hash and compare on the point, not the layers
31+
class AccessPointHash
2532
{
2633
public:
27-
PointHash(int y_size) : y_size_(y_size) {}
34+
AccessPointHash(int y_size) : y_size_(y_size) {}
2835

29-
std::size_t operator()(const PointT& pt) const
36+
std::size_t operator()(const AccessPoint& ap) const
3037
{
31-
return robin_hood::hash_int(pt.x() * y_size_ + pt.y());
38+
return robin_hood::hash_int(ap.point.x() * y_size_ + ap.point.y());
3239
}
3340

3441
private:
3542
const uint64_t y_size_;
3643
};
3744

45+
struct AccessPointEqual
46+
{
47+
bool operator()(const AccessPoint& lhs, const AccessPoint& rhs) const
48+
{
49+
return lhs.point == rhs.point;
50+
}
51+
};
52+
53+
using AccessPointSet
54+
= robin_hood::unordered_set<AccessPoint, AccessPointHash, AccessPointEqual>;
55+
3856
struct GraphEdge
3957
{
4058
CapacityT getResource() const { return capacity - demand; }
@@ -85,15 +103,7 @@ class GridGraph
85103
CostT getUnitViaCost() const { return unit_via_cost_; }
86104

87105
// Misc
88-
struct AccessPoint
89-
{
90-
PointT point;
91-
IntervalT layers;
92-
};
93-
94-
using AccessPointMap
95-
= robin_hood::unordered_map<PointT, AccessPoint, PointHash>;
96-
AccessPointMap selectAccessPoints(const GRNet* net) const;
106+
AccessPointSet selectAccessPoints(const GRNet* net) const;
97107

98108
// Methods for updating demands
99109
void commitTree(const std::shared_ptr<GRTreeNode>& tree, bool rip_up = false);

src/grt/src/cugr/src/MazeRoute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void SparseGraph::init(const GridGraphView<CostT>& wire_cost_view,
2626
const auto selectedAccessPoints = grid_graph_->selectAccessPoints(net_);
2727
pseudo_pins_.reserve(selectedAccessPoints.size());
2828
for (const auto& selectedPoint : selectedAccessPoints) {
29-
pseudo_pins_.push_back(selectedPoint.second);
29+
pseudo_pins_.push_back(selectedPoint);
3030
}
3131

3232
// 1. Collect additional routing grid lines

src/grt/src/cugr/src/MazeRoute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SparseGraph
4848
void init(const GridGraphView<CostT>& wire_cost_view, const SparseGrid& grid);
4949
int getNumVertices() const { return vertices_.size(); }
5050
int getNumPseudoPins() const { return pseudo_pins_.size(); }
51-
GridGraph::AccessPoint getPseudoPin(int pin_index) const
51+
AccessPoint getPseudoPin(int pin_index) const
5252
{
5353
return pseudo_pins_[pin_index];
5454
}
@@ -81,7 +81,7 @@ class SparseGraph
8181
GRNet* net_;
8282
const GridGraph* grid_graph_;
8383

84-
std::vector<GridGraph::AccessPoint> pseudo_pins_;
84+
std::vector<AccessPoint> pseudo_pins_;
8585

8686
std::vector<int> xs_;
8787
std::vector<int> ys_;

src/grt/src/cugr/src/PatternRoute.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ void PatternRoute::constructSteinerTree()
8484
const int degree = selectedAccessPoints.size();
8585
if (degree == 1) {
8686
const auto& accessPoint = *selectedAccessPoints.begin();
87-
steiner_tree_ = std::make_shared<SteinerTreeNode>(
88-
accessPoint.second.point, accessPoint.second.layers);
87+
steiner_tree_ = std::make_shared<SteinerTreeNode>(accessPoint.point,
88+
accessPoint.layers);
8989
return;
9090
}
9191

9292
std::vector<int> xs;
9393
std::vector<int> ys;
9494
for (auto& accessPoint : selectedAccessPoints) {
95-
xs.push_back(accessPoint.second.point.x());
96-
ys.push_back(accessPoint.second.point.y());
95+
xs.push_back(accessPoint.point.x());
96+
ys.push_back(accessPoint.point.y());
9797
}
9898

9999
stt::Tree flutetree = stt_builder_->flute(xs, ys, flute_accuracy_);
@@ -136,10 +136,10 @@ void PatternRoute::constructSteinerTree()
136136
constructTree(current, curIndex, nextIndex);
137137
}
138138
// Set fixed layer interval
139-
const PointT current_pt{current->x(), current->y()};
140-
if (selectedAccessPoints.find(current_pt)
141-
!= selectedAccessPoints.end()) {
142-
current->setFixedLayers(selectedAccessPoints[current_pt].layers);
139+
const AccessPoint current_pt{{current->x(), current->y()}, {}};
140+
if (auto it = selectedAccessPoints.find(current_pt);
141+
it != selectedAccessPoints.end()) {
142+
current->setFixedLayers(it->layers);
143143
}
144144
// Connect current to parent
145145
if (parent == nullptr) {

0 commit comments

Comments
 (0)