147
|
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 //===----------------------------------------------------------------------===//
|
|
13
|
|
14 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
|
|
15 #define LLVM_TOOLS_LLVM_EXEGESIS_ANALYSIS_H
|
|
16
|
|
17 #include "Clustering.h"
|
|
18 #include "SchedClassResolution.h"
|
|
19 #include "llvm/MC/MCContext.h"
|
|
20 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
|
|
21 #include "llvm/MC/MCInstPrinter.h"
|
|
22 #include "llvm/MC/MCInstrInfo.h"
|
|
23 #include "llvm/MC/MCObjectFileInfo.h"
|
|
24 #include "llvm/MC/MCSubtargetInfo.h"
|
|
25 #include "llvm/Support/Error.h"
|
|
26 #include "llvm/Support/TargetRegistry.h"
|
|
27 #include "llvm/Support/raw_ostream.h"
|
|
28 #include <memory>
|
|
29 #include <set>
|
|
30 #include <string>
|
|
31 #include <unordered_map>
|
|
32
|
|
33 namespace llvm {
|
|
34 namespace exegesis {
|
|
35
|
|
36 // A helper class to analyze benchmark results for a target.
|
|
37 class Analysis {
|
|
38 public:
|
|
39 Analysis(const llvm::Target &Target,
|
|
40 std::unique_ptr<llvm::MCInstrInfo> InstrInfo,
|
|
41 const InstructionBenchmarkClustering &Clustering,
|
|
42 double AnalysisInconsistencyEpsilon,
|
|
43 bool AnalysisDisplayUnstableOpcodes);
|
|
44
|
|
45 // Prints a csv of instructions for each cluster.
|
|
46 struct PrintClusters {};
|
|
47 // Find potential errors in the scheduling information given measurements.
|
|
48 struct PrintSchedClassInconsistencies {};
|
|
49
|
|
50 template <typename Pass> llvm::Error run(llvm::raw_ostream &OS) const;
|
|
51
|
|
52 private:
|
|
53 using ClusterId = InstructionBenchmarkClustering::ClusterId;
|
|
54
|
|
55 // Represents the intersection of a sched class and a cluster.
|
|
56 class SchedClassCluster {
|
|
57 public:
|
|
58 const InstructionBenchmarkClustering::ClusterId &id() const {
|
|
59 return ClusterId;
|
|
60 }
|
|
61
|
|
62 const std::vector<size_t> &getPointIds() const { return PointIds; }
|
|
63
|
|
64 void addPoint(size_t PointId,
|
|
65 const InstructionBenchmarkClustering &Clustering);
|
|
66
|
|
67 // Return the cluster centroid.
|
|
68 const SchedClassClusterCentroid &getCentroid() const { return Centroid; }
|
|
69
|
|
70 // Returns true if the cluster representative measurements match that of SC.
|
|
71 bool
|
|
72 measurementsMatch(const llvm::MCSubtargetInfo &STI,
|
|
73 const ResolvedSchedClass &SC,
|
|
74 const InstructionBenchmarkClustering &Clustering,
|
|
75 const double AnalysisInconsistencyEpsilonSquared_) const;
|
|
76
|
|
77 private:
|
|
78 InstructionBenchmarkClustering::ClusterId ClusterId;
|
|
79 std::vector<size_t> PointIds;
|
|
80 // Measurement stats for the points in the SchedClassCluster.
|
|
81 SchedClassClusterCentroid Centroid;
|
|
82 };
|
|
83
|
|
84 void printInstructionRowCsv(size_t PointId, llvm::raw_ostream &OS) const;
|
|
85
|
|
86 void
|
|
87 printSchedClassClustersHtml(const std::vector<SchedClassCluster> &Clusters,
|
|
88 const ResolvedSchedClass &SC,
|
|
89 llvm::raw_ostream &OS) const;
|
|
90 void printSchedClassDescHtml(const ResolvedSchedClass &SC,
|
|
91 llvm::raw_ostream &OS) const;
|
|
92
|
|
93 // A pair of (Sched Class, indices of points that belong to the sched
|
|
94 // class).
|
|
95 struct ResolvedSchedClassAndPoints {
|
|
96 explicit ResolvedSchedClassAndPoints(ResolvedSchedClass &&RSC);
|
|
97
|
|
98 ResolvedSchedClass RSC;
|
|
99 std::vector<size_t> PointIds;
|
|
100 };
|
|
101
|
|
102 // Builds a list of ResolvedSchedClassAndPoints.
|
|
103 std::vector<ResolvedSchedClassAndPoints> makePointsPerSchedClass() const;
|
|
104
|
|
105 template <typename EscapeTag, EscapeTag Tag>
|
|
106 void writeSnippet(llvm::raw_ostream &OS, llvm::ArrayRef<uint8_t> Bytes,
|
|
107 const char *Separator) const;
|
|
108
|
|
109 const InstructionBenchmarkClustering &Clustering_;
|
|
110 llvm::MCObjectFileInfo ObjectFileInfo_;
|
|
111 std::unique_ptr<llvm::MCContext> Context_;
|
|
112 std::unique_ptr<llvm::MCSubtargetInfo> SubtargetInfo_;
|
|
113 std::unique_ptr<llvm::MCInstrInfo> InstrInfo_;
|
|
114 std::unique_ptr<llvm::MCRegisterInfo> RegInfo_;
|
|
115 std::unique_ptr<llvm::MCAsmInfo> AsmInfo_;
|
|
116 std::unique_ptr<llvm::MCInstPrinter> InstPrinter_;
|
|
117 std::unique_ptr<llvm::MCDisassembler> Disasm_;
|
|
118 const double AnalysisInconsistencyEpsilonSquared_;
|
|
119 const bool AnalysisDisplayUnstableOpcodes_;
|
|
120 };
|
|
121
|
|
122 } // namespace exegesis
|
|
123 } // namespace llvm
|
|
124
|
|
125 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H
|