[PATCH] D54390: [llvm-exegesis] InstructionBenchmarkClustering::rangeQuery(): write into llvm::SmallVectorImpl& output parameter

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 19 05:31:42 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL347202: [llvm-exegesis] InstructionBenchmarkClustering::rangeQuery(): write into llvm… (authored by lebedevri, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54390?vs=173553&id=174597#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54390

Files:
  llvm/trunk/tools/llvm-exegesis/lib/Clustering.cpp
  llvm/trunk/tools/llvm-exegesis/lib/Clustering.h


Index: llvm/trunk/tools/llvm-exegesis/lib/Clustering.cpp
===================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Clustering.cpp
+++ llvm/trunk/tools/llvm-exegesis/lib/Clustering.cpp
@@ -33,9 +33,9 @@
 
 // Finds the points at distance less than sqrt(EpsilonSquared) of Q (not
 // including Q).
-llvm::SmallVector<size_t, 0>
-InstructionBenchmarkClustering::rangeQuery(const size_t Q) const {
-  llvm::SmallVector<size_t, 0> Neighbors;
+void InstructionBenchmarkClustering::rangeQuery(
+    const size_t Q, llvm::SmallVectorImpl<size_t> &Neighbors) const {
+  Neighbors.clear();
   const auto &QMeasurements = Points_[Q].Measurements;
   for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) {
     if (P == Q)
@@ -47,7 +47,6 @@
       Neighbors.push_back(P);
     }
   }
-  return Neighbors;
 }
 
 bool InstructionBenchmarkClustering::isNeighbour(
@@ -103,10 +102,11 @@
 }
 
 void InstructionBenchmarkClustering::dbScan(const size_t MinPts) {
+  llvm::SmallVector<size_t, 0> 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.
-    const auto Neighbors = rangeQuery(P);
+    rangeQuery(P, Neighbors);
     if (Neighbors.size() + 1 < MinPts) { // Density check.
       // The region around P is not dense enough to create a new cluster, mark
       // as noise for now.
@@ -141,7 +141,7 @@
       ClusterIdForPoint_[Q] = CurrentCluster.Id;
       CurrentCluster.PointIndices.push_back(Q);
       // And extend to the neighbors of Q if the region is dense enough.
-      const auto Neighbors = rangeQuery(Q);
+      rangeQuery(Q, Neighbors);
       if (Neighbors.size() + 1 >= MinPts) {
         ToProcess.insert(Neighbors.begin(), Neighbors.end());
       }
Index: llvm/trunk/tools/llvm-exegesis/lib/Clustering.h
===================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Clustering.h
+++ llvm/trunk/tools/llvm-exegesis/lib/Clustering.h
@@ -97,7 +97,7 @@
       const std::vector<InstructionBenchmark> &Points, double EpsilonSquared);
   llvm::Error validateAndSetup();
   void dbScan(size_t MinPts);
-  llvm::SmallVector<size_t, 0> rangeQuery(size_t Q) const;
+  void rangeQuery(size_t Q, llvm::SmallVectorImpl<size_t> &Scratchpad) const;
 
   const std::vector<InstructionBenchmark> &Points_;
   const double EpsilonSquared_;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54390.174597.patch
Type: text/x-patch
Size: 2507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181119/d180abc7/attachment.bin>


More information about the llvm-commits mailing list