[RISCV] Eliminate dead li after emitting VSETVLIs (#65934)
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / Analysis.h
blob4a85d45a2d56a624345944601079d473438bebf5
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>
27 namespace llvm {
28 namespace exegesis {
30 // A helper class to analyze benchmark results for a target.
31 class Analysis {
32 public:
33 Analysis(const LLVMState &State,
34 const BenchmarkClustering &Clustering,
35 double AnalysisInconsistencyEpsilon,
36 bool AnalysisDisplayUnstableOpcodes);
38 // Prints a csv of instructions for each cluster.
39 struct PrintClusters {};
40 // Find potential errors in the scheduling information given measurements.
41 struct PrintSchedClassInconsistencies {};
43 template <typename Pass> Error run(raw_ostream &OS) const;
45 private:
46 using ClusterId = BenchmarkClustering::ClusterId;
48 // Represents the intersection of a sched class and a cluster.
49 class SchedClassCluster {
50 public:
51 const BenchmarkClustering::ClusterId &id() const {
52 return ClusterId;
55 const std::vector<size_t> &getPointIds() const { return PointIds; }
57 void addPoint(size_t PointId,
58 const BenchmarkClustering &Clustering);
60 // Return the cluster centroid.
61 const SchedClassClusterCentroid &getCentroid() const { return Centroid; }
63 // Returns true if the cluster representative measurements match that of SC.
64 bool
65 measurementsMatch(const MCSubtargetInfo &STI, const ResolvedSchedClass &SC,
66 const BenchmarkClustering &Clustering,
67 const double AnalysisInconsistencyEpsilonSquared_) const;
69 private:
70 BenchmarkClustering::ClusterId ClusterId;
71 std::vector<size_t> PointIds;
72 // Measurement stats for the points in the SchedClassCluster.
73 SchedClassClusterCentroid Centroid;
76 void printInstructionRowCsv(size_t PointId, raw_ostream &OS) const;
78 void printClusterRawHtml(const BenchmarkClustering::ClusterId &Id,
79 StringRef display_name, llvm::raw_ostream &OS) const;
81 void printPointHtml(const Benchmark &Point,
82 llvm::raw_ostream &OS) const;
84 void
85 printSchedClassClustersHtml(const std::vector<SchedClassCluster> &Clusters,
86 const ResolvedSchedClass &SC,
87 raw_ostream &OS) const;
88 void printSchedClassDescHtml(const ResolvedSchedClass &SC,
89 raw_ostream &OS) const;
91 // A pair of (Sched Class, indices of points that belong to the sched
92 // class).
93 struct ResolvedSchedClassAndPoints {
94 explicit ResolvedSchedClassAndPoints(ResolvedSchedClass &&RSC);
96 ResolvedSchedClass RSC;
97 std::vector<size_t> PointIds;
100 // Builds a list of ResolvedSchedClassAndPoints.
101 std::vector<ResolvedSchedClassAndPoints> makePointsPerSchedClass() const;
103 template <typename EscapeTag, EscapeTag Tag>
104 void writeSnippet(raw_ostream &OS, ArrayRef<uint8_t> Bytes,
105 const char *Separator) const;
107 const BenchmarkClustering &Clustering_;
108 const LLVMState &State_;
109 std::unique_ptr<DisassemblerHelper> DisasmHelper_;
110 const double AnalysisInconsistencyEpsilonSquared_;
111 const bool AnalysisDisplayUnstableOpcodes_;
114 } // namespace exegesis
115 } // namespace llvm
117 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H