Skip to content

Commit e686405

Browse files
authored
Merge pull request #6841 from The-OpenROAD-Project-staging/rsz-graphics
rsz: add debug Graphics class and simple subdivide renderer
2 parents 4ed996b + b19258a commit e686405

File tree

10 files changed

+293
-5
lines changed

10 files changed

+293
-5
lines changed

src/rsz/include/rsz/Resizer.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class RecoverPower;
138138
class RepairDesign;
139139
class RepairSetup;
140140
class RepairHold;
141+
class ResizerObserver;
141142

142143
class SpefWriter;
143144

@@ -445,6 +446,7 @@ class Resizer : public dbStaState, public dbNetworkObserver
445446
std::optional<float> cellLeakage(LibertyCell* cell);
446447
// For debugging - calls getSwappableCells
447448
void reportEquivalentCells(LibertyCell* base_cell, bool match_cell_footprint);
449+
void setDebugGraphics(std::shared_ptr<ResizerObserver> graphics);
448450

449451
protected:
450452
void init();
@@ -828,6 +830,8 @@ class Resizer : public dbStaState, public dbNetworkObserver
828830
std::unordered_map<size_t, int>
829831
vt_hash_map_; // maps hash value to unique int
830832

833+
std::shared_ptr<ResizerObserver> graphics_;
834+
831835
friend class BufferedNet;
832836
friend class GateCloner;
833837
friend class PreChecks;

src/rsz/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ add_library(rsz_lib
5959

6060
target_sources(rsz
6161
PRIVATE
62+
Graphics.cc
6263
MakeResizer.cc
6364
SteinerRenderer.cc
6465
)
@@ -70,6 +71,7 @@ target_include_directories(rsz
7071
# A side-effect of including OpenSTA swig files
7172
${OPENSTA_HOME}
7273
${OPENSTA_HOME}/include/sta
74+
.
7375
)
7476

7577
target_include_directories(rsz_lib

src/rsz/src/Graphics.cc

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Precision Innovations Inc.
4+
// All rights reserved.
5+
//
6+
// BSD 3-Clause License
7+
//
8+
// Redistribution and use in source and binary forms, with or without
9+
// modification, are permitted provided that the following conditions are met:
10+
//
11+
// * Redistributions of source code must retain the above copyright notice, this
12+
// list of conditions and the following disclaimer.
13+
//
14+
// * Redistributions in binary form must reproduce the above copyright notice,
15+
// this list of conditions and the following disclaimer in the documentation
16+
// and/or other materials provided with the distribution.
17+
//
18+
// * Neither the name of the copyright holder nor the names of its
19+
// contributors may be used to endorse or promote products derived from
20+
// this software without specific prior written permission.
21+
//
22+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
// POSSIBILITY OF SUCH DAMAGE.
33+
//
34+
///////////////////////////////////////////////////////////////////////////////
35+
36+
#include "Graphics.hh"
37+
38+
namespace rsz {
39+
40+
Graphics::Graphics()
41+
{
42+
gui::Gui::get()->registerRenderer(this);
43+
}
44+
45+
void Graphics::setNet(odb::dbNet* net)
46+
{
47+
net_ = net;
48+
if (!net) {
49+
subdivide_ignore_ = false;
50+
}
51+
}
52+
53+
void Graphics::stopOnSubdivideStep(const bool stop)
54+
{
55+
stop_on_subdivide_step_ = stop;
56+
}
57+
58+
void Graphics::subdivideStart(odb::dbNet* net)
59+
{
60+
lines_.clear();
61+
if (net_) {
62+
subdivide_ignore_ = (net != net_);
63+
}
64+
}
65+
66+
void Graphics::subdivide(const odb::Line& line)
67+
{
68+
if (subdivide_ignore_) {
69+
return;
70+
}
71+
lines_.emplace_back(line);
72+
if (stop_on_subdivide_step_) {
73+
gui::Gui::get()->redraw();
74+
gui::Gui::get()->pause();
75+
}
76+
}
77+
78+
void Graphics::subdivideDone()
79+
{
80+
if (!subdivide_ignore_) {
81+
gui::Gui::get()->redraw();
82+
gui::Gui::get()->pause();
83+
}
84+
}
85+
86+
void Graphics::drawObjects(gui::Painter& painter)
87+
{
88+
painter.setPen(gui::Painter::red, true);
89+
for (const odb::Line& line : lines_) {
90+
painter.drawLine(line.pt0(), line.pt1());
91+
}
92+
}
93+
94+
} // namespace rsz

src/rsz/src/Graphics.hh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2025, Precision Innovations Inc.
4+
// All rights reserved.
5+
//
6+
// BSD 3-Clause License
7+
//
8+
// Redistribution and use in source and binary forms, with or without
9+
// modification, are permitted provided that the following conditions are met:
10+
//
11+
// * Redistributions of source code must retain the above copyright notice, this
12+
// list of conditions and the following disclaimer.
13+
//
14+
// * Redistributions in binary form must reproduce the above copyright notice,
15+
// this list of conditions and the following disclaimer in the documentation
16+
// and/or other materials provided with the distribution.
17+
//
18+
// * Neither the name of the copyright holder nor the names of its
19+
// contributors may be used to endorse or promote products derived from
20+
// this software without specific prior written permission.
21+
//
22+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
// POSSIBILITY OF SUCH DAMAGE.
33+
//
34+
///////////////////////////////////////////////////////////////////////////////
35+
36+
#pragma once
37+
38+
#include "ResizerObserver.hh"
39+
#include "gui/gui.h"
40+
41+
namespace rsz {
42+
43+
class Graphics : public gui::Renderer, public ResizerObserver
44+
{
45+
public:
46+
Graphics();
47+
48+
// ResizerObserver
49+
void setNet(odb::dbNet* net) override;
50+
void stopOnSubdivideStep(bool stop) override;
51+
void subdivideStart(odb::dbNet* net) override;
52+
void subdivide(const odb::Line& line) override;
53+
void subdivideDone() override;
54+
55+
// Renderer
56+
void drawObjects(gui::Painter& painter) override;
57+
58+
private:
59+
odb::dbNet* net_{nullptr};
60+
std::vector<odb::Line> lines_;
61+
// Ingore this net if true
62+
bool subdivide_ignore_{false};
63+
// stop at each step?
64+
bool stop_on_subdivide_step_{false};
65+
};
66+
67+
} // namespace rsz

src/rsz/src/RepairDesign.cc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <vector>
3939

4040
#include "BufferedNet.hh"
41+
#include "ResizerObserver.hh"
4142
#include "db_sta/dbNetwork.hh"
4243
#include "rsz/Resizer.hh"
4344
#include "sta/Corner.hh"
@@ -670,7 +671,7 @@ void RepairDesign::repairNet(Net* net,
670671
repaired_net = true;
671672

672673
debugPrint(logger_, RSZ, "repair_net", 3, "fanout violation");
673-
LoadRegion region = findLoadRegions(drvr_pin, max_fanout);
674+
LoadRegion region = findLoadRegions(net, drvr_pin, max_fanout);
674675
corner_ = corner;
675676
makeRegionRepeaters(region,
676677
max_fanout,
@@ -1480,12 +1481,21 @@ LoadRegion::LoadRegion(PinSeq& pins, Rect& bbox) : pins_(pins), bbox_(bbox)
14801481
{
14811482
}
14821483

1483-
LoadRegion RepairDesign::findLoadRegions(const Pin* drvr_pin, int max_fanout)
1484+
LoadRegion RepairDesign::findLoadRegions(const Net* net,
1485+
const Pin* drvr_pin,
1486+
int max_fanout)
14841487
{
14851488
PinSeq loads = findLoads(drvr_pin);
14861489
Rect bbox = findBbox(loads);
14871490
LoadRegion region(loads, bbox);
1491+
if (graphics_) {
1492+
odb::dbNet* db_net = db_network_->staToDb(net);
1493+
graphics_->subdivideStart(db_net);
1494+
}
14881495
subdivideRegion(region, max_fanout);
1496+
if (graphics_) {
1497+
graphics_->subdivideDone();
1498+
}
14891499
return region;
14901500
}
14911501

@@ -1498,17 +1508,20 @@ void RepairDesign::subdivideRegion(LoadRegion& region, int max_fanout)
14981508
int y_min = region.bbox_.yMin();
14991509
int y_max = region.bbox_.yMax();
15001510
region.regions_.resize(2);
1501-
int64_t x_mid = (x_min + x_max) / 2;
1502-
int64_t y_mid = (y_min + y_max) / 2;
1511+
int x_mid = (x_min + x_max) / 2;
1512+
int y_mid = (y_min + y_max) / 2;
15031513
bool horz_partition;
1514+
odb::Line cut;
15041515
if (region.bbox_.dx() > region.bbox_.dy()) {
15051516
region.regions_[0].bbox_ = Rect(x_min, y_min, x_mid, y_max);
15061517
region.regions_[1].bbox_ = Rect(x_mid, y_min, x_max, y_max);
1518+
cut = odb::Line{x_mid, y_min, x_mid, y_max};
15071519
horz_partition = true;
15081520
} else {
15091521
region.regions_[0].bbox_ = Rect(x_min, y_min, x_max, y_mid);
15101522
region.regions_[1].bbox_ = Rect(x_min, y_mid, x_max, y_max);
15111523
horz_partition = false;
1524+
cut = odb::Line{x_min, y_mid, x_max, y_mid};
15121525
}
15131526
for (const Pin* pin : region.pins_) {
15141527
Point loc = db_network_->location(pin);
@@ -1523,6 +1536,9 @@ void RepairDesign::subdivideRegion(LoadRegion& region, int max_fanout)
15231536
logger_->critical(RSZ, 83, "pin outside regions");
15241537
}
15251538
}
1539+
if (graphics_) {
1540+
graphics_->subdivide(cut);
1541+
}
15261542
region.pins_.clear();
15271543
for (LoadRegion& sub : region.regions_) {
15281544
if (!sub.pins_.empty()) {
@@ -2233,4 +2249,9 @@ void RepairDesign::reportViolationCounters(bool invalidate_driver_vertices,
22332249
}
22342250
}
22352251

2252+
void RepairDesign::setDebugGraphics(std::shared_ptr<ResizerObserver> graphics)
2253+
{
2254+
graphics_ = std::move(graphics);
2255+
}
2256+
22362257
} // namespace rsz

src/rsz/src/RepairDesign.hh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class RepairDesign : dbStaState
113113
int fanout_violations,
114114
int length_violations,
115115
int repaired_net_count);
116+
void setDebugGraphics(std::shared_ptr<ResizerObserver> graphics);
116117

117118
protected:
118119
void init();
@@ -198,7 +199,9 @@ class RepairDesign : dbStaState
198199
double load_cap,
199200
double slew,
200201
const DcalcAnalysisPt* dcalc_ap);
201-
LoadRegion findLoadRegions(const Pin* drvr_pin, int max_fanout);
202+
LoadRegion findLoadRegions(const Net* net,
203+
const Pin* drvr_pin,
204+
int max_fanout);
202205
void subdivideRegion(LoadRegion& region, int max_fanout);
203206
void makeRegionRepeaters(LoadRegion& region,
204207
int max_fanout,
@@ -280,6 +283,7 @@ class RepairDesign : dbStaState
280283
const MinMax* max_ = MinMax::max();
281284

282285
int print_interval_ = 0;
286+
std::shared_ptr<ResizerObserver> graphics_;
283287

284288
// Elmore factor for 20-80% slew thresholds.
285289
static constexpr float elmore_skew_factor_ = 1.39;

src/rsz/src/Resizer.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "RepairDesign.hh"
4848
#include "RepairHold.hh"
4949
#include "RepairSetup.hh"
50+
#include "ResizerObserver.hh"
5051
#include "boost/multi_array.hpp"
5152
#include "db_sta/dbNetwork.hh"
5253
#include "sta/ArcDelayCalc.hh"
@@ -4606,4 +4607,10 @@ void Resizer::copyDontUseFromLiberty()
46064607
}
46074608
}
46084609

4610+
void Resizer::setDebugGraphics(std::shared_ptr<ResizerObserver> graphics)
4611+
{
4612+
repair_design_->setDebugGraphics(graphics);
4613+
graphics_ = std::move(graphics);
4614+
}
4615+
46094616
} // namespace rsz

src/rsz/src/Resizer.i

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "rsz/Resizer.hh"
4545
#include "sta/Delay.hh"
4646
#include "db_sta/dbNetwork.hh"
47+
#include "Graphics.hh"
4748

4849
namespace ord {
4950
// Defined in OpenRoad.i
@@ -777,6 +778,23 @@ void report_equiv_cells_cmd(LibertyCell* cell, bool match_cell_footprint)
777778
resizer->reportEquivalentCells(cell, match_cell_footprint);
778779
}
779780

781+
void set_debug_cmd(const char* net_name,
782+
const bool subdivide_step)
783+
{
784+
Resizer* resizer = getResizer();
785+
786+
odb::dbNet* net = nullptr;
787+
if (net_name) {
788+
auto block = ord::OpenRoad::openRoad()->getDb()->getChip()->getBlock();
789+
net = block->findNet(net_name);
790+
}
791+
792+
auto graphics = std::make_shared<Graphics>();
793+
graphics->setNet(net);
794+
graphics->stopOnSubdivideStep(subdivide_step);
795+
resizer->setDebugGraphics(std::move(graphics));
796+
}
797+
780798
} // namespace
781799

782800
%} // inline

src/rsz/src/Resizer.tcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,21 @@ proc repair_setup_pin { end_pin } {
980980
repair_setup_pin_cmd $end_pin
981981
}
982982

983+
proc set_debug { args } {
984+
sta::parse_key_args "set_debug" args \
985+
keys { -net } \
986+
flags { -subdivide_step } ;# checker off
987+
988+
set net ""
989+
if { [info exists keys(-net)] } {
990+
set net $keys(-net)
991+
}
992+
993+
set subdivide_step [info exists flags(-subdivide_step)]
994+
995+
rsz::set_debug_cmd $net $subdivide_step
996+
}
997+
983998
proc report_swappable_pins { } {
984999
report_swappable_pins_cmd
9851000
}

0 commit comments

Comments
 (0)