From: Aiden Grossman Date: Mon, 27 Mar 2023 08:14:18 +0000 (+0000) Subject: [llvm-exegesis] Refactor InstructionBenchmark to Benchmark X-Git-Tag: upstream/17.0.6~13615 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=389bf5d870b3bc014b004a750c539786eba8c543;p=platform%2Fupstream%2Fllvm.git [llvm-exegesis] Refactor InstructionBenchmark to Benchmark When llvm-exegesis was first introduced, it only supported benchmarking individual instructions, hence the name for the data structure storing the data corresponding to a benchmark being called InstructionBenchmark made sense. However, now that benchmarking arbitrary snippets is supported, InstructionBenchmark doesn't correspond to a single instruction. This patch refactors InstructionBenchmark to be called Benchmark to clean up this little bit of technical debt. Reviewed By: courbet Differential Revision: https://reviews.llvm.org/D146884 --- diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp index 2d7e17f..f6ee8f6 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -71,7 +71,7 @@ void writeEscaped(raw_ostream &OS, const StringRef S) { template static void writeClusterId(raw_ostream &OS, - const InstructionBenchmarkClustering::ClusterId &CID) { + const BenchmarkClustering::ClusterId &CID) { if (CID.isNoise()) writeEscaped(OS, "[noise]"); else if (CID.isError()) @@ -126,7 +126,7 @@ void Analysis::writeSnippet(raw_ostream &OS, ArrayRef Bytes, // point coordinates (measurements). void Analysis::printInstructionRowCsv(const size_t PointId, raw_ostream &OS) const { - const InstructionBenchmark &Point = Clustering_.getPoints()[PointId]; + const Benchmark &Point = Clustering_.getPoints()[PointId]; writeClusterId(OS, Clustering_.getClusterIdForPoint(PointId)); OS << kCsvSep; writeSnippet(OS, Point.AssembledSnippet, "; "); @@ -153,7 +153,7 @@ void Analysis::printInstructionRowCsv(const size_t PointId, } Analysis::Analysis(const LLVMState &State, - const InstructionBenchmarkClustering &Clustering, + const BenchmarkClustering &Clustering, double AnalysisInconsistencyEpsilon, bool AnalysisDisplayUnstableOpcodes) : Clustering_(Clustering), State_(State), @@ -215,7 +215,7 @@ Analysis::makePointsPerSchedClass() const { std::unordered_map SchedClassIdToIndex; const auto &Points = Clustering_.getPoints(); for (size_t PointId = 0, E = Points.size(); PointId < E; ++PointId) { - const InstructionBenchmark &Point = Points[PointId]; + const Benchmark &Point = Points[PointId]; if (!Point.Error.empty()) continue; assert(!Point.Key.Instructions.empty()); @@ -270,17 +270,17 @@ static void writeLatencySnippetHtml(raw_ostream &OS, } } -void Analysis::printPointHtml(const InstructionBenchmark &Point, +void Analysis::printPointHtml(const Benchmark &Point, llvm::raw_ostream &OS) const { OS << "
  • (OS, Point.AssembledSnippet, "\n"); OS << "\">"; switch (Point.Mode) { - case InstructionBenchmark::Latency: + case Benchmark::Latency: writeLatencySnippetHtml(OS, Point.Key.Instructions, State_.getInstrInfo()); break; - case InstructionBenchmark::Uops: - case InstructionBenchmark::InverseThroughput: + case Benchmark::Uops: + case Benchmark::InverseThroughput: writeParallelSnippetHtml(OS, Point.Key.Instructions, State_.getInstrInfo()); break; default: @@ -334,7 +334,7 @@ void Analysis::printSchedClassClustersHtml( } void Analysis::SchedClassCluster::addPoint( - size_t PointId, const InstructionBenchmarkClustering &Clustering) { + size_t PointId, const BenchmarkClustering &Clustering) { PointIds.push_back(PointId); const auto &Point = Clustering.getPoints()[PointId]; if (ClusterId.isUndef()) @@ -346,10 +346,10 @@ void Analysis::SchedClassCluster::addPoint( bool Analysis::SchedClassCluster::measurementsMatch( const MCSubtargetInfo &STI, const ResolvedSchedClass &RSC, - const InstructionBenchmarkClustering &Clustering, + const BenchmarkClustering &Clustering, const double AnalysisInconsistencyEpsilonSquared_) const { assert(!Clustering.getPoints().empty()); - const InstructionBenchmark::ModeE Mode = Clustering.getPoints()[0].Mode; + const Benchmark::ModeE Mode = Clustering.getPoints()[0].Mode; if (!Centroid.validate(Mode)) return false; @@ -427,7 +427,7 @@ void Analysis::printSchedClassDescHtml(const ResolvedSchedClass &RSC, } void Analysis::printClusterRawHtml( - const InstructionBenchmarkClustering::ClusterId &Id, StringRef display_name, + const BenchmarkClustering::ClusterId &Id, StringRef display_name, llvm::raw_ostream &OS) const { const auto &Points = Clustering_.getPoints(); const auto &Cluster = Clustering_.getCluster(Id); @@ -589,7 +589,7 @@ Error Analysis::run( OS << ""; } - printClusterRawHtml(InstructionBenchmarkClustering::ClusterId::noise(), + printClusterRawHtml(BenchmarkClustering::ClusterId::noise(), "[noise]", OS); OS << ""; diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.h b/llvm/tools/llvm-exegesis/lib/Analysis.h index a903fd2..3271925 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.h +++ b/llvm/tools/llvm-exegesis/lib/Analysis.h @@ -37,7 +37,7 @@ namespace exegesis { class Analysis { public: Analysis(const LLVMState &State, - const InstructionBenchmarkClustering &Clustering, + const BenchmarkClustering &Clustering, double AnalysisInconsistencyEpsilon, bool AnalysisDisplayUnstableOpcodes); @@ -49,19 +49,19 @@ public: template Error run(raw_ostream &OS) const; private: - using ClusterId = InstructionBenchmarkClustering::ClusterId; + using ClusterId = BenchmarkClustering::ClusterId; // Represents the intersection of a sched class and a cluster. class SchedClassCluster { public: - const InstructionBenchmarkClustering::ClusterId &id() const { + const BenchmarkClustering::ClusterId &id() const { return ClusterId; } const std::vector &getPointIds() const { return PointIds; } void addPoint(size_t PointId, - const InstructionBenchmarkClustering &Clustering); + const BenchmarkClustering &Clustering); // Return the cluster centroid. const SchedClassClusterCentroid &getCentroid() const { return Centroid; } @@ -69,11 +69,11 @@ private: // Returns true if the cluster representative measurements match that of SC. bool measurementsMatch(const MCSubtargetInfo &STI, const ResolvedSchedClass &SC, - const InstructionBenchmarkClustering &Clustering, + const BenchmarkClustering &Clustering, const double AnalysisInconsistencyEpsilonSquared_) const; private: - InstructionBenchmarkClustering::ClusterId ClusterId; + BenchmarkClustering::ClusterId ClusterId; std::vector PointIds; // Measurement stats for the points in the SchedClassCluster. SchedClassClusterCentroid Centroid; @@ -81,10 +81,10 @@ private: void printInstructionRowCsv(size_t PointId, raw_ostream &OS) const; - void printClusterRawHtml(const InstructionBenchmarkClustering::ClusterId &Id, + void printClusterRawHtml(const BenchmarkClustering::ClusterId &Id, StringRef display_name, llvm::raw_ostream &OS) const; - void printPointHtml(const InstructionBenchmark &Point, + void printPointHtml(const Benchmark &Point, llvm::raw_ostream &OS) const; void @@ -110,7 +110,7 @@ private: void writeSnippet(raw_ostream &OS, ArrayRef Bytes, const char *Separator) const; - const InstructionBenchmarkClustering &Clustering_; + const BenchmarkClustering &Clustering_; const LLVMState &State_; std::unique_ptr Context_; std::unique_ptr AsmInfo_; diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkCode.h b/llvm/tools/llvm-exegesis/lib/BenchmarkCode.h index 7dceb25..1db8472 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkCode.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkCode.h @@ -19,7 +19,7 @@ namespace exegesis { // A collection of instructions that are to be assembled, executed and measured. struct BenchmarkCode { - InstructionBenchmarkKey Key; + BenchmarkKey Key; // We also need to provide the registers that are live on entry for the // assembler to generate proper prologue/epilogue. diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp index 673221e..b8e53de 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -209,14 +209,14 @@ template <> struct MappingTraits { }; template <> -struct ScalarEnumerationTraits { +struct ScalarEnumerationTraits { static void enumeration(IO &Io, - exegesis::InstructionBenchmark::ModeE &Value) { - Io.enumCase(Value, "", exegesis::InstructionBenchmark::Unknown); - Io.enumCase(Value, "latency", exegesis::InstructionBenchmark::Latency); - Io.enumCase(Value, "uops", exegesis::InstructionBenchmark::Uops); + exegesis::Benchmark::ModeE &Value) { + Io.enumCase(Value, "", exegesis::Benchmark::Unknown); + Io.enumCase(Value, "latency", exegesis::Benchmark::Latency); + Io.enumCase(Value, "uops", exegesis::Benchmark::Uops); Io.enumCase(Value, "inverse_throughput", - exegesis::InstructionBenchmark::InverseThroughput); + exegesis::Benchmark::InverseThroughput); } }; @@ -260,8 +260,8 @@ template <> struct ScalarTraits { }; template <> -struct MappingContextTraits { - static void mapping(IO &Io, exegesis::InstructionBenchmarkKey &Obj, +struct MappingContextTraits { + static void mapping(IO &Io, exegesis::BenchmarkKey &Obj, YamlContext &Context) { Io.setContext(&Context); Io.mapRequired("instructions", Obj.Instructions); @@ -271,7 +271,7 @@ struct MappingContextTraits { }; template <> -struct MappingContextTraits { +struct MappingContextTraits { struct NormalizedBinary { NormalizedBinary(IO &io) {} NormalizedBinary(IO &, std::vector &Data) : Binary(Data) {} @@ -288,7 +288,7 @@ struct MappingContextTraits { BinaryRef Binary; }; - static void mapping(IO &Io, exegesis::InstructionBenchmark &Obj, + static void mapping(IO &Io, exegesis::Benchmark &Obj, YamlContext &Context) { Io.mapRequired("mode", Obj.Mode); Io.mapRequired("key", Obj.Key, Context); @@ -305,9 +305,9 @@ struct MappingContextTraits { } }; -template <> struct MappingTraits { +template <> struct MappingTraits { static void mapping(IO &Io, - exegesis::InstructionBenchmark::TripleAndCpu &Obj) { + exegesis::Benchmark::TripleAndCpu &Obj) { assert(!Io.outputting() && "can only read TripleAndCpu"); // Read triple. Io.mapRequired("llvm_triple", Obj.LLVMTriple); @@ -320,8 +320,8 @@ template <> struct MappingTraits { namespace exegesis { -Expected> -InstructionBenchmark::readTriplesAndCpusFromYamls(MemoryBufferRef Buffer) { +Expected> +Benchmark::readTriplesAndCpusFromYamls(MemoryBufferRef Buffer) { // We're only mapping a field, drop other fields and silence the corresponding // warnings. yaml::Input Yin( @@ -340,11 +340,11 @@ InstructionBenchmark::readTriplesAndCpusFromYamls(MemoryBufferRef Buffer) { return Result; } -Expected -InstructionBenchmark::readYaml(const LLVMState &State, MemoryBufferRef Buffer) { +Expected +Benchmark::readYaml(const LLVMState &State, MemoryBufferRef Buffer) { yaml::Input Yin(Buffer); YamlContext Context(State); - InstructionBenchmark Benchmark; + Benchmark Benchmark; if (Yin.setCurrentDocument()) yaml::yamlize(Yin, Benchmark, /*unused*/ true, Context); if (!Context.getLastError().empty()) @@ -352,12 +352,12 @@ InstructionBenchmark::readYaml(const LLVMState &State, MemoryBufferRef Buffer) { return std::move(Benchmark); } -Expected> -InstructionBenchmark::readYamls(const LLVMState &State, +Expected> +Benchmark::readYamls(const LLVMState &State, MemoryBufferRef Buffer) { yaml::Input Yin(Buffer); YamlContext Context(State); - std::vector Benchmarks; + std::vector Benchmarks; while (Yin.setCurrentDocument()) { Benchmarks.emplace_back(); yamlize(Yin, Benchmarks.back(), /*unused*/ true, Context); @@ -370,7 +370,7 @@ InstructionBenchmark::readYamls(const LLVMState &State, return std::move(Benchmarks); } -Error InstructionBenchmark::writeYamlTo(const LLVMState &State, +Error Benchmark::writeYamlTo(const LLVMState &State, raw_ostream &OS) { auto Cleanup = make_scope_exit([&] { OS.flush(); }); yaml::Output Yout(OS, nullptr /*Ctx*/, 200 /*WrapColumn*/); @@ -383,7 +383,7 @@ Error InstructionBenchmark::writeYamlTo(const LLVMState &State, return Error::success(); } -Error InstructionBenchmark::readYamlFrom(const LLVMState &State, +Error Benchmark::readYamlFrom(const LLVMState &State, StringRef InputContent) { yaml::Input Yin(InputContent); YamlContext Context(State); diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h index a2a8095..0ad18ce 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h @@ -41,9 +41,9 @@ enum class BenchmarkPhaseSelectorE { Measure, }; -enum class InstructionBenchmarkFilter { All, RegOnly, WithMem }; +enum class BenchmarkFilter { All, RegOnly, WithMem }; -struct InstructionBenchmarkKey { +struct BenchmarkKey { // The LLVM opcode name. std::vector Instructions; // The initial values of the registers. @@ -68,8 +68,8 @@ struct BenchmarkMeasure { }; // The result of an instruction benchmark. -struct InstructionBenchmark { - InstructionBenchmarkKey Key; +struct Benchmark { + BenchmarkKey Key; enum ModeE { Unknown, Latency, Uops, InverseThroughput }; ModeE Mode; std::string CpuName; @@ -88,18 +88,18 @@ struct InstructionBenchmark { // How to aggregate measurements. enum ResultAggregationModeE { Min, Max, Mean, MinVariance }; - InstructionBenchmark() = default; - InstructionBenchmark(InstructionBenchmark &&) = default; + Benchmark() = default; + Benchmark(Benchmark &&) = default; - InstructionBenchmark(const InstructionBenchmark &) = delete; - InstructionBenchmark &operator=(const InstructionBenchmark &) = delete; - InstructionBenchmark &operator=(InstructionBenchmark &&) = delete; + Benchmark(const Benchmark &) = delete; + Benchmark &operator=(const Benchmark &) = delete; + Benchmark &operator=(Benchmark &&) = delete; // Read functions. - static Expected readYaml(const LLVMState &State, + static Expected readYaml(const LLVMState &State, MemoryBufferRef Buffer); - static Expected> + static Expected> readYamls(const LLVMState &State, MemoryBufferRef Buffer); // Given a set of serialized instruction benchmarks, returns the set of diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index cc53b00..e268ba7 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -30,7 +30,7 @@ namespace llvm { namespace exegesis { BenchmarkRunner::BenchmarkRunner(const LLVMState &State, - InstructionBenchmark::ModeE Mode, + Benchmark::ModeE Mode, BenchmarkPhaseSelectorE BenchmarkPhaseSelector) : State(State), Mode(Mode), BenchmarkPhaseSelector(BenchmarkPhaseSelector), Scratch(std::make_unique()) {} @@ -155,7 +155,7 @@ BenchmarkRunner::getRunnableConfiguration( const SnippetRepetitor &Repetitor) const { RunnableConfiguration RC; - InstructionBenchmark &InstrBenchmark = RC.InstrBenchmark; + Benchmark &InstrBenchmark = RC.InstrBenchmark; InstrBenchmark.Mode = Mode; InstrBenchmark.CpuName = std::string(State.getTargetMachine().getTargetCPU()); InstrBenchmark.LLVMTriple = @@ -196,10 +196,10 @@ BenchmarkRunner::getRunnableConfiguration( return std::move(RC); } -Expected +Expected BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC, bool DumpObjectToDisk) const { - InstructionBenchmark &InstrBenchmark = RC.InstrBenchmark; + Benchmark &InstrBenchmark = RC.InstrBenchmark; object::OwningBinary &ObjectFile = RC.ObjectFile; if (DumpObjectToDisk && diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h index ea60eee..a74f347 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -35,7 +35,7 @@ namespace exegesis { class BenchmarkRunner { public: explicit BenchmarkRunner(const LLVMState &State, - InstructionBenchmark::ModeE Mode, + Benchmark::ModeE Mode, BenchmarkPhaseSelectorE BenchmarkPhaseSelector); virtual ~BenchmarkRunner(); @@ -54,7 +54,7 @@ public: private: RunnableConfiguration() = default; - InstructionBenchmark InstrBenchmark; + Benchmark InstrBenchmark; object::OwningBinary ObjectFile; }; @@ -63,7 +63,7 @@ public: unsigned NumRepetitions, unsigned LoopUnrollFactor, const SnippetRepetitor &Repetitor) const; - Expected runConfiguration(RunnableConfiguration &&RC, + Expected runConfiguration(RunnableConfiguration &&RC, bool DumpObjectToDisk) const; // Scratch space to run instructions that touch memory. @@ -97,7 +97,7 @@ public: protected: const LLVMState &State; - const InstructionBenchmark::ModeE Mode; + const Benchmark::ModeE Mode; const BenchmarkPhaseSelectorE BenchmarkPhaseSelector; private: diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.cpp b/llvm/tools/llvm-exegesis/lib/Clustering.cpp index f91d6fc..c702462 100644 --- a/llvm/tools/llvm-exegesis/lib/Clustering.cpp +++ b/llvm/tools/llvm-exegesis/lib/Clustering.cpp @@ -39,7 +39,7 @@ namespace exegesis { // Finds the points at distance less than sqrt(EpsilonSquared) of Q (not // including Q). -void InstructionBenchmarkClustering::rangeQuery( +void BenchmarkClustering::rangeQuery( const size_t Q, std::vector &Neighbors) const { Neighbors.clear(); Neighbors.reserve(Points_.size() - 1); // The Q itself isn't a neighbor. @@ -59,7 +59,7 @@ void InstructionBenchmarkClustering::rangeQuery( // Given a set of points, checks that all the points are neighbours // up to AnalysisClusteringEpsilon. This is O(2*N). -bool InstructionBenchmarkClustering::areAllNeighbours( +bool BenchmarkClustering::areAllNeighbours( ArrayRef Pts) const { // First, get the centroid of this group of points. This is O(N). SchedClassClusterCentroid G; @@ -88,14 +88,14 @@ bool InstructionBenchmarkClustering::areAllNeighbours( }); } -InstructionBenchmarkClustering::InstructionBenchmarkClustering( - const std::vector &Points, +BenchmarkClustering::BenchmarkClustering( + const std::vector &Points, const double AnalysisClusteringEpsilonSquared) : Points_(Points), AnalysisClusteringEpsilonSquared_(AnalysisClusteringEpsilonSquared), NoiseCluster_(ClusterId::noise()), ErrorCluster_(ClusterId::error()) {} -Error InstructionBenchmarkClustering::validateAndSetup() { +Error BenchmarkClustering::validateAndSetup() { ClusterIdForPoint_.resize(Points_.size()); // Mark erroneous measurements out. // All points must have the same number of dimensions, in the same order. @@ -128,7 +128,7 @@ Error InstructionBenchmarkClustering::validateAndSetup() { return Error::success(); } -void InstructionBenchmarkClustering::clusterizeDbScan(const size_t MinPts) { +void BenchmarkClustering::clusterizeDbScan(const size_t MinPts) { std::vector Neighbors; // Persistent buffer to avoid allocs. for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) { if (!ClusterIdForPoint_[P].isUndef()) @@ -185,7 +185,7 @@ void InstructionBenchmarkClustering::clusterizeDbScan(const size_t MinPts) { } } -void InstructionBenchmarkClustering::clusterizeNaive( +void BenchmarkClustering::clusterizeNaive( const MCSubtargetInfo &SubtargetInfo, const MCInstrInfo &InstrInfo) { // Given an instruction Opcode, which sched class id's are represented, // and which are the benchmarks for each sched class? @@ -195,7 +195,7 @@ void InstructionBenchmarkClustering::clusterizeNaive( OpcodeToSchedClassesToPoints.resize(NumOpcodes); size_t NumClusters = 0; for (size_t P = 0, NumPoints = Points_.size(); P < NumPoints; ++P) { - const InstructionBenchmark &Point = Points_[P]; + const Benchmark &Point = Points_[P]; const MCInst &MCI = Point.keyInstruction(); unsigned SchedClassId; std::tie(SchedClassId, std::ignore) = @@ -249,11 +249,11 @@ void InstructionBenchmarkClustering::clusterizeNaive( // clustered into *different* clusters. This is not great for further analysis. // We shall find every opcode with benchmarks not in just one cluster, and move // *all* the benchmarks of said Opcode into one new unstable cluster per Opcode. -void InstructionBenchmarkClustering::stabilize(unsigned NumOpcodes) { +void BenchmarkClustering::stabilize(unsigned NumOpcodes) { // Given an instruction Opcode and Config, in which clusters do benchmarks of // this instruction lie? Normally, they all should be in the same cluster. struct OpcodeAndConfig { - explicit OpcodeAndConfig(const InstructionBenchmark &IB) + explicit OpcodeAndConfig(const Benchmark &IB) : Opcode(IB.keyInstruction().getOpcode()), Config(&IB.Key.Config) {} unsigned Opcode; const std::string *Config; @@ -327,11 +327,11 @@ void InstructionBenchmarkClustering::stabilize(unsigned NumOpcodes) { } } -Expected InstructionBenchmarkClustering::create( - const std::vector &Points, const ModeE Mode, +Expected BenchmarkClustering::create( + const std::vector &Points, const ModeE Mode, const size_t DbscanMinPts, const double AnalysisClusteringEpsilon, const MCSubtargetInfo *SubtargetInfo, const MCInstrInfo *InstrInfo) { - InstructionBenchmarkClustering Clustering( + BenchmarkClustering Clustering( Points, AnalysisClusteringEpsilon * AnalysisClusteringEpsilon); if (auto Error = Clustering.validateAndSetup()) { return std::move(Error); @@ -373,10 +373,10 @@ std::vector SchedClassClusterCentroid::getAsPoint() const { } bool SchedClassClusterCentroid::validate( - InstructionBenchmark::ModeE Mode) const { + Benchmark::ModeE Mode) const { size_t NumMeasurements = Representative.size(); switch (Mode) { - case InstructionBenchmark::Latency: + case Benchmark::Latency: if (NumMeasurements != 1) { errs() << "invalid number of measurements in latency mode: expected 1, got " @@ -384,10 +384,10 @@ bool SchedClassClusterCentroid::validate( return false; } break; - case InstructionBenchmark::Uops: + case Benchmark::Uops: // Can have many measurements. break; - case InstructionBenchmark::InverseThroughput: + case Benchmark::InverseThroughput: if (NumMeasurements != 1) { errs() << "invalid number of measurements in inverse throughput " "mode: expected 1, got " diff --git a/llvm/tools/llvm-exegesis/lib/Clustering.h b/llvm/tools/llvm-exegesis/lib/Clustering.h index 8d8570b..9d6c110 100644 --- a/llvm/tools/llvm-exegesis/lib/Clustering.h +++ b/llvm/tools/llvm-exegesis/lib/Clustering.h @@ -22,14 +22,14 @@ namespace llvm { namespace exegesis { -class InstructionBenchmarkClustering { +class BenchmarkClustering { public: enum ModeE { Dbscan, Naive }; // Clusters `Points` using DBSCAN with the given parameters. See the cc file // for more explanations on the algorithm. - static Expected - create(const std::vector &Points, ModeE Mode, + static Expected + create(const std::vector &Points, ModeE Mode, size_t DbscanMinPts, double AnalysisClusteringEpsilon, const MCSubtargetInfo *SubtargetInfo = nullptr, const MCInstrInfo *InstrInfo = nullptr); @@ -91,7 +91,7 @@ public: return ClusterIdForPoint_[P]; } - const std::vector &getPoints() const { return Points_; } + const std::vector &getPoints() const { return Points_; } const Cluster &getCluster(ClusterId Id) const { assert(!Id.isUndef() && "unlabeled cluster"); @@ -119,8 +119,8 @@ public: } private: - InstructionBenchmarkClustering( - const std::vector &Points, + BenchmarkClustering( + const std::vector &Points, double AnalysisClusteringEpsilonSquared); Error validateAndSetup(); @@ -136,7 +136,7 @@ private: bool areAllNeighbours(ArrayRef Pts) const; - const std::vector &Points_; + const std::vector &Points_; const double AnalysisClusteringEpsilonSquared_; int NumDimensions_ = 0; @@ -157,7 +157,7 @@ public: void addPoint(ArrayRef Point); - bool validate(InstructionBenchmark::ModeE Mode) const; + bool validate(Benchmark::ModeE Mode) const; private: // Measurement stats for the points in the SchedClassCluster. diff --git a/llvm/tools/llvm-exegesis/lib/CodeTemplate.h b/llvm/tools/llvm-exegesis/lib/CodeTemplate.h index 16982f9..7aca224 100644 --- a/llvm/tools/llvm-exegesis/lib/CodeTemplate.h +++ b/llvm/tools/llvm-exegesis/lib/CodeTemplate.h @@ -123,7 +123,7 @@ struct CodeTemplate { CodeTemplate clone() const; ExecutionMode Execution = ExecutionMode::UNKNOWN; - // See InstructionBenchmarkKey.::Config. + // See BenchmarkKey.::Config. std::string Config; // Some information about how this template has been created. std::string Info; diff --git a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp index d57ee14..18c0671 100644 --- a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.cpp @@ -19,12 +19,12 @@ namespace llvm { namespace exegesis { LatencyBenchmarkRunner::LatencyBenchmarkRunner( - const LLVMState &State, InstructionBenchmark::ModeE Mode, + const LLVMState &State, Benchmark::ModeE Mode, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE ResultAgg) + Benchmark::ResultAggregationModeE ResultAgg) : BenchmarkRunner(State, Mode, BenchmarkPhaseSelector) { - assert((Mode == InstructionBenchmark::Latency || - Mode == InstructionBenchmark::InverseThroughput) && + assert((Mode == Benchmark::Latency || + Mode == Benchmark::InverseThroughput) && "invalid mode"); ResultAggMode = ResultAgg; } @@ -94,10 +94,10 @@ Expected> LatencyBenchmarkRunner::runMeasurements( std::string ModeName; switch (Mode) { - case InstructionBenchmark::Latency: + case Benchmark::Latency: ModeName = "latency"; break; - case InstructionBenchmark::InverseThroughput: + case Benchmark::InverseThroughput: ModeName = "inverse_throughput"; break; default: @@ -105,7 +105,7 @@ Expected> LatencyBenchmarkRunner::runMeasurements( } switch (ResultAggMode) { - case InstructionBenchmark::MinVariance: { + case Benchmark::MinVariance: { if (ValuesCount == 1) llvm::errs() << "Each sample only has one value. result-aggregation-mode " "of min-variance is probably non-sensical\n"; @@ -115,19 +115,19 @@ Expected> LatencyBenchmarkRunner::runMeasurements( Result.push_back(BenchmarkMeasure::Create(ModeName, Value)); return std::move(Result); } - case InstructionBenchmark::Min: { + case Benchmark::Min: { std::vector Result; Result.push_back( BenchmarkMeasure::Create(ModeName, findMin(AccumulatedValues))); return std::move(Result); } - case InstructionBenchmark::Max: { + case Benchmark::Max: { std::vector Result; Result.push_back( BenchmarkMeasure::Create(ModeName, findMax(AccumulatedValues))); return std::move(Result); } - case InstructionBenchmark::Mean: { + case Benchmark::Mean: { std::vector Result; Result.push_back( BenchmarkMeasure::Create(ModeName, findMean(AccumulatedValues))); diff --git a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h index d7d1fa9..cd06d00 100644 --- a/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/LatencyBenchmarkRunner.h @@ -22,16 +22,16 @@ namespace exegesis { class LatencyBenchmarkRunner : public BenchmarkRunner { public: LatencyBenchmarkRunner( - const LLVMState &State, InstructionBenchmark::ModeE Mode, + const LLVMState &State, Benchmark::ModeE Mode, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE ResultAggMode); + Benchmark::ResultAggregationModeE ResultAggMode); ~LatencyBenchmarkRunner() override; private: Expected> runMeasurements(const FunctionExecutor &Executor) const override; - InstructionBenchmark::ResultAggregationModeE ResultAggMode; + Benchmark::ResultAggregationModeE ResultAggMode; }; } // namespace exegesis } // namespace llvm diff --git a/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp b/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp index 6ed327f..bd4e542 100644 --- a/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp +++ b/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp @@ -280,13 +280,13 @@ static unsigned findProcResIdx(const MCSubtargetInfo &STI, } std::vector ResolvedSchedClass::getAsPoint( - InstructionBenchmark::ModeE Mode, const MCSubtargetInfo &STI, + Benchmark::ModeE Mode, const MCSubtargetInfo &STI, ArrayRef Representative) const { const size_t NumMeasurements = Representative.size(); std::vector SchedClassPoint(NumMeasurements); - if (Mode == InstructionBenchmark::Latency) { + if (Mode == Benchmark::Latency) { assert(NumMeasurements == 1 && "Latency is a single measure."); BenchmarkMeasure &LatencyMeasure = SchedClassPoint[0]; @@ -299,7 +299,7 @@ std::vector ResolvedSchedClass::getAsPoint( LatencyMeasure.PerInstructionValue = std::max(LatencyMeasure.PerInstructionValue, WLE->Cycles); } - } else if (Mode == InstructionBenchmark::Uops) { + } else if (Mode == Benchmark::Uops) { for (auto I : zip(SchedClassPoint, Representative)) { BenchmarkMeasure &Measure = std::get<0>(I); const PerInstructionStats &Stats = std::get<1>(I); @@ -326,7 +326,7 @@ std::vector ResolvedSchedClass::getAsPoint( return {}; } } - } else if (Mode == InstructionBenchmark::InverseThroughput) { + } else if (Mode == Benchmark::InverseThroughput) { assert(NumMeasurements == 1 && "Inverse Throughput is a single measure."); BenchmarkMeasure &RThroughputMeasure = SchedClassPoint[0]; diff --git a/llvm/tools/llvm-exegesis/lib/SchedClassResolution.h b/llvm/tools/llvm-exegesis/lib/SchedClassResolution.h index 3c7d8b3..2347449 100644 --- a/llvm/tools/llvm-exegesis/lib/SchedClassResolution.h +++ b/llvm/tools/llvm-exegesis/lib/SchedClassResolution.h @@ -45,7 +45,7 @@ struct ResolvedSchedClass { const MCInstrInfo &InstrInfo, const MCInst &MCI); std::vector - getAsPoint(InstructionBenchmark::ModeE Mode, const MCSubtargetInfo &STI, + getAsPoint(Benchmark::ModeE Mode, const MCSubtargetInfo &STI, ArrayRef Representative) const; const unsigned SchedClassId; diff --git a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp index bf05131..7112d32 100644 --- a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp @@ -131,14 +131,14 @@ private: SnippetRepetitor::~SnippetRepetitor() {} std::unique_ptr -SnippetRepetitor::Create(InstructionBenchmark::RepetitionModeE Mode, +SnippetRepetitor::Create(Benchmark::RepetitionModeE Mode, const LLVMState &State) { switch (Mode) { - case InstructionBenchmark::Duplicate: + case Benchmark::Duplicate: return std::make_unique(State); - case InstructionBenchmark::Loop: + case Benchmark::Loop: return std::make_unique(State); - case InstructionBenchmark::AggregateMin: + case Benchmark::AggregateMin: break; } llvm_unreachable("Unknown RepetitionModeE enum"); diff --git a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.h b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.h index 239fa25..6f70633 100644 --- a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.h +++ b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.h @@ -29,7 +29,7 @@ namespace exegesis { class SnippetRepetitor { public: static std::unique_ptr - Create(InstructionBenchmark::RepetitionModeE Mode, const LLVMState &State); + Create(Benchmark::RepetitionModeE Mode, const LLVMState &State); virtual ~SnippetRepetitor(); diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp index f12444a..4717f9f 100644 --- a/llvm/tools/llvm-exegesis/lib/Target.cpp +++ b/llvm/tools/llvm-exegesis/lib/Target.cpp @@ -57,15 +57,15 @@ void ExegesisTarget::registerTarget(ExegesisTarget *Target) { } std::unique_ptr ExegesisTarget::createSnippetGenerator( - InstructionBenchmark::ModeE Mode, const LLVMState &State, + Benchmark::ModeE Mode, const LLVMState &State, const SnippetGenerator::Options &Opts) const { switch (Mode) { - case InstructionBenchmark::Unknown: + case Benchmark::Unknown: return nullptr; - case InstructionBenchmark::Latency: + case Benchmark::Latency: return createSerialSnippetGenerator(State, Opts); - case InstructionBenchmark::Uops: - case InstructionBenchmark::InverseThroughput: + case Benchmark::Uops: + case Benchmark::InverseThroughput: return createParallelSnippetGenerator(State, Opts); } return nullptr; @@ -73,18 +73,18 @@ std::unique_ptr ExegesisTarget::createSnippetGenerator( Expected> ExegesisTarget::createBenchmarkRunner( - InstructionBenchmark::ModeE Mode, const LLVMState &State, + Benchmark::ModeE Mode, const LLVMState &State, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE ResultAggMode) const { + Benchmark::ResultAggregationModeE ResultAggMode) const { PfmCountersInfo PfmCounters = State.getPfmCounters(); switch (Mode) { - case InstructionBenchmark::Unknown: + case Benchmark::Unknown: return nullptr; - case InstructionBenchmark::Latency: - case InstructionBenchmark::InverseThroughput: + case Benchmark::Latency: + case Benchmark::InverseThroughput: if (BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::Measure && !PfmCounters.CycleCounter) { - const char *ModeName = Mode == InstructionBenchmark::Latency + const char *ModeName = Mode == Benchmark::Latency ? "latency" : "inverse_throughput"; return make_error( @@ -97,7 +97,7 @@ ExegesisTarget::createBenchmarkRunner( } return createLatencyBenchmarkRunner(State, Mode, BenchmarkPhaseSelector, ResultAggMode); - case InstructionBenchmark::Uops: + case Benchmark::Uops: if (BenchmarkPhaseSelector == BenchmarkPhaseSelectorE::Measure && !PfmCounters.UopsCounter && !PfmCounters.IssueCounters) return make_error( @@ -121,16 +121,16 @@ std::unique_ptr ExegesisTarget::createParallelSnippetGenerator } std::unique_ptr ExegesisTarget::createLatencyBenchmarkRunner( - const LLVMState &State, InstructionBenchmark::ModeE Mode, + const LLVMState &State, Benchmark::ModeE Mode, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE ResultAggMode) const { + Benchmark::ResultAggregationModeE ResultAggMode) const { return std::make_unique( State, Mode, BenchmarkPhaseSelector, ResultAggMode); } std::unique_ptr ExegesisTarget::createUopsBenchmarkRunner( const LLVMState &State, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE /*unused*/) const { + Benchmark::ResultAggregationModeE /*unused*/) const { return std::make_unique(State, BenchmarkPhaseSelector); } diff --git a/llvm/tools/llvm-exegesis/lib/Target.h b/llvm/tools/llvm-exegesis/lib/Target.h index 7669b6c..9f21122 100644 --- a/llvm/tools/llvm-exegesis/lib/Target.h +++ b/llvm/tools/llvm-exegesis/lib/Target.h @@ -154,15 +154,15 @@ public: // Creates a snippet generator for the given mode. std::unique_ptr - createSnippetGenerator(InstructionBenchmark::ModeE Mode, + createSnippetGenerator(Benchmark::ModeE Mode, const LLVMState &State, const SnippetGenerator::Options &Opts) const; // Creates a benchmark runner for the given mode. Expected> createBenchmarkRunner( - InstructionBenchmark::ModeE Mode, const LLVMState &State, + Benchmark::ModeE Mode, const LLVMState &State, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE ResultAggMode = - InstructionBenchmark::Min) const; + Benchmark::ResultAggregationModeE ResultAggMode = + Benchmark::Min) const; // Returns the ExegesisTarget for the given triple or nullptr if the target // does not exist. @@ -198,12 +198,12 @@ private: std::unique_ptr virtual createParallelSnippetGenerator( const LLVMState &State, const SnippetGenerator::Options &Opts) const; std::unique_ptr virtual createLatencyBenchmarkRunner( - const LLVMState &State, InstructionBenchmark::ModeE Mode, + const LLVMState &State, Benchmark::ModeE Mode, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE ResultAggMode) const; + Benchmark::ResultAggregationModeE ResultAggMode) const; std::unique_ptr virtual createUopsBenchmarkRunner( const LLVMState &State, BenchmarkPhaseSelectorE BenchmarkPhaseSelector, - InstructionBenchmark::ResultAggregationModeE ResultAggMode) const; + Benchmark::ResultAggregationModeE ResultAggMode) const; const ExegesisTarget *Next = nullptr; const ArrayRef CpuPfmCounters; diff --git a/llvm/tools/llvm-exegesis/lib/UopsBenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/UopsBenchmarkRunner.h index c726944..e08eaa7 100644 --- a/llvm/tools/llvm-exegesis/lib/UopsBenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/UopsBenchmarkRunner.h @@ -23,7 +23,7 @@ class UopsBenchmarkRunner : public BenchmarkRunner { public: UopsBenchmarkRunner(const LLVMState &State, BenchmarkPhaseSelectorE BenchmarkPhaseSelector) - : BenchmarkRunner(State, InstructionBenchmark::Uops, + : BenchmarkRunner(State, Benchmark::Uops, BenchmarkPhaseSelector) {} ~UopsBenchmarkRunner() override; diff --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp index 4e260e0..06ae924 100644 --- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp +++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp @@ -69,47 +69,47 @@ static cl::opt "results. “-” uses stdin/stdout."), cl::cat(Options), cl::init("")); -static cl::opt BenchmarkMode( +static cl::opt BenchmarkMode( "mode", cl::desc("the mode to run"), cl::cat(Options), - cl::values(clEnumValN(exegesis::InstructionBenchmark::Latency, "latency", + cl::values(clEnumValN(exegesis::Benchmark::Latency, "latency", "Instruction Latency"), - clEnumValN(exegesis::InstructionBenchmark::InverseThroughput, + clEnumValN(exegesis::Benchmark::InverseThroughput, "inverse_throughput", "Instruction Inverse Throughput"), - clEnumValN(exegesis::InstructionBenchmark::Uops, "uops", + clEnumValN(exegesis::Benchmark::Uops, "uops", "Uop Decomposition"), // When not asking for a specific benchmark mode, // we'll analyse the results. - clEnumValN(exegesis::InstructionBenchmark::Unknown, "analysis", + clEnumValN(exegesis::Benchmark::Unknown, "analysis", "Analysis"))); -static cl::opt +static cl::opt ResultAggMode( "result-aggregation-mode", cl::desc("How to aggregate multi-values result"), cl::cat(BenchmarkOptions), - cl::values(clEnumValN(exegesis::InstructionBenchmark::Min, "min", + cl::values(clEnumValN(exegesis::Benchmark::Min, "min", "Keep min reading"), - clEnumValN(exegesis::InstructionBenchmark::Max, "max", + clEnumValN(exegesis::Benchmark::Max, "max", "Keep max reading"), - clEnumValN(exegesis::InstructionBenchmark::Mean, "mean", + clEnumValN(exegesis::Benchmark::Mean, "mean", "Compute mean of all readings"), - clEnumValN(exegesis::InstructionBenchmark::MinVariance, + clEnumValN(exegesis::Benchmark::MinVariance, "min-variance", "Keep readings set with min-variance")), - cl::init(exegesis::InstructionBenchmark::Min)); + cl::init(exegesis::Benchmark::Min)); -static cl::opt RepetitionMode( +static cl::opt RepetitionMode( "repetition-mode", cl::desc("how to repeat the instruction snippet"), cl::cat(BenchmarkOptions), cl::values( - clEnumValN(exegesis::InstructionBenchmark::Duplicate, "duplicate", + clEnumValN(exegesis::Benchmark::Duplicate, "duplicate", "Duplicate the snippet"), - clEnumValN(exegesis::InstructionBenchmark::Loop, "loop", + clEnumValN(exegesis::Benchmark::Loop, "loop", "Loop over the snippet"), - clEnumValN(exegesis::InstructionBenchmark::AggregateMin, "min", + clEnumValN(exegesis::Benchmark::AggregateMin, "min", "All of the above and take the minimum of measurements")), - cl::init(exegesis::InstructionBenchmark::Duplicate)); + cl::init(exegesis::Benchmark::Duplicate)); static cl::opt BenchmarkMeasurementsPrintProgress( "measurements-print-progress", @@ -163,27 +163,27 @@ static cl::opt IgnoreInvalidSchedClass( cl::desc("ignore instructions that do not define a sched class"), cl::cat(BenchmarkOptions), cl::init(false)); -static cl::opt AnalysisSnippetFilter( +static cl::opt AnalysisSnippetFilter( "analysis-filter", cl::desc("Filter the benchmarks before analysing them"), cl::cat(BenchmarkOptions), cl::values( - clEnumValN(exegesis::InstructionBenchmarkFilter::All, "all", + clEnumValN(exegesis::BenchmarkFilter::All, "all", "Keep all benchmarks (default)"), - clEnumValN(exegesis::InstructionBenchmarkFilter::RegOnly, "reg-only", + clEnumValN(exegesis::BenchmarkFilter::RegOnly, "reg-only", "Keep only those benchmarks that do *NOT* involve memory"), - clEnumValN(exegesis::InstructionBenchmarkFilter::WithMem, "mem-only", + clEnumValN(exegesis::BenchmarkFilter::WithMem, "mem-only", "Keep only the benchmarks that *DO* involve memory")), - cl::init(exegesis::InstructionBenchmarkFilter::All)); + cl::init(exegesis::BenchmarkFilter::All)); -static cl::opt +static cl::opt AnalysisClusteringAlgorithm( "analysis-clustering", cl::desc("the clustering algorithm to use"), cl::cat(AnalysisOptions), - cl::values(clEnumValN(exegesis::InstructionBenchmarkClustering::Dbscan, + cl::values(clEnumValN(exegesis::BenchmarkClustering::Dbscan, "dbscan", "use DBSCAN/OPTICS algorithm"), - clEnumValN(exegesis::InstructionBenchmarkClustering::Naive, + clEnumValN(exegesis::BenchmarkClustering::Naive, "naive", "one cluster per opcode")), - cl::init(exegesis::InstructionBenchmarkClustering::Dbscan)); + cl::init(exegesis::BenchmarkClustering::Dbscan)); static cl::opt AnalysisDbscanNumPoints( "analysis-numpoints", @@ -369,7 +369,7 @@ static void runBenchmarkConfigurations( Meter.emplace(Configurations.size()); for (const BenchmarkCode &Conf : Configurations) { ProgressMeter<>::ProgressMeterStep MeterStep(Meter ? &*Meter : nullptr); - SmallVector AllResults; + SmallVector AllResults; for (const std::unique_ptr &Repetitor : Repetitors) { @@ -378,18 +378,18 @@ static void runBenchmarkConfigurations( AllResults.emplace_back( ExitOnErr(Runner.runConfiguration(std::move(RC), DumpObjectToDisk))); } - InstructionBenchmark &Result = AllResults.front(); + Benchmark &Result = AllResults.front(); // If any of our measurements failed, pretend they all have failed. if (AllResults.size() > 1 && - any_of(AllResults, [](const InstructionBenchmark &R) { + any_of(AllResults, [](const Benchmark &R) { return R.Measurements.empty(); })) Result.Measurements.clear(); - if (RepetitionMode == InstructionBenchmark::RepetitionModeE::AggregateMin) { - for (const InstructionBenchmark &OtherResult : - ArrayRef(AllResults).drop_front()) { + if (RepetitionMode == Benchmark::RepetitionModeE::AggregateMin) { + for (const Benchmark &OtherResult : + ArrayRef(AllResults).drop_front()) { llvm::append_range(Result.AssembledSnippet, OtherResult.AssembledSnippet); // Aggregate measurements, but only iff all measurements succeeded. @@ -449,12 +449,12 @@ void benchmarkMain() { const auto Opcodes = getOpcodesOrDie(State); SmallVector, 2> Repetitors; - if (RepetitionMode != InstructionBenchmark::RepetitionModeE::AggregateMin) + if (RepetitionMode != Benchmark::RepetitionModeE::AggregateMin) Repetitors.emplace_back(SnippetRepetitor::Create(RepetitionMode, State)); else { - for (InstructionBenchmark::RepetitionModeE RepMode : - {InstructionBenchmark::RepetitionModeE::Duplicate, - InstructionBenchmark::RepetitionModeE::Loop}) + for (Benchmark::RepetitionModeE RepMode : + {Benchmark::RepetitionModeE::Duplicate, + Benchmark::RepetitionModeE::Loop}) Repetitors.emplace_back(SnippetRepetitor::Create(RepMode, State)); } @@ -526,14 +526,14 @@ static void maybeRunAnalysis(const Analysis &Analyzer, const std::string &Name, ExitOnFileError(OutputFilename, std::move(Err)); } -static void filterPoints(MutableArrayRef Points, +static void filterPoints(MutableArrayRef Points, const MCInstrInfo &MCII) { - if (AnalysisSnippetFilter == exegesis::InstructionBenchmarkFilter::All) + if (AnalysisSnippetFilter == exegesis::BenchmarkFilter::All) return; bool WantPointsWithMemOps = - AnalysisSnippetFilter == exegesis::InstructionBenchmarkFilter::WithMem; - for (InstructionBenchmark &Point : Points) { + AnalysisSnippetFilter == exegesis::BenchmarkFilter::WithMem; + for (Benchmark &Point : Points) { if (!Point.Error.empty()) continue; if (WantPointsWithMemOps == @@ -568,7 +568,7 @@ static void analysisMain() { const auto TriplesAndCpus = ExitOnFileError( BenchmarkFile, - InstructionBenchmark::readTriplesAndCpusFromYamls(*MemoryBuffer)); + Benchmark::readTriplesAndCpusFromYamls(*MemoryBuffer)); if (TriplesAndCpus.empty()) { errs() << "no benchmarks to analyze\n"; return; @@ -591,8 +591,8 @@ static void analysisMain() { // Read benchmarks. const LLVMState State = ExitOnErr( LLVMState::Create(TripleAndCpu.LLVMTriple, TripleAndCpu.CpuName)); - std::vector Points = ExitOnFileError( - BenchmarkFile, InstructionBenchmark::readYamls(State, *MemoryBuffer)); + std::vector Points = ExitOnFileError( + BenchmarkFile, Benchmark::readYamls(State, *MemoryBuffer)); outs() << "Parsed " << Points.size() << " benchmark points\n"; if (Points.empty()) { @@ -603,7 +603,7 @@ static void analysisMain() { filterPoints(Points, State.getInstrInfo()); - const auto Clustering = ExitOnErr(InstructionBenchmarkClustering::create( + const auto Clustering = ExitOnErr(BenchmarkClustering::create( Points, AnalysisClusteringAlgorithm, AnalysisDbscanNumPoints, AnalysisClusteringEpsilon, &State.getSubtargetInfo(), &State.getInstrInfo())); @@ -651,7 +651,7 @@ int main(int Argc, char **Argv) { return EXIT_FAILURE; }); - if (exegesis::BenchmarkMode == exegesis::InstructionBenchmark::Unknown) { + if (exegesis::BenchmarkMode == exegesis::Benchmark::Unknown) { exegesis::analysisMain(); } else { exegesis::benchmarkMain(); diff --git a/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp b/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp index b23938a..25fe813 100644 --- a/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp @@ -23,12 +23,12 @@ using testing::UnorderedElementsAre; using testing::UnorderedElementsAreArray; static const auto HasPoints = [](const std::vector &Indices) { - return Field(&InstructionBenchmarkClustering::Cluster::PointIndices, + return Field(&BenchmarkClustering::Cluster::PointIndices, UnorderedElementsAreArray(Indices)); }; TEST(ClusteringTest, Clusters3D) { - std::vector Points(6); + std::vector Points(6); // Cluster around (x=0, y=1, z=2): points {0, 3}. Points[0].Measurements = { @@ -46,22 +46,22 @@ TEST(ClusteringTest, Clusters3D) { // Error cluster: points {2} Points[2].Error = "oops"; - auto Clustering = InstructionBenchmarkClustering::create( - Points, InstructionBenchmarkClustering::ModeE::Dbscan, 2, 0.25); + auto Clustering = BenchmarkClustering::create( + Points, BenchmarkClustering::ModeE::Dbscan, 2, 0.25); ASSERT_TRUE((bool)Clustering); EXPECT_THAT(Clustering.get().getValidClusters(), UnorderedElementsAre(HasPoints({0, 3}), HasPoints({1, 4}))); EXPECT_THAT(Clustering.get().getCluster( - InstructionBenchmarkClustering::ClusterId::noise()), + BenchmarkClustering::ClusterId::noise()), HasPoints({5})); EXPECT_THAT(Clustering.get().getCluster( - InstructionBenchmarkClustering::ClusterId::error()), + BenchmarkClustering::ClusterId::error()), HasPoints({2})); EXPECT_EQ(Clustering.get().getClusterIdForPoint(2), - InstructionBenchmarkClustering::ClusterId::error()); + BenchmarkClustering::ClusterId::error()); EXPECT_EQ(Clustering.get().getClusterIdForPoint(5), - InstructionBenchmarkClustering::ClusterId::noise()); + BenchmarkClustering::ClusterId::noise()); EXPECT_EQ(Clustering.get().getClusterIdForPoint(0), Clustering.get().getClusterIdForPoint(3)); EXPECT_EQ(Clustering.get().getClusterIdForPoint(1), @@ -69,46 +69,46 @@ TEST(ClusteringTest, Clusters3D) { } TEST(ClusteringTest, Clusters3D_InvalidSize) { - std::vector Points(6); + std::vector Points(6); Points[0].Measurements = { {"x", 0.01, 0.0}, {"y", 1.02, 0.0}, {"z", 1.98, 0.0}}; Points[1].Measurements = {{"y", 1.02, 0.0}, {"z", 1.98, 0.0}}; auto Error = - InstructionBenchmarkClustering::create( - Points, InstructionBenchmarkClustering::ModeE::Dbscan, 2, 0.25) + BenchmarkClustering::create( + Points, BenchmarkClustering::ModeE::Dbscan, 2, 0.25) .takeError(); ASSERT_TRUE((bool)Error); consumeError(std::move(Error)); } TEST(ClusteringTest, Clusters3D_InvalidOrder) { - std::vector Points(6); + std::vector Points(6); Points[0].Measurements = {{"x", 0.01, 0.0}, {"y", 1.02, 0.0}}; Points[1].Measurements = {{"y", 1.02, 0.0}, {"x", 1.98, 0.0}}; auto Error = - InstructionBenchmarkClustering::create( - Points, InstructionBenchmarkClustering::ModeE::Dbscan, 2, 0.25) + BenchmarkClustering::create( + Points, BenchmarkClustering::ModeE::Dbscan, 2, 0.25) .takeError(); ASSERT_TRUE((bool)Error); consumeError(std::move(Error)); } TEST(ClusteringTest, Ordering) { - ASSERT_LT(InstructionBenchmarkClustering::ClusterId::makeValid(1), - InstructionBenchmarkClustering::ClusterId::makeValid(2)); + ASSERT_LT(BenchmarkClustering::ClusterId::makeValid(1), + BenchmarkClustering::ClusterId::makeValid(2)); - ASSERT_LT(InstructionBenchmarkClustering::ClusterId::makeValid(2), - InstructionBenchmarkClustering::ClusterId::noise()); + ASSERT_LT(BenchmarkClustering::ClusterId::makeValid(2), + BenchmarkClustering::ClusterId::noise()); - ASSERT_LT(InstructionBenchmarkClustering::ClusterId::makeValid(2), - InstructionBenchmarkClustering::ClusterId::error()); + ASSERT_LT(BenchmarkClustering::ClusterId::makeValid(2), + BenchmarkClustering::ClusterId::error()); - ASSERT_LT(InstructionBenchmarkClustering::ClusterId::noise(), - InstructionBenchmarkClustering::ClusterId::error()); + ASSERT_LT(BenchmarkClustering::ClusterId::noise(), + BenchmarkClustering::ClusterId::error()); } TEST(ClusteringTest, Ordering1) { - std::vector Points(3); + std::vector Points(3); Points[0].Measurements = { {"x", 0.0, 0.0}}; @@ -117,15 +117,15 @@ TEST(ClusteringTest, Ordering1) { Points[2].Measurements = { {"x", 2.0, 0.0}}; - auto Clustering = InstructionBenchmarkClustering::create( - Points, InstructionBenchmarkClustering::ModeE::Dbscan, 2, 1.1); + auto Clustering = BenchmarkClustering::create( + Points, BenchmarkClustering::ModeE::Dbscan, 2, 1.1); ASSERT_TRUE((bool)Clustering); EXPECT_THAT(Clustering.get().getValidClusters(), UnorderedElementsAre(HasPoints({0, 1, 2}))); } TEST(ClusteringTest, Ordering2) { - std::vector Points(3); + std::vector Points(3); Points[0].Measurements = { {"x", 0.0, 0.0}}; @@ -134,8 +134,8 @@ TEST(ClusteringTest, Ordering2) { Points[2].Measurements = { {"x", 1.0, 0.0}}; - auto Clustering = InstructionBenchmarkClustering::create( - Points, InstructionBenchmarkClustering::ModeE::Dbscan, 2, 1.1); + auto Clustering = BenchmarkClustering::create( + Points, BenchmarkClustering::ModeE::Dbscan, 2, 1.1); ASSERT_TRUE((bool)Clustering); EXPECT_THAT(Clustering.get().getValidClusters(), UnorderedElementsAre(HasPoints({0, 1, 2}))); diff --git a/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp b/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp index 575e53d..2b72453 100644 --- a/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/Mips/BenchmarkResultTest.cpp @@ -55,7 +55,7 @@ class MipsBenchmarkResultTest : public MipsTestBase {}; TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) { ExitOnError ExitOnErr; - InstructionBenchmark ToDisk; + Benchmark ToDisk; ToDisk.Key.Instructions.push_back(MCInstBuilder(Mips::XOR) .addReg(Mips::T0) @@ -65,7 +65,7 @@ TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) { ToDisk.Key.RegisterInitialValues = { RegisterValue{Mips::T1, APInt(8, "123", 10)}, RegisterValue{Mips::T2, APInt(8, "456", 10)}}; - ToDisk.Mode = InstructionBenchmark::Latency; + ToDisk.Mode = Benchmark::Latency; ToDisk.CpuName = "cpu_name"; ToDisk.LLVMTriple = "llvm_triple"; ToDisk.NumRepetitions = 1; @@ -94,7 +94,7 @@ TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) { { // One-element version. const auto FromDisk = - ExitOnErr(InstructionBenchmark::readYaml(State, *Buffer)); + ExitOnErr(Benchmark::readYaml(State, *Buffer)); EXPECT_THAT(FromDisk.Key.Instructions, Pointwise(EqMCInst(), ToDisk.Key.Instructions)); @@ -110,7 +110,7 @@ TEST_F(MipsBenchmarkResultTest, WriteToAndReadFromDisk) { { // Vector version. const auto FromDiskVector = - ExitOnErr(InstructionBenchmark::readYamls(State, *Buffer)); + ExitOnErr(Benchmark::readYamls(State, *Buffer)); ASSERT_EQ(FromDiskVector.size(), size_t{1}); const auto &FromDisk = FromDiskVector[0]; EXPECT_THAT(FromDisk.Key.Instructions, diff --git a/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp index bfee792..5423bfc 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp @@ -63,7 +63,7 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) { ExitOnError ExitOnErr; - InstructionBenchmark ToDisk; + Benchmark ToDisk; ToDisk.Key.Instructions.push_back(MCInstBuilder(X86::XOR32rr) .addReg(X86::AL) @@ -74,7 +74,7 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) { ToDisk.Key.RegisterInitialValues = { RegisterValue{X86::AL, APInt(8, "-1", 10)}, RegisterValue{X86::AH, APInt(8, "123", 10)}}; - ToDisk.Mode = InstructionBenchmark::Latency; + ToDisk.Mode = Benchmark::Latency; ToDisk.CpuName = "cpu_name"; ToDisk.LLVMTriple = "llvm_triple"; ToDisk.NumRepetitions = 1; @@ -106,19 +106,19 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) { { // Read Triples/Cpu only. const auto TriplesAndCpus = - ExitOnErr(InstructionBenchmark::readTriplesAndCpusFromYamls(*Buffer)); + ExitOnErr(Benchmark::readTriplesAndCpusFromYamls(*Buffer)); ASSERT_THAT(TriplesAndCpus, testing::ElementsAre( - AllOf(Field(&InstructionBenchmark::TripleAndCpu::LLVMTriple, + AllOf(Field(&Benchmark::TripleAndCpu::LLVMTriple, Eq("llvm_triple")), - Field(&InstructionBenchmark::TripleAndCpu::CpuName, + Field(&Benchmark::TripleAndCpu::CpuName, Eq("cpu_name"))))); } { // One-element version. const auto FromDisk = - ExitOnErr(InstructionBenchmark::readYaml(State, *Buffer)); + ExitOnErr(Benchmark::readYaml(State, *Buffer)); EXPECT_THAT(FromDisk.Key.Instructions, Pointwise(EqMCInst(), ToDisk.Key.Instructions)); @@ -134,7 +134,7 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) { { // Vector version. const auto FromDiskVector = - ExitOnErr(InstructionBenchmark::readYamls(State, *Buffer)); + ExitOnErr(Benchmark::readYamls(State, *Buffer)); ASSERT_EQ(FromDiskVector.size(), size_t{1}); const auto &FromDisk = FromDiskVector[0]; EXPECT_THAT(FromDisk.Key.Instructions, diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp index 91a271c..5173526 100644 --- a/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp @@ -38,7 +38,7 @@ protected: MF = &createVoidVoidPtrMachineFunction("TestFn", Mod.get(), MMI.get()); } - void TestCommon(InstructionBenchmark::RepetitionModeE RepetitionMode) { + void TestCommon(Benchmark::RepetitionModeE RepetitionMode) { const auto Repetitor = SnippetRepetitor::Create(RepetitionMode, State); const std::vector Instructions = {MCInstBuilder(X86::NOOP)}; FunctionFiller Sink(*MF, {X86::EAX}); @@ -66,7 +66,7 @@ static auto LiveReg = [](unsigned Reg) { }; TEST_F(X86SnippetRepetitorTest, Duplicate) { - TestCommon(InstructionBenchmark::Duplicate); + TestCommon(Benchmark::Duplicate); // Duplicating creates a single basic block that repeats the instructions. ASSERT_EQ(MF->getNumBlockIDs(), 1u); EXPECT_THAT(MF->getBlockNumbered(0)->instrs(), @@ -75,7 +75,7 @@ TEST_F(X86SnippetRepetitorTest, Duplicate) { } TEST_F(X86SnippetRepetitorTest, Loop) { - TestCommon(InstructionBenchmark::Loop); + TestCommon(Benchmark::Loop); // Duplicating creates an entry block, a loop body and a ret block. ASSERT_EQ(MF->getNumBlockIDs(), 3u); const auto &LoopBlock = *MF->getBlockNumbered(1);