Skip to content

Commit 953f4d7

Browse files
committed
pdn: make addShape use unique_ptr
Signed-off-by: Peter Gadfort <[email protected]>
1 parent 0cdaba9 commit 953f4d7

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

src/pdn/src/grid_component.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ std::string GridComponent::typeToString(Type type)
6161
return "Unknown";
6262
}
6363

64-
ShapePtr GridComponent::addShape(Shape* shape)
64+
ShapePtr GridComponent::addShape(std::unique_ptr<Shape> shape)
6565
{
6666
debugPrint(getLogger(),
6767
utl::PDN,
6868
"Shape",
6969
3,
7070
"Adding shape {}.",
7171
shape->getReportText());
72-
auto shape_ptr = std::shared_ptr<Shape>(shape);
73-
if (!shape_ptr->isValid()) {
72+
if (!shape->isValid()) {
7473
// do not add invalid shapes
7574
return nullptr;
7675
}
7776

77+
auto shape_ptr = std::shared_ptr<Shape>(shape.release());
7878
shape_ptr->setGridComponent(this);
7979
const odb::Rect& shape_rect = shape_ptr->getRect();
8080

@@ -209,7 +209,7 @@ void GridComponent::replaceShape(
209209
removeShape(shape);
210210

211211
for (auto& new_shape : replacements) {
212-
const auto& new_shape_ptr = addShape(new_shape.release());
212+
const auto& new_shape_ptr = addShape(std::move(new_shape));
213213

214214
if (new_shape_ptr == nullptr) {
215215
continue;

src/pdn/src/grid_component.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class GridComponent
102102
int width,
103103
int spacing,
104104
const odb::dbTechLayerDir& direction) const;
105-
ShapePtr addShape(Shape* shape);
105+
ShapePtr addShape(std::unique_ptr<Shape> shape);
106106

107107
virtual bool areIntersectionsAllowed() const { return false; }
108108

src/pdn/src/rings.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,11 @@ void Rings::makeShapes(const Shape::ShapeTreeMap& other_shapes)
249249
int y_start = core.yMin() - width;
250250
int y_end = core.yMin();
251251
for (auto net : nets) {
252-
addShape(new Shape(layer,
253-
net,
254-
odb::Rect(x_start, y_start, x_end, y_end),
255-
odb::dbWireShapeType::RING));
252+
addShape(
253+
std::make_unique<Shape>(layer,
254+
net,
255+
odb::Rect(x_start, y_start, x_end, y_end),
256+
odb::dbWireShapeType::RING));
256257
if (!extend_to_boundary_) {
257258
x_start -= other_pitch;
258259
x_end += other_pitch;
@@ -268,10 +269,11 @@ void Rings::makeShapes(const Shape::ShapeTreeMap& other_shapes)
268269
y_start = core.yMax();
269270
y_end = y_start + width;
270271
for (auto net : nets) {
271-
addShape(new Shape(layer,
272-
net,
273-
odb::Rect(x_start, y_start, x_end, y_end),
274-
odb::dbWireShapeType::RING));
272+
addShape(
273+
std::make_unique<Shape>(layer,
274+
net,
275+
odb::Rect(x_start, y_start, x_end, y_end),
276+
odb::dbWireShapeType::RING));
275277
if (!extend_to_boundary_) {
276278
x_start -= other_pitch;
277279
x_end += other_pitch;
@@ -290,10 +292,11 @@ void Rings::makeShapes(const Shape::ShapeTreeMap& other_shapes)
290292
y_end = boundary.yMax();
291293
}
292294
for (auto net : nets) {
293-
addShape(new Shape(layer,
294-
net,
295-
odb::Rect(x_start, y_start, x_end, y_end),
296-
odb::dbWireShapeType::RING));
295+
addShape(
296+
std::make_unique<Shape>(layer,
297+
net,
298+
odb::Rect(x_start, y_start, x_end, y_end),
299+
odb::dbWireShapeType::RING));
297300
x_start -= pitch;
298301
x_end -= pitch;
299302
if (!extend_to_boundary_) {
@@ -309,10 +312,11 @@ void Rings::makeShapes(const Shape::ShapeTreeMap& other_shapes)
309312
y_end = core.yMax() + other_width;
310313
}
311314
for (auto net : nets) {
312-
addShape(new Shape(layer,
313-
net,
314-
odb::Rect(x_start, y_start, x_end, y_end),
315-
odb::dbWireShapeType::RING));
315+
addShape(
316+
std::make_unique<Shape>(layer,
317+
net,
318+
odb::Rect(x_start, y_start, x_end, y_end),
319+
odb::dbWireShapeType::RING));
316320
x_start += pitch;
317321
x_end += pitch;
318322
if (!extend_to_boundary_) {

src/pdn/src/straps.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ void Straps::makeStraps(int x_start,
337337
}
338338
}
339339

340-
addShape(
341-
new Shape(layer_, net, strap_rect, odb::dbWireShapeType::STRIPE));
340+
addShape(std::make_unique<Shape>(
341+
layer_, net, strap_rect, odb::dbWireShapeType::STRIPE));
342342
}
343343
strap_count++;
344344
if (number_of_straps_ != 0 && strap_count == number_of_straps_) {
@@ -462,15 +462,15 @@ void FollowPins::makeShapes(const Shape::ShapeTreeMap& other_shapes)
462462
const int ground_y_bot
463463
= (power_on_top ? bbox.yMin() : bbox.yMax()) - width / 2;
464464

465-
auto* power_strap = new FollowPinShape(
465+
auto power_strap = std::make_unique<FollowPinShape>(
466466
layer, power, odb::Rect(x0, power_y_bot, x1, power_y_bot + width));
467467
power_strap->addRow(row);
468-
addShape(power_strap);
468+
addShape(std::move(power_strap));
469469

470-
auto* ground_strap = new FollowPinShape(
470+
auto ground_strap = std::make_unique<FollowPinShape>(
471471
layer, ground, odb::Rect(x0, ground_y_bot, x1, ground_y_bot + width));
472472
ground_strap->addRow(row);
473-
addShape(ground_strap);
473+
addShape(std::move(ground_strap));
474474
}
475475
}
476476

@@ -1072,14 +1072,17 @@ void PadDirectConnectionStraps::makeShapesFacingCore(
10721072
}
10731073
}
10741074

1075-
auto* shape
1076-
= new Shape(layer, net, shape_rect, odb::dbWireShapeType::STRIPE);
1075+
auto shape = std::make_unique<Shape>(
1076+
layer, net, shape_rect, odb::dbWireShapeType::STRIPE);
10771077
// use intersection of pin_rect to ensure max width limitation is
10781078
// preserved
10791079
shape->addITermConnection(pin_rect.intersect(shape_rect));
1080-
addShape(shape);
1080+
const auto added = addShape(std::move(shape));
1081+
if (added == nullptr) {
1082+
continue;
1083+
}
10811084

1082-
target_shapes_[shape] = closest_shape.get();
1085+
target_shapes_[added.get()] = closest_shape.get();
10831086
}
10841087
}
10851088
}
@@ -1210,15 +1213,19 @@ void PadDirectConnectionStraps::makeShapesOverPads(
12101213
return;
12111214
}
12121215

1213-
auto* shape = new Shape(
1216+
auto shape = std::make_unique<Shape>(
12141217
getLayer(), iterm_->getNet(), shape_rect, odb::dbWireShapeType::STRIPE);
12151218

12161219
if (getDirection() != getLayer()->getDirection()) {
12171220
shape->setAllowsNonPreferredDirectionChange();
12181221
}
1219-
addShape(shape);
1220-
target_shapes_[shape] = closest_shape.get();
1221-
target_pin_shape_[shape] = org_pin_shape;
1222+
const auto added = addShape(std::move(shape));
1223+
if (added == nullptr) {
1224+
return;
1225+
}
1226+
1227+
target_shapes_[added.get()] = closest_shape.get();
1228+
target_pin_shape_[added.get()] = org_pin_shape;
12221229
}
12231230

12241231
bool PadDirectConnectionStraps::snapRectToClosestShape(
@@ -1495,7 +1502,7 @@ bool PadDirectConnectionStraps::refineShape(
14951502
new_rect.set_xhi(check_loc + getWidth());
14961503
}
14971504

1498-
std::unique_ptr<Shape> new_shape(shape->copy());
1505+
std::unique_ptr<Shape> new_shape = shape->copy();
14991506
new_shape->setRect(new_rect);
15001507

15011508
debugPrint(
@@ -1513,7 +1520,7 @@ bool PadDirectConnectionStraps::refineShape(
15131520
new_shape.get(), all_shapes, all_obstructions, true)) {
15141521
continue;
15151522
}
1516-
const ShapePtr& added_shape = addShape(new_shape.release());
1523+
const ShapePtr& added_shape = addShape(std::move(new_shape));
15171524
if (added_shape != nullptr) {
15181525
added_shape->clearITermConnections();
15191526
added_shape->addITermConnection(

0 commit comments

Comments
 (0)