Skip to content

Commit ab54954

Browse files
committed
mpl: update connections after merging clusters
Signed-off-by: Arthur Koucher <[email protected]>
1 parent 4f65393 commit ab54954

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

src/mpl/src/clusterEngine.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,14 +1849,21 @@ void ClusteringEngine::mergeChildrenBelowThresholds(
18491849

18501850
bool ClusteringEngine::attemptMerge(Cluster* receiver, Cluster* incomer)
18511851
{
1852-
// The incomer might be deleted so we need to cache
1853-
// its id in order to erase it from the map if so.
1852+
// Cache incomer data in case it is deleted.
18541853
const int incomer_id = incomer->getId();
1854+
const ConnectionsMap incomer_connections = incomer->getConnectionsMap();
18551855

18561856
bool incomer_deleted = false;
18571857
if (receiver->attemptMerge(incomer, incomer_deleted)) {
18581858
if (incomer_deleted) {
18591859
tree_->maps.id_to_cluster.erase(incomer_id);
1860+
1861+
// Update connections of clusters connected to the deleted cluster.
1862+
for (const auto& [cluster_id, connection_weight] : incomer_connections) {
1863+
Cluster* cluster = tree_->maps.id_to_cluster.at(cluster_id);
1864+
cluster->removeConnection(incomer_id);
1865+
cluster->addConnection(receiver->getId(), connection_weight);
1866+
}
18601867
}
18611868

18621869
updateInstancesAssociation(receiver);
@@ -2194,7 +2201,7 @@ void ClusteringEngine::classifyMacrosByConnSignature(
21942201
logger_->report("\nPrint Connection Signature\n");
21952202
for (Cluster* cluster : macro_clusters) {
21962203
logger_->report("Macro Signature: {}", cluster->getName());
2197-
for (auto& [cluster_id, weight] : cluster->getConnection()) {
2204+
for (auto& [cluster_id, weight] : cluster->getConnectionsMap()) {
21982205
logger_->report(" {} {} ",
21992206
tree_->maps.id_to_cluster[cluster_id]->getName(),
22002207
weight);

src/mpl/src/hier_rtlmp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ void HierRTLMP::placeChildren(Cluster* parent, bool ignore_std_cell_area)
14861486
for (auto& cluster : parent->getChildren()) {
14871487
const int src_id = cluster->getId();
14881488
const std::string src_name = cluster->getName();
1489-
for (auto& [cluster_id, weight] : cluster->getConnection()) {
1489+
for (auto& [cluster_id, weight] : cluster->getConnectionsMap()) {
14901490
debugPrint(logger_,
14911491
MPL,
14921492
"hierarchical_macro_placement",
@@ -2296,7 +2296,7 @@ void HierRTLMP::createFixedTerminals(const Rect& outline,
22962296
std::set<int> clusters_ids;
22972297

22982298
for (auto& macro_cluster : macro_clusters) {
2299-
for (auto [cluster_id, weight] : macro_cluster->getConnection()) {
2299+
for (auto [cluster_id, weight] : macro_cluster->getConnectionsMap()) {
23002300
clusters_ids.insert(cluster_id);
23012301
}
23022302
}
@@ -2323,7 +2323,7 @@ std::vector<BundledNet> HierRTLMP::computeBundledNets(
23232323
for (auto& macro_cluster : macro_clusters) {
23242324
const int src_id = macro_cluster->getId();
23252325

2326-
for (auto [cluster_id, weight] : macro_cluster->getConnection()) {
2326+
for (auto [cluster_id, weight] : macro_cluster->getConnectionsMap()) {
23272327
BundledNet net(
23282328
cluster_to_macro.at(src_id), cluster_to_macro.at(cluster_id), weight);
23292329

src/mpl/src/object.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -565,21 +565,26 @@ bool Cluster::attemptMerge(Cluster* incomer, bool& incomer_deleted)
565565
// Connection signature support
566566
void Cluster::initConnection()
567567
{
568-
connection_map_.clear();
568+
connections_map_.clear();
569569
}
570570

571571
void Cluster::addConnection(int cluster_id, float weight)
572572
{
573-
if (connection_map_.find(cluster_id) == connection_map_.end()) {
574-
connection_map_[cluster_id] = weight;
573+
if (connections_map_.find(cluster_id) == connections_map_.end()) {
574+
connections_map_[cluster_id] = weight;
575575
} else {
576-
connection_map_[cluster_id] += weight;
576+
connections_map_[cluster_id] += weight;
577577
}
578578
}
579579

580-
std::map<int, float> Cluster::getConnection() const
580+
void Cluster::removeConnection(int cluster_id)
581581
{
582-
return connection_map_;
582+
connections_map_.erase(cluster_id);
583+
}
584+
585+
const ConnectionsMap& Cluster::getConnectionsMap() const
586+
{
587+
return connections_map_;
583588
}
584589

585590
// The connection signature is based on connection topology
@@ -590,7 +595,7 @@ bool Cluster::isSameConnSignature(const Cluster& cluster, float net_threshold)
590595
{
591596
std::vector<int> neighbors; // neighbors of current cluster
592597
std::vector<int> cluster_neighbors; // neighbors of the input cluster
593-
for (auto& [cluster_id, weight] : connection_map_) {
598+
for (auto& [cluster_id, weight] : connections_map_) {
594599
if ((cluster_id != id_) && (cluster_id != cluster.id_)
595600
&& (weight >= net_threshold)) {
596601
neighbors.push_back(cluster_id);
@@ -601,7 +606,7 @@ bool Cluster::isSameConnSignature(const Cluster& cluster, float net_threshold)
601606
return false;
602607
}
603608

604-
for (auto& [cluster_id, weight] : cluster.connection_map_) {
609+
for (auto& [cluster_id, weight] : cluster.connections_map_) {
605610
if ((cluster_id != id_) && (cluster_id != cluster.id_)
606611
&& (weight >= net_threshold)) {
607612
cluster_neighbors.push_back(cluster_id);
@@ -629,7 +634,7 @@ bool Cluster::hasMacroConnectionWith(const Cluster& cluster,
629634
float net_threshold)
630635
{
631636
if (id_ != cluster.getId()) {
632-
for (const auto& [cluster_id, num_of_conn] : connection_map_) {
637+
for (const auto& [cluster_id, num_of_conn] : connections_map_) {
633638
if (cluster_id == cluster.getId() && num_of_conn > net_threshold) {
634639
return true;
635640
}
@@ -650,7 +655,7 @@ int Cluster::getCloseCluster(const std::vector<int>& candidate_clusters,
650655
{
651656
int closely_cluster = -1;
652657
int num_closely_clusters = 0;
653-
for (auto& [cluster_id, num_nets] : connection_map_) {
658+
for (auto& [cluster_id, num_nets] : connections_map_) {
654659
debugPrint(logger_,
655660
MPL,
656661
"multilevel_autoclustering",

src/mpl/src/object.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class HardMacro;
3737
class SoftMacro;
3838
class Cluster;
3939

40+
using ConnectionsMap = std::map<int, float>;
4041
using IntervalList = std::vector<Interval>;
4142
using TilingList = std::vector<Tiling>;
4243
using TilingSet = std::set<Tiling>;
@@ -209,9 +210,8 @@ class Cluster
209210
// Connection signature support
210211
void initConnection();
211212
void addConnection(int cluster_id, float weight);
212-
// TODO: this should return a const reference iff callers don't implicitly
213-
// modify it. See comment in Cluster.
214-
std::map<int, float> getConnection() const;
213+
void removeConnection(int cluster_id);
214+
const ConnectionsMap& getConnectionsMap() const;
215215
bool isSameConnSignature(const Cluster& cluster, float net_threshold);
216216
bool hasMacroConnectionWith(const Cluster& cluster, float net_threshold);
217217
int getCloseCluster(const std::vector<int>& candidate_clusters,
@@ -255,7 +255,7 @@ class Cluster
255255
Cluster* parent_{nullptr};
256256
UniqueClusterVector children_;
257257

258-
std::map<int, float> connection_map_; // id -> connection weight
258+
ConnectionsMap connections_map_; // cluster id -> connection weight
259259
std::vector<std::pair<int, int>> virtual_connections_; // id -> id
260260

261261
utl::Logger* logger_;

0 commit comments

Comments
 (0)