summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib/Clustering.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/Clustering.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/Clustering.cpp61
1 files changed, 28 insertions, 33 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.cpp b/llvm/tools/llvm-exegesis/lib/Clustering.cpp
index 5df47933e71..7fb500e8399 100644
--- a/llvm/tools/llvm-exegesis/lib/Clustering.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Clustering.cpp
@@ -59,7 +59,7 @@ bool InstructionBenchmarkClustering::areAllNeighbours(
ArrayRef<size_t> Pts) const {
// First, get the centroid of this group of points. This is O(N).
SchedClassClusterCentroid G;
- llvm::for_each(Pts, [this, &G](size_t P) {
+ for_each(Pts, [this, &G](size_t P) {
assert(P < Points_.size());
ArrayRef<BenchmarkMeasure> Measurements = Points_[P].Measurements;
if (Measurements.empty()) // Error point.
@@ -73,7 +73,7 @@ bool InstructionBenchmarkClustering::areAllNeighbours(
AnalysisClusteringEpsilonSquared_ / 4.0;
// And now check that every point is a neighbour of the centroid. Also O(N).
- return llvm::all_of(
+ return all_of(
Pts, [this, &Centroid, AnalysisClusteringEpsilonHalvedSquared](size_t P) {
assert(P < Points_.size());
const auto &PMeasurements = Points_[P].Measurements;
@@ -91,7 +91,7 @@ InstructionBenchmarkClustering::InstructionBenchmarkClustering(
AnalysisClusteringEpsilonSquared_(AnalysisClusteringEpsilonSquared),
NoiseCluster_(ClusterId::noise()), ErrorCluster_(ClusterId::error()) {}
-llvm::Error InstructionBenchmarkClustering::validateAndSetup() {
+Error InstructionBenchmarkClustering::validateAndSetup() {
ClusterIdForPoint_.resize(Points_.size());
// Mark erroneous measurements out.
// All points must have the same number of dimensions, in the same order.
@@ -106,15 +106,14 @@ llvm::Error InstructionBenchmarkClustering::validateAndSetup() {
const auto *CurMeasurement = &Point.Measurements;
if (LastMeasurement) {
if (LastMeasurement->size() != CurMeasurement->size()) {
- return llvm::make_error<llvm::StringError>(
- "inconsistent measurement dimensions",
- llvm::inconvertibleErrorCode());
+ return make_error<StringError>("inconsistent measurement dimensions",
+ inconvertibleErrorCode());
}
for (size_t I = 0, E = LastMeasurement->size(); I < E; ++I) {
if (LastMeasurement->at(I).Key != CurMeasurement->at(I).Key) {
- return llvm::make_error<llvm::StringError>(
+ return make_error<StringError>(
"inconsistent measurement dimensions keys",
- llvm::inconvertibleErrorCode());
+ inconvertibleErrorCode());
}
}
}
@@ -123,7 +122,7 @@ llvm::Error InstructionBenchmarkClustering::validateAndSetup() {
if (LastMeasurement) {
NumDimensions_ = LastMeasurement->size();
}
- return llvm::Error::success();
+ return Error::success();
}
void InstructionBenchmarkClustering::clusterizeDbScan(const size_t MinPts) {
@@ -146,7 +145,7 @@ void InstructionBenchmarkClustering::clusterizeDbScan(const size_t MinPts) {
CurrentCluster.PointIndices.push_back(P);
// Process P's neighbors.
- llvm::SetVector<size_t, std::deque<size_t>> ToProcess;
+ SetVector<size_t, std::deque<size_t>> ToProcess;
ToProcess.insert(Neighbors.begin(), Neighbors.end());
while (!ToProcess.empty()) {
// Retrieve a point from the set.
@@ -185,14 +184,14 @@ void InstructionBenchmarkClustering::clusterizeDbScan(const size_t MinPts) {
void InstructionBenchmarkClustering::clusterizeNaive(unsigned NumOpcodes) {
// Given an instruction Opcode, which are the benchmarks of this instruction?
- std::vector<llvm::SmallVector<size_t, 1>> OpcodeToPoints;
+ std::vector<SmallVector<size_t, 1>> OpcodeToPoints;
OpcodeToPoints.resize(NumOpcodes);
size_t NumOpcodesSeen = 0;
for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) {
const InstructionBenchmark &Point = Points_[P];
const unsigned Opcode = Point.keyInstruction().getOpcode();
assert(Opcode < NumOpcodes && "NumOpcodes is incorrect (too small)");
- llvm::SmallVectorImpl<size_t> &PointsOfOpcode = OpcodeToPoints[Opcode];
+ SmallVectorImpl<size_t> &PointsOfOpcode = OpcodeToPoints[Opcode];
if (PointsOfOpcode.empty()) // If we previously have not seen any points of
++NumOpcodesSeen; // this opcode, then naturally this is the new opcode.
PointsOfOpcode.emplace_back(P);
@@ -204,16 +203,16 @@ void InstructionBenchmarkClustering::clusterizeNaive(unsigned NumOpcodes) {
"can't see more opcodes than there are total points");
Clusters_.reserve(NumOpcodesSeen); // One cluster per opcode.
- for (ArrayRef<size_t> PointsOfOpcode : llvm::make_filter_range(
- OpcodeToPoints, [](ArrayRef<size_t> PointsOfOpcode) {
- return !PointsOfOpcode.empty(); // Ignore opcodes with no points.
- })) {
+ for (ArrayRef<size_t> PointsOfOpcode :
+ make_filter_range(OpcodeToPoints, [](ArrayRef<size_t> PointsOfOpcode) {
+ return !PointsOfOpcode.empty(); // Ignore opcodes with no points.
+ })) {
// Create a new cluster.
Clusters_.emplace_back(ClusterId::makeValid(
Clusters_.size(), /*IsUnstable=*/!areAllNeighbours(PointsOfOpcode)));
Cluster &CurrentCluster = Clusters_.back();
// Mark points as belonging to the new cluster.
- llvm::for_each(PointsOfOpcode, [this, &CurrentCluster](size_t P) {
+ for_each(PointsOfOpcode, [this, &CurrentCluster](size_t P) {
ClusterIdForPoint_[P] = CurrentCluster.Id;
});
// And add all the points of this opcode to the new cluster.
@@ -250,8 +249,7 @@ void InstructionBenchmarkClustering::stabilize(unsigned NumOpcodes) {
bool operator<(const OpcodeAndConfig &O) const { return Tie() < O.Tie(); }
bool operator!=(const OpcodeAndConfig &O) const { return Tie() != O.Tie(); }
};
- std::map<OpcodeAndConfig, llvm::SmallSet<ClusterId, 1>>
- OpcodeConfigToClusterIDs;
+ std::map<OpcodeAndConfig, SmallSet<ClusterId, 1>> OpcodeConfigToClusterIDs;
// Populate OpcodeConfigToClusterIDs and UnstableOpcodes data structures.
assert(ClusterIdForPoint_.size() == Points_.size() && "size mismatch");
for (const auto &Point : zip(Points_, ClusterIdForPoint_)) {
@@ -259,14 +257,12 @@ void InstructionBenchmarkClustering::stabilize(unsigned NumOpcodes) {
if (!ClusterIdOfPoint.isValid())
continue; // Only process fully valid clusters.
const OpcodeAndConfig Key(std::get<0>(Point));
- llvm::SmallSet<ClusterId, 1> &ClusterIDsOfOpcode =
- OpcodeConfigToClusterIDs[Key];
+ SmallSet<ClusterId, 1> &ClusterIDsOfOpcode = OpcodeConfigToClusterIDs[Key];
ClusterIDsOfOpcode.insert(ClusterIdOfPoint);
}
for (const auto &OpcodeConfigToClusterID : OpcodeConfigToClusterIDs) {
- const llvm::SmallSet<ClusterId, 1> &ClusterIDs =
- OpcodeConfigToClusterID.second;
+ const SmallSet<ClusterId, 1> &ClusterIDs = OpcodeConfigToClusterID.second;
const OpcodeAndConfig &Key = OpcodeConfigToClusterID.first;
// We only care about unstable instructions.
if (ClusterIDs.size() < 2)
@@ -317,11 +313,10 @@ void InstructionBenchmarkClustering::stabilize(unsigned NumOpcodes) {
}
}
-llvm::Expected<InstructionBenchmarkClustering>
-InstructionBenchmarkClustering::create(
+Expected<InstructionBenchmarkClustering> InstructionBenchmarkClustering::create(
const std::vector<InstructionBenchmark> &Points, const ModeE Mode,
const size_t DbscanMinPts, const double AnalysisClusteringEpsilon,
- llvm::Optional<unsigned> NumOpcodes) {
+ Optional<unsigned> NumOpcodes) {
InstructionBenchmarkClustering Clustering(
Points, AnalysisClusteringEpsilon * AnalysisClusteringEpsilon);
if (auto Error = Clustering.validateAndSetup()) {
@@ -338,7 +333,7 @@ InstructionBenchmarkClustering::create(
Clustering.stabilize(NumOpcodes.getValue());
} else /*if(Mode == ModeE::Naive)*/ {
if (!NumOpcodes.hasValue())
- llvm::report_fatal_error(
+ report_fatal_error(
"'naive' clustering mode requires opcode count to be specified");
Clustering.clusterizeNaive(NumOpcodes.getValue());
}
@@ -352,13 +347,13 @@ void SchedClassClusterCentroid::addPoint(ArrayRef<BenchmarkMeasure> Point) {
assert(Representative.size() == Point.size() &&
"All points should have identical dimensions.");
- for (const auto &I : llvm::zip(Representative, Point))
+ for (const auto &I : zip(Representative, Point))
std::get<0>(I).push(std::get<1>(I));
}
std::vector<BenchmarkMeasure> SchedClassClusterCentroid::getAsPoint() const {
std::vector<BenchmarkMeasure> ClusterCenterPoint(Representative.size());
- for (const auto &I : llvm::zip(ClusterCenterPoint, Representative))
+ for (const auto &I : zip(ClusterCenterPoint, Representative))
std::get<0>(I).PerInstructionValue = std::get<1>(I).avg();
return ClusterCenterPoint;
}
@@ -369,7 +364,7 @@ bool SchedClassClusterCentroid::validate(
switch (Mode) {
case InstructionBenchmark::Latency:
if (NumMeasurements != 1) {
- llvm::errs()
+ errs()
<< "invalid number of measurements in latency mode: expected 1, got "
<< NumMeasurements << "\n";
return false;
@@ -380,9 +375,9 @@ bool SchedClassClusterCentroid::validate(
break;
case InstructionBenchmark::InverseThroughput:
if (NumMeasurements != 1) {
- llvm::errs() << "invalid number of measurements in inverse throughput "
- "mode: expected 1, got "
- << NumMeasurements << "\n";
+ errs() << "invalid number of measurements in inverse throughput "
+ "mode: expected 1, got "
+ << NumMeasurements << "\n";
return false;
}
break;
OpenPOWER on IntegriCloud