[llvm] r357263 - [NFC][llvm-exegesis] Also promote getSchedClassPoint() into ResolvedSchedClass.
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 29 07:58:01 PDT 2019
Author: lebedevri
Date: Fri Mar 29 07:58:01 2019
New Revision: 357263
URL: http://llvm.org/viewvc/llvm-project?rev=357263&view=rev
Log:
[NFC][llvm-exegesis] Also promote getSchedClassPoint() into ResolvedSchedClass.
Summary:
It doesn't need anything from Analysis::SchedClassCluster class,
and takes ResolvedSchedClass as param, so this seems rather fitting.
Reviewers: courbet, gchatelet
Reviewed By: courbet
Subscribers: tschuett, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59994
Modified:
llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
llvm/trunk/tools/llvm-exegesis/lib/Analysis.h
llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.cpp
llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.h
Modified: llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp?rev=357263&r1=357262&r2=357263&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp Fri Mar 29 07:58:01 2019
@@ -348,84 +348,6 @@ void Analysis::SchedClassCluster::addPoi
Centroid.addPoint(Point.Measurements);
}
-// Returns a ProxResIdx by id or name.
-static unsigned findProcResIdx(const llvm::MCSubtargetInfo &STI,
- const llvm::StringRef NameOrId) {
- // Interpret the key as an ProcResIdx.
- unsigned ProcResIdx = 0;
- if (llvm::to_integer(NameOrId, ProcResIdx, 10))
- return ProcResIdx;
- // Interpret the key as a ProcRes name.
- const auto &SchedModel = STI.getSchedModel();
- for (int I = 0, E = SchedModel.getNumProcResourceKinds(); I < E; ++I) {
- if (NameOrId == SchedModel.getProcResource(I)->Name)
- return I;
- }
- return 0;
-}
-
-std::vector<BenchmarkMeasure> Analysis::SchedClassCluster::getSchedClassPoint(
- InstructionBenchmark::ModeE Mode, const llvm::MCSubtargetInfo &STI,
- const ResolvedSchedClass &RSC,
- ArrayRef<PerInstructionStats> Representative) const {
- const size_t NumMeasurements = Representative.size();
-
- std::vector<BenchmarkMeasure> SchedClassPoint(NumMeasurements);
-
- if (Mode == InstructionBenchmark::Latency) {
- assert(NumMeasurements == 1 && "Latency is a single measure.");
- BenchmarkMeasure &LatencyMeasure = SchedClassPoint[0];
-
- // Find the latency.
- LatencyMeasure.PerInstructionValue = 0.0;
-
- for (unsigned I = 0; I < RSC.SCDesc->NumWriteLatencyEntries; ++I) {
- const llvm::MCWriteLatencyEntry *const WLE =
- STI.getWriteLatencyEntry(RSC.SCDesc, I);
- LatencyMeasure.PerInstructionValue =
- std::max<double>(LatencyMeasure.PerInstructionValue, WLE->Cycles);
- }
- } else if (Mode == InstructionBenchmark::Uops) {
- for (const auto &I : llvm::zip(SchedClassPoint, Representative)) {
- BenchmarkMeasure &Measure = std::get<0>(I);
- const PerInstructionStats &Stats = std::get<1>(I);
-
- StringRef Key = Stats.key();
- uint16_t ProcResIdx = findProcResIdx(STI, Key);
- if (ProcResIdx > 0) {
- // Find the pressure on ProcResIdx `Key`.
- const auto ProcResPressureIt =
- std::find_if(RSC.IdealizedProcResPressure.begin(),
- RSC.IdealizedProcResPressure.end(),
- [ProcResIdx](const std::pair<uint16_t, float> &WPR) {
- return WPR.first == ProcResIdx;
- });
- Measure.PerInstructionValue =
- ProcResPressureIt == RSC.IdealizedProcResPressure.end()
- ? 0.0
- : ProcResPressureIt->second;
- } else if (Key == "NumMicroOps") {
- Measure.PerInstructionValue = RSC.SCDesc->NumMicroOps;
- } else {
- llvm::errs() << "expected `key` to be either a ProcResIdx or a ProcRes "
- "name, got "
- << Key << "\n";
- return {};
- }
- }
- } else if (Mode == InstructionBenchmark::InverseThroughput) {
- assert(NumMeasurements == 1 && "Inverse Throughput is a single measure.");
- BenchmarkMeasure &RThroughputMeasure = SchedClassPoint[0];
-
- RThroughputMeasure.PerInstructionValue =
- MCSchedModel::getReciprocalThroughput(STI, *RSC.SCDesc);
- } else {
- llvm_unreachable("unimplemented measurement matching mode");
- }
-
- return SchedClassPoint;
-}
-
bool Analysis::SchedClassCluster::measurementsMatch(
const llvm::MCSubtargetInfo &STI, const ResolvedSchedClass &RSC,
const InstructionBenchmarkClustering &Clustering,
@@ -440,7 +362,7 @@ bool Analysis::SchedClassCluster::measur
Centroid.getAsPoint();
const std::vector<BenchmarkMeasure> SchedClassPoint =
- getSchedClassPoint(Mode, STI, RSC, Centroid.getStats());
+ RSC.getAsPoint(Mode, STI, Centroid.getStats());
if (SchedClassPoint.empty())
return false; // In Uops mode validate() may not be enough.
Modified: llvm/trunk/tools/llvm-exegesis/lib/Analysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Analysis.h?rev=357263&r1=357262&r2=357263&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.h Fri Mar 29 07:58:01 2019
@@ -67,12 +67,6 @@ private:
// Return the cluster centroid.
const SchedClassClusterCentroid &getCentroid() const { return Centroid; }
- std::vector<BenchmarkMeasure>
- getSchedClassPoint(InstructionBenchmark::ModeE Mode,
- const llvm::MCSubtargetInfo &STI,
- const ResolvedSchedClass &SC,
- ArrayRef<PerInstructionStats> Representative) const;
-
// Returns true if the cluster representative measurements match that of SC.
bool
measurementsMatch(const llvm::MCSubtargetInfo &STI,
Modified: llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.cpp?rev=357263&r1=357262&r2=357263&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.cpp Fri Mar 29 07:58:01 2019
@@ -239,5 +239,81 @@ ResolvedSchedClass::resolveSchedClassId(
return std::make_pair(SchedClassId, WasVariant);
}
+// Returns a ProxResIdx by id or name.
+static unsigned findProcResIdx(const llvm::MCSubtargetInfo &STI,
+ const llvm::StringRef NameOrId) {
+ // Interpret the key as an ProcResIdx.
+ unsigned ProcResIdx = 0;
+ if (llvm::to_integer(NameOrId, ProcResIdx, 10))
+ return ProcResIdx;
+ // Interpret the key as a ProcRes name.
+ const auto &SchedModel = STI.getSchedModel();
+ for (int I = 0, E = SchedModel.getNumProcResourceKinds(); I < E; ++I) {
+ if (NameOrId == SchedModel.getProcResource(I)->Name)
+ return I;
+ }
+ return 0;
+}
+
+std::vector<BenchmarkMeasure> ResolvedSchedClass::getAsPoint(
+ InstructionBenchmark::ModeE Mode, const llvm::MCSubtargetInfo &STI,
+ ArrayRef<PerInstructionStats> Representative) const {
+ const size_t NumMeasurements = Representative.size();
+
+ std::vector<BenchmarkMeasure> SchedClassPoint(NumMeasurements);
+
+ if (Mode == InstructionBenchmark::Latency) {
+ assert(NumMeasurements == 1 && "Latency is a single measure.");
+ BenchmarkMeasure &LatencyMeasure = SchedClassPoint[0];
+
+ // Find the latency.
+ LatencyMeasure.PerInstructionValue = 0.0;
+
+ for (unsigned I = 0; I < SCDesc->NumWriteLatencyEntries; ++I) {
+ const llvm::MCWriteLatencyEntry *const WLE =
+ STI.getWriteLatencyEntry(SCDesc, I);
+ LatencyMeasure.PerInstructionValue =
+ std::max<double>(LatencyMeasure.PerInstructionValue, WLE->Cycles);
+ }
+ } else if (Mode == InstructionBenchmark::Uops) {
+ for (const auto &I : llvm::zip(SchedClassPoint, Representative)) {
+ BenchmarkMeasure &Measure = std::get<0>(I);
+ const PerInstructionStats &Stats = std::get<1>(I);
+
+ StringRef Key = Stats.key();
+ uint16_t ProcResIdx = findProcResIdx(STI, Key);
+ if (ProcResIdx > 0) {
+ // Find the pressure on ProcResIdx `Key`.
+ const auto ProcResPressureIt = std::find_if(
+ IdealizedProcResPressure.begin(), IdealizedProcResPressure.end(),
+ [ProcResIdx](const std::pair<uint16_t, float> &WPR) {
+ return WPR.first == ProcResIdx;
+ });
+ Measure.PerInstructionValue =
+ ProcResPressureIt == IdealizedProcResPressure.end()
+ ? 0.0
+ : ProcResPressureIt->second;
+ } else if (Key == "NumMicroOps") {
+ Measure.PerInstructionValue = SCDesc->NumMicroOps;
+ } else {
+ llvm::errs() << "expected `key` to be either a ProcResIdx or a ProcRes "
+ "name, got "
+ << Key << "\n";
+ return {};
+ }
+ }
+ } else if (Mode == InstructionBenchmark::InverseThroughput) {
+ assert(NumMeasurements == 1 && "Inverse Throughput is a single measure.");
+ BenchmarkMeasure &RThroughputMeasure = SchedClassPoint[0];
+
+ RThroughputMeasure.PerInstructionValue =
+ MCSchedModel::getReciprocalThroughput(STI, *SCDesc);
+ } else {
+ llvm_unreachable("unimplemented measurement matching mode");
+ }
+
+ return SchedClassPoint;
+}
+
} // namespace exegesis
} // namespace llvm
Modified: llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.h?rev=357263&r1=357262&r2=357263&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/SchedClassResolution.h Fri Mar 29 07:58:01 2019
@@ -7,13 +7,14 @@
//===----------------------------------------------------------------------===//
///
/// \file
-/// Analysis output for benchmark results.
+/// Resolution of MCInst sched class into expanded form for further analysis.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_EXEGESIS_SCHEDCLASSRESOLUTION_H
#define LLVM_TOOLS_LLVM_EXEGESIS_SCHEDCLASSRESOLUTION_H
+#include "BenchmarkResult.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
#include "llvm/MC/MCInstPrinter.h"
@@ -44,6 +45,10 @@ struct ResolvedSchedClass {
const llvm::MCInstrInfo &InstrInfo,
const llvm::MCInst &MCI);
+ std::vector<BenchmarkMeasure>
+ getAsPoint(InstructionBenchmark::ModeE Mode, const llvm::MCSubtargetInfo &STI,
+ ArrayRef<PerInstructionStats> Representative) const;
+
const unsigned SchedClassId;
const llvm::MCSchedClassDesc *const SCDesc;
const bool WasVariant; // Whether the original class was variant.
More information about the llvm-commits
mailing list