@@ -1027,9 +1027,11 @@ void ClusteringEngine::buildDataFlowConnections()
10271027 for (int hops = 0 ; hops < max_num_of_hops_; hops++) {
10281028 std::set<int > sink_clusters = computeSinks (insts[hops]);
10291029 const float conn_weight = computeConnWeight (hops);
1030- for (auto & sink : sink_clusters) {
1031- Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink);
1032- connect (driver_cluster, sink_cluster, conn_weight);
1030+ for (const int sink_id : sink_clusters) {
1031+ if (driver_id != sink_id) {
1032+ Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink_id);
1033+ connect (driver_cluster, sink_cluster, conn_weight);
1034+ }
10331035 }
10341036 }
10351037 }
@@ -1042,9 +1044,11 @@ void ClusteringEngine::buildDataFlowConnections()
10421044 for (int hops = 0 ; hops < max_num_of_hops_; hops++) {
10431045 std::set<int > sink_clusters = computeSinks (insts[hops]);
10441046 const float conn_weight = computeConnWeight (hops);
1045- for (auto & sink : sink_clusters) {
1046- Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink);
1047- connect (driver_cluster, sink_cluster, conn_weight);
1047+ for (const int sink_id : sink_clusters) {
1048+ if (driver_id != sink_id) {
1049+ Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink_id);
1050+ connect (driver_cluster, sink_cluster, conn_weight);
1051+ }
10481052 }
10491053 }
10501054 }
@@ -1057,9 +1061,11 @@ void ClusteringEngine::buildDataFlowConnections()
10571061 for (int hops = 0 ; hops < max_num_of_hops_; hops++) {
10581062 std::set<int > sink_clusters = computeSinks (insts[hops]);
10591063 const float conn_weight = computeConnWeight (hops);
1060- for (auto & sink : sink_clusters) {
1061- Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink);
1062- connect (driver_cluster, sink_cluster, conn_weight);
1064+ for (const int sink_id : sink_clusters) {
1065+ if (driver_id != sink_id) {
1066+ Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink_id);
1067+ connect (driver_cluster, sink_cluster, conn_weight);
1068+ }
10631069 }
10641070 }
10651071 }
@@ -1869,7 +1875,13 @@ bool ClusteringEngine::attemptMerge(Cluster* receiver, Cluster* incomer)
18691875 for (const auto & [cluster_id, connection_weight] : incomer_connections) {
18701876 Cluster* cluster = tree_->maps .id_to_cluster .at (cluster_id);
18711877 cluster->removeConnection (incomer_id);
1872- cluster->addConnection (receiver, connection_weight);
1878+
1879+ // If the incomer and the receiver were connected, we forget that
1880+ // connection, otherwise we'll end up with the receiver connected
1881+ // to itself.
1882+ if (cluster_id != receiver->getId ()) {
1883+ cluster->addConnection (receiver, connection_weight);
1884+ }
18731885 }
18741886 }
18751887
0 commit comments