@@ -1032,9 +1032,11 @@ void ClusteringEngine::buildDataFlowConnections()
10321032 for (int hops = 0 ; hops < max_num_of_hops_; hops++) {
10331033 std::set<int > sink_clusters = computeSinks (insts[hops]);
10341034 const float conn_weight = computeConnWeight (hops);
1035- for (auto & sink : sink_clusters) {
1036- Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink);
1037- connect (driver_cluster, sink_cluster, conn_weight);
1035+ for (const int sink_id : sink_clusters) {
1036+ if (driver_id != sink_id) {
1037+ Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink_id);
1038+ connect (driver_cluster, sink_cluster, conn_weight);
1039+ }
10381040 }
10391041 }
10401042 }
@@ -1047,9 +1049,11 @@ void ClusteringEngine::buildDataFlowConnections()
10471049 for (int hops = 0 ; hops < max_num_of_hops_; hops++) {
10481050 std::set<int > sink_clusters = computeSinks (insts[hops]);
10491051 const float conn_weight = computeConnWeight (hops);
1050- for (auto & sink : sink_clusters) {
1051- Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink);
1052- connect (driver_cluster, sink_cluster, conn_weight);
1052+ for (const int sink_id : sink_clusters) {
1053+ if (driver_id != sink_id) {
1054+ Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink_id);
1055+ connect (driver_cluster, sink_cluster, conn_weight);
1056+ }
10531057 }
10541058 }
10551059 }
@@ -1062,9 +1066,11 @@ void ClusteringEngine::buildDataFlowConnections()
10621066 for (int hops = 0 ; hops < max_num_of_hops_; hops++) {
10631067 std::set<int > sink_clusters = computeSinks (insts[hops]);
10641068 const float conn_weight = computeConnWeight (hops);
1065- for (auto & sink : sink_clusters) {
1066- Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink);
1067- connect (driver_cluster, sink_cluster, conn_weight);
1069+ for (const int sink_id : sink_clusters) {
1070+ if (driver_id != sink_id) {
1071+ Cluster* sink_cluster = tree_->maps .id_to_cluster .at (sink_id);
1072+ connect (driver_cluster, sink_cluster, conn_weight);
1073+ }
10681074 }
10691075 }
10701076 }
@@ -1874,7 +1880,13 @@ bool ClusteringEngine::attemptMerge(Cluster* receiver, Cluster* incomer)
18741880 for (const auto & [cluster_id, connection_weight] : incomer_connections) {
18751881 Cluster* cluster = tree_->maps .id_to_cluster .at (cluster_id);
18761882 cluster->removeConnection (incomer_id);
1877- cluster->addConnection (receiver, connection_weight);
1883+
1884+ // If the incomer and the receiver were connected, we forget that
1885+ // connection, otherwise we'll end up with the receiver connected
1886+ // to itself.
1887+ if (cluster_id != receiver->getId ()) {
1888+ cluster->addConnection (receiver, connection_weight);
1889+ }
18781890 }
18791891 }
18801892
0 commit comments