From: Simon Pilgrim Date: Fri, 14 Dec 2018 09:25:08 +0000 (+0000) Subject: Revert rL349136: [llvm-exegesis] Optimize ToProcess in dbScan X-Git-Tag: llvmorg-8.0.0-rc1~2122 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=96408bb04a03b4ac961831c270fd9c996358ee03;p=platform%2Fupstream%2Fllvm.git Revert rL349136: [llvm-exegesis] Optimize ToProcess in dbScan Summary: Use `vector Added + vector ToProcess` to replace `SetVector ToProcess` We also check `Added[P]` to enqueueing a point more than once, which also saves us a `ClusterIdForPoint_[Q].isUndef()` check. Reviewers: courbet, RKSimon, gchatelet, john.brawn, lebedev.ri Subscribers: tschuett, llvm-commits Differential Revision: https://reviews.llvm.org/D54442 ........ Patch wasn't approved and breaks buildbots llvm-svn: 349139 --- diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.cpp b/llvm/tools/llvm-exegesis/lib/Clustering.cpp index 508068e..b2cd97c 100644 --- a/llvm/tools/llvm-exegesis/lib/Clustering.cpp +++ b/llvm/tools/llvm-exegesis/lib/Clustering.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "Clustering.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include @@ -91,14 +92,8 @@ llvm::Error InstructionBenchmarkClustering::validateAndSetup() { } void InstructionBenchmarkClustering::dbScan(const size_t MinPts) { - const size_t NumPoints = Points_.size(); - - // Persistent buffers to avoid allocs. - std::vector Neighbors; - std::vector ToProcess(NumPoints); - std::vector Added(NumPoints); - - for (size_t P = 0; P < NumPoints; ++P) { + std::vector Neighbors; // Persistent buffer to avoid allocs. + for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) { if (!ClusterIdForPoint_[P].isUndef()) continue; // Previously processed in inner loop. rangeQuery(P, Neighbors); @@ -114,18 +109,14 @@ void InstructionBenchmarkClustering::dbScan(const size_t MinPts) { Cluster &CurrentCluster = Clusters_.back(); ClusterIdForPoint_[P] = CurrentCluster.Id; /* Label initial point */ CurrentCluster.PointIndices.push_back(P); - Added[P] = 1; // Process P's neighbors. - size_t Tail = 0; - for (size_t Q : Neighbors) - if (!Added[Q]) { - ToProcess[Tail++] = P; - Added[Q] = 1; - } - for (size_t Head = 0; Head < Tail; ++Head) { + llvm::SetVector> ToProcess; + ToProcess.insert(Neighbors.begin(), Neighbors.end()); + while (!ToProcess.empty()) { // Retrieve a point from the set. - size_t Q = ToProcess[Head]; + const size_t Q = *ToProcess.begin(); + ToProcess.erase(ToProcess.begin()); if (ClusterIdForPoint_[Q].isNoise()) { // Change noise point to border point. @@ -133,18 +124,17 @@ void InstructionBenchmarkClustering::dbScan(const size_t MinPts) { CurrentCluster.PointIndices.push_back(Q); continue; } - assert(ClusterIdForPoint_[Q].isUndef()); + if (!ClusterIdForPoint_[Q].isUndef()) { + continue; // Previously processed. + } // Add Q to the current custer. ClusterIdForPoint_[Q] = CurrentCluster.Id; CurrentCluster.PointIndices.push_back(Q); // And extend to the neighbors of Q if the region is dense enough. rangeQuery(Q, Neighbors); - if (Neighbors.size() + 1 >= MinPts) - for (size_t P : Neighbors) - if (!Added[P]) { - ToProcess[Tail++] = P; - Added[P] = 1; - } + if (Neighbors.size() + 1 >= MinPts) { + ToProcess.insert(Neighbors.begin(), Neighbors.end()); + } } } // assert(Neighbors.capacity() == (Points_.size() - 1));