[llvm] Stop including unordered_map (NFC)
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / Analysis.h
blobfb9417b4d566ba543ea949a49bb3737e33bb2c38
1 //===-- Analysis.h ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Analysis output for benchmark results.
11 ///
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
15 #define LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
17 #include "Clustering.h"
18 #include "DisassemblerHelper.h"
19 #include "SchedClassResolution.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCObjectFileInfo.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/Support/Error.h"
24 #include "llvm/Support/raw_ostream.h"
25 #include <memory>
26 #include <set>
27 #include <string>
29 namespace llvm {
30 namespace exegesis {
32 // A helper class to analyze benchmark results for a target.
33 class Analysis {
34 public:
35 Analysis(const LLVMState &State,
36 const BenchmarkClustering &Clustering,
37 double AnalysisInconsistencyEpsilon,
38 bool AnalysisDisplayUnstableOpcodes);
40 // Prints a csv of instructions for each cluster.
41 struct PrintClusters {};
42 // Find potential errors in the scheduling information given measurements.
43 struct PrintSchedClassInconsistencies {};
45 template <typename Pass> Error run(raw_ostream &OS) const;
47 private:
48 using ClusterId = BenchmarkClustering::ClusterId;
50 // Represents the intersection of a sched class and a cluster.
51 class SchedClassCluster {
52 public:
53 const BenchmarkClustering::ClusterId &id() const {
54 return ClusterId;
57 const std::vector<size_t> &getPointIds() const { return PointIds; }
59 void addPoint(size_t PointId,
60 const BenchmarkClustering &Clustering);
62 // Return the cluster centroid.
63 const SchedClassClusterCentroid &getCentroid() const { return Centroid; }
65 // Returns true if the cluster representative measurements match that of SC.
66 bool
67 measurementsMatch(const MCSubtargetInfo &STI, const ResolvedSchedClass &SC,
68 const BenchmarkClustering &Clustering,
69 const double AnalysisInconsistencyEpsilonSquared_) const;
71 private:
72 BenchmarkClustering::ClusterId ClusterId;
73 std::vector<size_t> PointIds;
74 // Measurement stats for the points in the SchedClassCluster.
75 SchedClassClusterCentroid Centroid;
78 void printInstructionRowCsv(size_t PointId, raw_ostream &OS) const;
80 void printClusterRawHtml(const BenchmarkClustering::ClusterId &Id,
81 StringRef display_name, llvm::raw_ostream &OS) const;
83 void printPointHtml(const Benchmark &Point,
84 llvm::raw_ostream &OS) const;
86 void
87 printSchedClassClustersHtml(const std::vector<SchedClassCluster> &Clusters,
88 const ResolvedSchedClass &SC,
89 raw_ostream &OS) const;
90 void printSchedClassDescHtml(const ResolvedSchedClass &SC,
91 raw_ostream &OS) const;
93 // A pair of (Sched Class, indices of points that belong to the sched
94 // class).
95 struct ResolvedSchedClassAndPoints {
96 explicit ResolvedSchedClassAndPoints(ResolvedSchedClass &&RSC);
98 ResolvedSchedClass RSC;
99 std::vector<size_t> PointIds;
102 // Builds a list of ResolvedSchedClassAndPoints.
103 std::vector<ResolvedSchedClassAndPoints> makePointsPerSchedClass() const;
105 template <typename EscapeTag, EscapeTag Tag>
106 void writeSnippet(raw_ostream &OS, ArrayRef<uint8_t> Bytes,
107 const char *Separator) const;
109 const BenchmarkClustering &Clustering_;
110 const LLVMState &State_;
111 std::unique_ptr<DisassemblerHelper> DisasmHelper_;
112 const double AnalysisInconsistencyEpsilonSquared_;
113 const bool AnalysisDisplayUnstableOpcodes_;
116 } // namespace exegesis
117 } // namespace llvm
119 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H