Skip to content

Commit b9de175

Browse files
authored
Merge pull request #9102 from AcKoucher/mpl-graphics-refactor
mpl: some graphics refactoring
2 parents c9add04 + 06c9d45 commit b9de175

File tree

8 files changed

+50
-37
lines changed

8 files changed

+50
-37
lines changed

src/mpl/src/MplObserver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MplObserver
4444
const std::vector<odb::Rect>& placement_blockages)
4545
{
4646
}
47-
virtual void setBundledNets(const std::vector<BundledNet>& bundled_nets) {}
47+
virtual void setNets(const BundledNetList& nets) {}
4848
virtual void setShowBundledNets(bool show_bundled_nets) {}
4949
virtual void setShowClustersIds(bool show_clusters_ids) {}
5050
virtual void setSkipSteps(bool skip_steps) {}

src/mpl/src/SimulatedAnnealingCore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void SimulatedAnnealingCore<T>::initSequencePair()
118118

119119
// access functions
120120
template <class T>
121-
void SimulatedAnnealingCore<T>::setNets(const std::vector<BundledNet>& nets)
121+
void SimulatedAnnealingCore<T>::setNets(const BundledNetList& nets)
122122
{
123123
nets_ = nets;
124124
}
@@ -286,7 +286,7 @@ void SimulatedAnnealingCore<T>::calWirelength()
286286

287287
template <class T>
288288
float SimulatedAnnealingCore<T>::computeNetsWireLength(
289-
const std::vector<BundledNet>& nets) const
289+
const BundledNetList& nets) const
290290
{
291291
float nets_wire_length = 0.0;
292292
float nets_weight_sum = 0.0;

src/mpl/src/SimulatedAnnealingCore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class SimulatedAnnealingCore
6464
{
6565
number_of_sequence_pair_macros_ = number_of_sequence_pair_macros;
6666
};
67-
void setNets(const std::vector<BundledNet>& nets);
67+
void setNets(const BundledNetList& nets);
6868
void setFences(const std::map<int, odb::Rect>& fences);
6969
void setGuides(const std::map<int, odb::Rect>& guides);
7070
void setInitialSequencePair(const SequencePair& sequence_pair);
@@ -118,7 +118,7 @@ class SimulatedAnnealingCore
118118
virtual void calPenalty() = 0;
119119
void calOutlinePenalty();
120120
void calWirelength();
121-
float computeNetsWireLength(const std::vector<BundledNet>& nets) const;
121+
float computeNetsWireLength(const BundledNetList& nets) const;
122122
int64_t computeWLForClusterOfUnplacedIOPins(const T& macro,
123123
const T& unplaced_ios,
124124
float net_weight) const;
@@ -154,7 +154,7 @@ class SimulatedAnnealingCore
154154

155155
int number_of_sequence_pair_macros_ = 0;
156156

157-
std::vector<BundledNet> nets_;
157+
BundledNetList nets_;
158158
std::map<int, odb::Rect> fences_; // Macro Id -> Fence
159159
std::map<int, odb::Rect> guides_; // Macro Id -> Guide
160160

src/mpl/src/graphics.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,6 @@ void Graphics::drawObjects(gui::Painter& painter)
506506
}
507507

508508
if (show_bundled_nets_) {
509-
painter.setPen(gui::Painter::kYellow, true);
510-
511509
if (!hard_macros_.empty()) {
512510
drawBundledNets(painter, hard_macros_);
513511
}
@@ -580,21 +578,31 @@ template <typename T>
580578
void Graphics::drawBundledNets(gui::Painter& painter,
581579
const std::vector<T>& macros)
582580
{
583-
for (const auto& bundled_net : bundled_nets_) {
584-
const T& source = macros[bundled_net.terminals.first];
585-
const T& target = macros[bundled_net.terminals.second];
581+
painter.setPen(gui::Painter::kYellow, true);
586582

587-
if (target.isClusterOfUnplacedIOPins()) {
588-
drawDistToRegion(painter, source, target);
589-
continue;
590-
}
583+
for (const auto& net : nets_) {
584+
drawBundledNet(painter, macros, net);
585+
}
586+
}
591587

592-
odb::Point from(source.getPinX(), source.getPinY());
593-
odb::Point to(target.getPinX(), target.getPinY());
588+
template <typename T>
589+
void Graphics::drawBundledNet(gui::Painter& painter,
590+
const std::vector<T>& macros,
591+
const BundledNet& net)
592+
{
593+
const T& source = macros[net.terminals.first];
594+
const T& target = macros[net.terminals.second];
594595

595-
addOutlineOffsetToLine(from, to);
596-
painter.drawLine(from, to);
596+
if (target.isClusterOfUnplacedIOPins()) {
597+
drawDistToRegion(painter, source, target);
598+
return;
597599
}
600+
601+
odb::Point from(source.getPinX(), source.getPinY());
602+
odb::Point to(target.getPinX(), target.getPinY());
603+
604+
addOutlineOffsetToLine(from, to);
605+
painter.drawLine(from, to);
598606
}
599607

600608
template <typename T>
@@ -700,9 +708,9 @@ void Graphics::setOnlyFinalResult(bool only_final_result)
700708
only_final_result_ = only_final_result;
701709
}
702710

703-
void Graphics::setBundledNets(const std::vector<BundledNet>& bundled_nets)
711+
void Graphics::setNets(const BundledNetList& nets)
704712
{
705-
bundled_nets_ = bundled_nets;
713+
nets_ = nets;
706714
}
707715

708716
void Graphics::setTargetClusterId(const int target_cluster_id)
@@ -757,7 +765,7 @@ void Graphics::eraseDrawing()
757765
hard_macros_.clear();
758766
macro_blockages_.clear();
759767
placement_blockages_.clear();
760-
bundled_nets_.clear();
768+
nets_.clear();
761769
outline_.reset(0, 0, 0, 0);
762770
outlines_.clear();
763771
blocked_regions_for_pins_.clear();

src/mpl/src/graphics.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Graphics : public gui::Renderer, public MplObserver
5757
const std::vector<odb::Rect>& macro_blockages) override;
5858
void setPlacementBlockages(
5959
const std::vector<odb::Rect>& placement_blockages) override;
60-
void setBundledNets(const std::vector<BundledNet>& bundled_nets) override;
60+
void setNets(const BundledNetList& nets) override;
6161
void setShowBundledNets(bool show_bundled_nets) override;
6262
void setShowClustersIds(bool show_clusters_ids) override;
6363
void setSkipSteps(bool skip_steps) override;
@@ -91,6 +91,10 @@ class Graphics : public gui::Renderer, public MplObserver
9191
template <typename T>
9292
void drawBundledNets(gui::Painter& painter, const std::vector<T>& macros);
9393
template <typename T>
94+
void drawBundledNet(gui::Painter& painter,
95+
const std::vector<T>& macros,
96+
const BundledNet& net);
97+
template <typename T>
9498
void drawDistToRegion(gui::Painter& painter, const T& macro, const T& io);
9599
template <typename T>
96100
bool isOutsideTheOutline(const T& macro) const;
@@ -113,7 +117,7 @@ class Graphics : public gui::Renderer, public MplObserver
113117
std::vector<HardMacro> hard_macros_;
114118
std::vector<odb::Rect> macro_blockages_;
115119
std::vector<odb::Rect> placement_blockages_;
116-
std::vector<BundledNet> bundled_nets_;
120+
BundledNetList nets_;
117121
odb::Rect outline_;
118122
int target_cluster_id_{-1};
119123
std::vector<std::vector<odb::Rect>> outlines_;

src/mpl/src/hier_rtlmp.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ void HierRTLMP::setPlacementBlockages()
12681268
}
12691269

12701270
// Merge nets to reduce runtime
1271-
void HierRTLMP::mergeNets(std::vector<BundledNet>& nets)
1271+
void HierRTLMP::mergeNets(BundledNetList& nets)
12721272
{
12731273
std::vector<int> net_class(nets.size(), -1);
12741274
for (int i = 0; i < nets.size(); i++) {
@@ -1287,18 +1287,14 @@ void HierRTLMP::mergeNets(std::vector<BundledNet>& nets)
12871287
}
12881288
}
12891289

1290-
std::vector<BundledNet> merged_nets;
1290+
BundledNetList merged_nets;
12911291
for (int i = 0; i < net_class.size(); i++) {
12921292
if (net_class[i] == -1) {
12931293
merged_nets.push_back(nets[i]);
12941294
}
12951295
}
1296-
nets.clear();
1297-
nets = std::move(merged_nets);
12981296

1299-
if (graphics_) {
1300-
graphics_->setBundledNets(nets);
1301-
}
1297+
nets = std::move(merged_nets);
13021298
}
13031299

13041300
void HierRTLMP::considerFixedMacro(const odb::Rect& outline,
@@ -1477,6 +1473,10 @@ void HierRTLMP::placeChildren(Cluster* parent, bool ignore_std_cell_area)
14771473
BundledNetList nets = buildBundledNets(parent, soft_macro_id_map);
14781474
mergeNets(nets);
14791475

1476+
if (graphics_) {
1477+
graphics_->setNets(nets);
1478+
}
1479+
14801480
std::string file_name_prefix
14811481
= report_directory_ + "/"
14821482
+ std::regex_replace(
@@ -2085,7 +2085,7 @@ void HierRTLMP::placeMacros(Cluster* cluster)
20852085
BundledNetList nets = buildBundledNets(macro_clusters, cluster_to_macro);
20862086

20872087
if (graphics_) {
2088-
graphics_->setBundledNets(nets);
2088+
graphics_->setNets(nets);
20892089
}
20902090

20912091
// Use exchange more often when there are more instances of a common
@@ -2380,7 +2380,7 @@ BundledNetList HierRTLMP::buildBundledNets(
23802380
const UniqueClusterVector& clusters,
23812381
const ClusterToMacroMap& cluster_to_macro) const
23822382
{
2383-
std::vector<BundledNet> nets;
2383+
BundledNetList nets;
23842384

23852385
for (const auto& cluster : clusters) {
23862386
const int source_macro_id = cluster_to_macro.at(cluster->getId());
@@ -2821,7 +2821,7 @@ void HierRTLMP::printPlacementResult(Cluster* parent,
28212821

28222822
void HierRTLMP::writeNetFile(const std::string& file_name_prefix,
28232823
std::vector<SoftMacro>& macros,
2824-
std::vector<BundledNet>& nets)
2824+
BundledNetList& nets)
28252825
{
28262826
std::ofstream file(file_name_prefix + ".net.txt");
28272827
for (auto& net : nets) {

src/mpl/src/hier_rtlmp.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class SACoreHardMacro;
4343
using BoundaryToRegionsMap = std::map<Boundary, std::queue<odb::Rect>>;
4444
using SoftMacroNameToIdMap = std::map<std::string, int>;
4545
using ClusterToMacroMap = std::map<int, int>; // cluster_id -> macro_id
46-
using BundledNetList = std::vector<BundledNet>;
4746

4847
// The parameters necessary to compute one coordinate of the new
4948
// origin for aligning the macros' pins to the track-grid
@@ -195,7 +194,7 @@ class HierRTLMP
195194
void updateChildrenRealLocation(Cluster* parent,
196195
float offset_x,
197196
float offset_y);
198-
void mergeNets(std::vector<BundledNet>& nets);
197+
void mergeNets(BundledNetList& nets);
199198
void considerFixedMacro(const odb::Rect& outline,
200199
std::vector<SoftMacro>& sa_macros,
201200
Cluster* fixed_macro_cluster) const;
@@ -248,7 +247,7 @@ class HierRTLMP
248247
SACore* sa_core);
249248
void writeNetFile(const std::string& file_name_prefix,
250249
std::vector<SoftMacro>& macros,
251-
std::vector<BundledNet>& nets);
250+
BundledNetList& nets);
252251
void writeFloorplanFile(const std::string& file_name_prefix,
253252
std::vector<SoftMacro>& macros);
254253
template <typename SACore>

src/mpl/src/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Logger;
3333
}
3434

3535
namespace mpl {
36+
struct BundledNet;
3637
class HardMacro;
3738
class SoftMacro;
3839
class Cluster;
@@ -42,6 +43,7 @@ using IntervalList = std::vector<Interval>;
4243
using TilingList = std::vector<Tiling>;
4344
using TilingSet = std::set<Tiling>;
4445
using UniqueClusterVector = std::vector<std::unique_ptr<Cluster>>;
46+
using BundledNetList = std::vector<BundledNet>;
4547

4648
// ****************************************************************************
4749
// This file includes the basic functions and basic classes for the HierRTLMP

0 commit comments

Comments
 (0)