Skip to content

Commit d6e4e3c

Browse files
committed
grt: misc minor cugr cleanups
Signed-off-by: Matt Liberty <[email protected]>
1 parent 8309286 commit d6e4e3c

File tree

7 files changed

+70
-64
lines changed

7 files changed

+70
-64
lines changed

src/grt/src/cugr/src/Layers.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ MetalLayer::MetalLayer(odb::dbTechLayer* tech_layer,
1717
index_ = tech_layer->getRoutingLevel() - 1;
1818
direction_
1919
= tech_layer->getDirection() == odb::dbTechLayerDir::HORIZONTAL ? H : V;
20-
width_ = static_cast<int>(std::round(tech_layer->getWidth()));
21-
min_width_ = static_cast<int>(std::round(tech_layer->getMinWidth()));
20+
width_ = tech_layer->getWidth();
21+
min_width_ = tech_layer->getMinWidth();
2222

2323
track_grid->getAverageTrackSpacing(pitch_, first_track_loc_, num_tracks_);
2424
last_track_loc_ = first_track_loc_ + pitch_ * (num_tracks_ - 1);
2525

2626
// Design rules not parsed thoroughly
2727
// Min area
2828
const int database_unit = tech_layer->getTech()->getDbUnitsPerMicron();
29-
int min_area = static_cast<int>(
30-
std::round(tech_layer->getArea() * database_unit * database_unit));
29+
const int min_area = tech_layer->getArea() * database_unit * database_unit;
3130
min_length_ = std::max(min_area / width_ - width_, 0);
3231

3332
// Parallel run spacing
@@ -42,7 +41,7 @@ MetalLayer::MetalLayer(odb::dbTechLayer* tech_layer,
4241
if (num_length > 0) {
4342
parallel_length_.resize(num_length);
4443
for (int l = 0; l < num_length; l++) {
45-
parallel_length_[l] = static_cast<int>(std::round(lengths[l]));
44+
parallel_length_[l] = lengths[l];
4645
}
4746
}
4847

@@ -51,11 +50,10 @@ MetalLayer::MetalLayer(odb::dbTechLayer* tech_layer,
5150
parallel_width_.resize(num_width);
5251
parallel_spacing_.resize(num_width);
5352
for (int w = 0; w < num_width; w++) {
54-
parallel_width_[w] = static_cast<int>(std::round(widths[w]));
53+
parallel_width_[w] = widths[w];
5554
parallel_spacing_[w].resize(std::max(1, num_length), 0);
5655
for (int l = 0; l < num_length; l++) {
57-
parallel_spacing_[w][l]
58-
= static_cast<int>(std::round(spacing_table[w][l]));
56+
parallel_spacing_[w][l] = spacing_table[w][l];
5957
}
6058
}
6159
}
@@ -88,7 +86,7 @@ int MetalLayer::getTrackLocation(const int track_index) const
8886
}
8987

9088
IntervalT MetalLayer::rangeSearchTracks(const IntervalT& loc_range,
91-
bool include_bound) const
89+
const bool include_bound) const
9290
{
9391
IntervalT track_range(
9492
ceil(double(std::max(loc_range.low, first_track_loc_) - first_track_loc_)

src/grt/src/cugr/src/Layers.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ namespace grt {
1111
class MetalLayer
1212
{
1313
public:
14-
const static unsigned H = 0;
15-
const static unsigned V = 1;
14+
const static int H = 0;
15+
const static int V = 1;
16+
1617
MetalLayer(odb::dbTechLayer* tech_layer, odb::dbTrackGrid* track_grid);
18+
1719
std::string getName() const { return name_; }
18-
unsigned getDirection() const { return direction_; }
20+
int getDirection() const { return direction_; }
1921
int getWidth() const { return width_; }
2022
int getPitch() const { return pitch_; }
2123
int getTrackLocation(int track_index) const;
@@ -31,7 +33,7 @@ class MetalLayer
3133
private:
3234
std::string name_;
3335
int index_;
34-
unsigned direction_;
36+
int direction_;
3537
int width_;
3638
int min_width_;
3739

@@ -47,8 +49,8 @@ class MetalLayer
4749
// Parallel run spacing
4850
std::vector<int> parallel_width_ = {0};
4951
std::vector<int> parallel_length_ = {0};
50-
std::vector<std::vector<int>> parallel_spacing_
51-
= {{0}}; // width, length -> spacing
52+
// width, length -> spacing
53+
std::vector<std::vector<int>> parallel_spacing_ = {{0}};
5254
int default_spacing_ = 0;
5355

5456
// End-of-line spacing

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
namespace grt {
2121

22-
void SparseGraph::init(GridGraphView<CostT>& wire_cost_view, SparseGrid& grid)
22+
void SparseGraph::init(const GridGraphView<CostT>& wire_cost_view,
23+
const SparseGrid& grid)
2324
{
2425
// 0. Create pseudo pins
2526
robin_hood::unordered_map<uint64_t, std::pair<PointT, IntervalT>>
2627
selectedAccessPoints;
2728
grid_graph_->selectAccessPoints(net_, selectedAccessPoints);
2829
pseudo_pins_.reserve(selectedAccessPoints.size());
29-
for (auto& selectedPoint : selectedAccessPoints) {
30+
for (const auto& selectedPoint : selectedAccessPoints) {
3031
pseudo_pins_.push_back(selectedPoint.second);
3132
}
3233

@@ -46,9 +47,8 @@ void SparseGraph::init(GridGraphView<CostT>& wire_cost_view, SparseGrid& grid)
4647
const int ySize = grid_graph_->getSize(1);
4748
xs_.reserve(xSize / grid.interval.x() + pxs.size());
4849
ys_.reserve(ySize / grid.interval.y() + pys.size());
49-
int j = 0;
50-
for (int i = 0; true; i++) {
51-
int x = i * grid.interval.x() + grid.offset.x();
50+
for (int i = 0, j = 0; true; i++) {
51+
const int x = i * grid.interval.x() + grid.offset.x();
5252
for (; j < pxs.size() && pxs[j] <= x; j++) {
5353
if ((!xs_.empty() && pxs[j] == xs_.back()) || pxs[j] == x) {
5454
continue;
@@ -61,9 +61,8 @@ void SparseGraph::init(GridGraphView<CostT>& wire_cost_view, SparseGrid& grid)
6161
break;
6262
}
6363
}
64-
j = 0;
65-
for (int i = 0; true; i++) {
66-
int y = i * grid.interval.y() + grid.offset.y();
64+
for (int i = 0, j = 0; true; i++) {
65+
const int y = i * grid.interval.y() + grid.offset.y();
6766
for (; j < pys.size() && pys[j] <= y; j++) {
6867
if ((!ys_.empty() && pys[j] == ys_.back()) || pys[j] == y) {
6968
continue;
@@ -79,7 +78,7 @@ void SparseGraph::init(GridGraphView<CostT>& wire_cost_view, SparseGrid& grid)
7978

8079
// 2. Add vertices
8180
vertices_.reserve(2 * xs_.size() * ys_.size());
82-
for (unsigned direction = 0; direction < 2; direction++) {
81+
for (int direction = 0; direction < 2; direction++) {
8382
for (auto& y : ys_) {
8483
for (auto& x : xs_) {
8584
vertices_.emplace_back(direction, x, y);
@@ -94,15 +93,15 @@ void SparseGraph::init(GridGraphView<CostT>& wire_cost_view, SparseGrid& grid)
9493
= [&](const unsigned direction, const int xi, const int yi) {
9594
const int u = getVertexIndex(direction, xi, yi);
9695
const int v = direction == MetalLayer::H ? u + 1 : u + xs_.size();
97-
PointT U(xs_[xi], ys_[yi]);
98-
PointT V(xs_[xi + 1 - direction], ys_[yi + direction]);
96+
const PointT U(xs_[xi], ys_[yi]);
97+
const PointT V(xs_[xi + 1 - direction], ys_[yi + direction]);
9998

10099
edges_[u][0] = v;
101100
edges_[v][1] = u;
102101
costs_[u][0] = costs_[v][1] = wire_cost_view.sum(U, V);
103102
};
104103

105-
for (unsigned direction = 0; direction < 2; direction++) {
104+
for (int direction = 0; direction < 2; direction++) {
106105
if (direction == MetalLayer::H) {
107106
for (int yi = 0; yi < ys_.size(); yi++) {
108107
for (int xi = 0; xi + 1 < xs_.size(); xi++) {
@@ -207,12 +206,12 @@ void MazeRoute::run()
207206
continue;
208207
}
209208
for (int edgeIndex = 0; edgeIndex < 3; edgeIndex++) {
210-
int nextVertex = graph_.getNextVertex(solution->vertex, edgeIndex);
209+
const int nextVertex = graph_.getNextVertex(solution->vertex, edgeIndex);
211210
if (nextVertex == -1
212211
|| (solution->prev && nextVertex == solution->prev->vertex)) {
213212
continue;
214213
}
215-
CostT nextCost
214+
const CostT nextCost
216215
= solution->cost + graph_.getEdgeCost(solution->vertex, edgeIndex);
217216
if (nextCost < minCosts[nextVertex]) {
218217
updateSolution(
@@ -255,8 +254,8 @@ std::shared_ptr<SteinerTreeNode> MazeRoute::getSteinerTree() const
255254
while (temp) {
256255
auto it = created.find(temp->vertex);
257256
if (it == created.end()) {
258-
PointT point = graph_.getPoint(temp->vertex);
259-
auto node = std::make_shared<SteinerTreeNode>(point);
257+
const PointT point = graph_.getPoint(temp->vertex);
258+
const auto node = std::make_shared<SteinerTreeNode>(point);
260259
created.emplace(temp->vertex, node);
261260
if (lastNode) {
262261
node->addChild(lastNode);
@@ -266,7 +265,7 @@ std::shared_ptr<SteinerTreeNode> MazeRoute::getSteinerTree() const
266265
}
267266
if (!lastNode || !temp->prev) {
268267
// Both the start and the end of the path should contain pins
269-
int pinIndex = graph_.getVertexPin(temp->vertex);
268+
const int pinIndex = graph_.getVertexPin(temp->vertex);
270269
assert(pinIndex != -1);
271270
node->setFixedLayers(graph_.getPseudoPin(pinIndex).second);
272271
}
@@ -286,10 +285,10 @@ std::shared_ptr<SteinerTreeNode> MazeRoute::getSteinerTree() const
286285
tree, [&](const std::shared_ptr<SteinerTreeNode>& node) {
287286
for (int childIndex = 0; childIndex < node->getNumChildren();
288287
childIndex++) {
289-
std::shared_ptr<SteinerTreeNode> child
288+
const std::shared_ptr<SteinerTreeNode> child
290289
= node->getChildren()[childIndex];
291290
if (node->x() == child->x() && node->y() == child->y()) {
292-
for (auto& gradchild : child->getChildren()) {
291+
for (const auto& gradchild : child->getChildren()) {
293292
node->addChild(gradchild);
294293
}
295294
if (child->getFixedLayers().IsValid()) {
@@ -309,7 +308,7 @@ std::shared_ptr<SteinerTreeNode> MazeRoute::getSteinerTree() const
309308
SteinerTreeNode::preorder(
310309
tree, [&](const std::shared_ptr<SteinerTreeNode>& node) {
311310
for (std::shared_ptr<SteinerTreeNode>& child : node->getChildren()) {
312-
unsigned direction
311+
const int direction
313312
= (node->y() == child->y() ? MetalLayer::H : MetalLayer::V);
314313
std::shared_ptr<SteinerTreeNode> temp = child;
315314
while (!temp->getFixedLayers().IsValid()

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ namespace grt {
1717

1818
struct SparseGrid
1919
{
20-
PointT interval;
21-
PointT offset;
22-
2320
SparseGrid(int x_interval, int y_interval, int x_offset, int y_offset)
2421
: interval(x_interval, y_interval), offset(x_offset, y_offset)
2522
{
@@ -35,6 +32,9 @@ struct SparseGrid
3532
interval = {x_interval, y_interval};
3633
step();
3734
}
35+
36+
PointT interval;
37+
PointT offset;
3838
};
3939

4040
class SparseGraph
@@ -45,7 +45,7 @@ class SparseGraph
4545
{
4646
}
4747

48-
void init(GridGraphView<CostT>& wire_cost_view, SparseGrid& grid);
48+
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(); }
5151
std::pair<PointT, IntervalT> getPseudoPin(int pin_index) const
@@ -95,14 +95,14 @@ class SparseGraph
9595

9696
struct Solution
9797
{
98-
CostT cost;
99-
int vertex;
100-
std::shared_ptr<Solution> prev;
101-
10298
Solution(CostT c, int v, const std::shared_ptr<Solution>& p)
10399
: cost(c), vertex(v), prev(p)
104100
{
105101
}
102+
103+
const CostT cost;
104+
const int vertex;
105+
const std::shared_ptr<Solution> prev;
106106
};
107107

108108
class MazeRoute
@@ -114,15 +114,15 @@ class MazeRoute
114114
}
115115

116116
void run();
117-
void constructSparsifiedGraph(GridGraphView<CostT>& wire_cost_view,
118-
SparseGrid& grid)
117+
void constructSparsifiedGraph(const GridGraphView<CostT>& wire_cost_view,
118+
const SparseGrid& grid)
119119
{
120120
graph_.init(wire_cost_view, grid);
121121
}
122122
std::shared_ptr<SteinerTreeNode> getSteinerTree() const;
123123

124124
private:
125-
GRNet* net_;
125+
const GRNet* net_;
126126
const GridGraph* grid_graph_;
127127
SparseGraph graph_;
128128

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111

1212
namespace grt {
1313

14-
CUGRPin::CUGRPin(int index,
14+
CUGRPin::CUGRPin(const int index,
1515
odb::dbITerm* iterm,
1616
const std::vector<BoxOnLayer>& pin_shapes,
17-
bool is_port)
17+
const bool is_port)
1818
: index_(index), iterm(iterm), pin_shapes_(pin_shapes), is_port_(is_port)
1919
{
2020
}
2121

22-
CUGRPin::CUGRPin(int index,
22+
CUGRPin::CUGRPin(const int index,
2323
odb::dbBTerm* bterm,
2424
const std::vector<BoxOnLayer>& pin_shapes,
25-
bool is_port)
25+
const bool is_port)
2626
: index_(index), bterm(bterm), pin_shapes_(pin_shapes), is_port_(is_port)
2727
{
2828
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class CUGRPin
3131
std::string getName() const;
3232

3333
private:
34-
int index_;
34+
const int index_;
3535
union
3636
{
3737
odb::dbITerm* iterm;
3838
odb::dbBTerm* bterm;
3939
};
4040
std::vector<BoxOnLayer> pin_shapes_;
41-
bool is_port_;
41+
const bool is_port_;
4242
};
4343

4444
class CUGRNet
@@ -52,7 +52,7 @@ class CUGRNet
5252
std::string getName() const { return db_net_->getName(); }
5353

5454
private:
55-
int index_;
55+
const int index_;
5656
odb::dbNet* db_net_;
5757
std::vector<CUGRPin> pins_;
5858
};

src/grt/src/cugr/src/PatternRoute.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,12 @@ namespace grt {
1717
class SteinerTreeNode : public PointT
1818
{
1919
public:
20-
SteinerTreeNode(PointT point) : PointT(point) {}
21-
SteinerTreeNode(PointT point, IntervalT fixed_layers)
20+
SteinerTreeNode(const PointT& point) : PointT(point) {}
21+
SteinerTreeNode(const PointT& point, const IntervalT& fixed_layers)
2222
: PointT(point), fixed_layers_(fixed_layers)
2323
{
2424
}
2525

26-
static void preorder(
27-
const std::shared_ptr<SteinerTreeNode>& node,
28-
const std::function<void(std::shared_ptr<SteinerTreeNode>)>& visit);
29-
static std::string getPythonString(
30-
const std::shared_ptr<SteinerTreeNode>& node);
31-
3226
IntervalT& getFixedLayers() { return fixed_layers_; }
3327

3428
void setFixedLayers(const IntervalT& fixed_layers)
@@ -41,7 +35,10 @@ class SteinerTreeNode : public PointT
4135
children_.emplace_back(child);
4236
}
4337

44-
void removeChild(int index) { children_.erase(children_.begin() + index); }
38+
void removeChild(const int index)
39+
{
40+
children_.erase(children_.begin() + index);
41+
}
4542

4643
std::vector<std::shared_ptr<SteinerTreeNode>>& getChildren()
4744
{
@@ -50,6 +47,12 @@ class SteinerTreeNode : public PointT
5047

5148
int getNumChildren() const { return children_.size(); }
5249

50+
static void preorder(
51+
const std::shared_ptr<SteinerTreeNode>& node,
52+
const std::function<void(std::shared_ptr<SteinerTreeNode>)>& visit);
53+
static std::string getPythonString(
54+
const std::shared_ptr<SteinerTreeNode>& node);
55+
5356
private:
5457
IntervalT fixed_layers_;
5558
std::vector<std::shared_ptr<SteinerTreeNode>> children_;
@@ -58,11 +61,15 @@ class SteinerTreeNode : public PointT
5861
class PatternRoutingNode : public PointT
5962
{
6063
public:
61-
PatternRoutingNode(PointT point, int index, bool optional = false)
64+
PatternRoutingNode(const PointT& point,
65+
const int index,
66+
const bool optional = false)
6267
: PointT(point), index_(index), optional_(optional)
6368
{
6469
}
65-
PatternRoutingNode(PointT point, IntervalT fixed_layers, int index = 0)
70+
PatternRoutingNode(const PointT& point,
71+
const IntervalT& fixed_layers,
72+
const int index = 0)
6673
: PointT(point),
6774
index_(index),
6875
fixed_layers_(fixed_layers),

0 commit comments

Comments
 (0)