Revert "Reland - [Offload] Introduce offload-tblgen and initial new API implementatio...
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / Analysis.h
blob16eccf6879c23442aa9ee33a091c5c5cfff0080f
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, raw_ostream &OS) const;
81 void printPointHtml(const Benchmark &Point, raw_ostream &OS) const;
83 void
84 printSchedClassClustersHtml(const std::vector<SchedClassCluster> &Clusters,
85 const ResolvedSchedClass &SC,
86 raw_ostream &OS) const;
87 void printSchedClassDescHtml(const ResolvedSchedClass &SC,
88 raw_ostream &OS) const;
90 // A pair of (Sched Class, indices of points that belong to the sched
91 // class).
92 struct ResolvedSchedClassAndPoints {
93 explicit ResolvedSchedClassAndPoints(ResolvedSchedClass &&RSC);
95 ResolvedSchedClass RSC;
96 std::vector<size_t> PointIds;
99 // Builds a list of ResolvedSchedClassAndPoints.
100 std::vector<ResolvedSchedClassAndPoints> makePointsPerSchedClass() const;
102 template <typename EscapeTag, EscapeTag Tag>
103 void writeSnippet(raw_ostream &OS, ArrayRef<uint8_t> Bytes,
104 const char *Separator) const;
106 const BenchmarkClustering &Clustering_;
107 const LLVMState &State_;
108 std::unique_ptr<DisassemblerHelper> DisasmHelper_;
109 const double AnalysisInconsistencyEpsilonSquared_;
110 const bool AnalysisDisplayUnstableOpcodes_;
113 } // namespace exegesis
114 } // namespace llvm
116 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H