1 //===-- Analysis.h ----------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Analysis output for benchmark results.
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"
28 #include <unordered_map>
33 // A helper class to analyze benchmark results for a target.
36 Analysis(const LLVMState
&State
,
37 const BenchmarkClustering
&Clustering
,
38 double AnalysisInconsistencyEpsilon
,
39 bool AnalysisDisplayUnstableOpcodes
);
41 // Prints a csv of instructions for each cluster.
42 struct PrintClusters
{};
43 // Find potential errors in the scheduling information given measurements.
44 struct PrintSchedClassInconsistencies
{};
46 template <typename Pass
> Error
run(raw_ostream
&OS
) const;
49 using ClusterId
= BenchmarkClustering::ClusterId
;
51 // Represents the intersection of a sched class and a cluster.
52 class SchedClassCluster
{
54 const BenchmarkClustering::ClusterId
&id() const {
58 const std::vector
<size_t> &getPointIds() const { return PointIds
; }
60 void addPoint(size_t PointId
,
61 const BenchmarkClustering
&Clustering
);
63 // Return the cluster centroid.
64 const SchedClassClusterCentroid
&getCentroid() const { return Centroid
; }
66 // Returns true if the cluster representative measurements match that of SC.
68 measurementsMatch(const MCSubtargetInfo
&STI
, const ResolvedSchedClass
&SC
,
69 const BenchmarkClustering
&Clustering
,
70 const double AnalysisInconsistencyEpsilonSquared_
) const;
73 BenchmarkClustering::ClusterId ClusterId
;
74 std::vector
<size_t> PointIds
;
75 // Measurement stats for the points in the SchedClassCluster.
76 SchedClassClusterCentroid Centroid
;
79 void printInstructionRowCsv(size_t PointId
, raw_ostream
&OS
) const;
81 void printClusterRawHtml(const BenchmarkClustering::ClusterId
&Id
,
82 StringRef display_name
, llvm::raw_ostream
&OS
) const;
84 void printPointHtml(const Benchmark
&Point
,
85 llvm::raw_ostream
&OS
) const;
88 printSchedClassClustersHtml(const std::vector
<SchedClassCluster
> &Clusters
,
89 const ResolvedSchedClass
&SC
,
90 raw_ostream
&OS
) const;
91 void printSchedClassDescHtml(const ResolvedSchedClass
&SC
,
92 raw_ostream
&OS
) const;
94 // A pair of (Sched Class, indices of points that belong to the sched
96 struct ResolvedSchedClassAndPoints
{
97 explicit ResolvedSchedClassAndPoints(ResolvedSchedClass
&&RSC
);
99 ResolvedSchedClass RSC
;
100 std::vector
<size_t> PointIds
;
103 // Builds a list of ResolvedSchedClassAndPoints.
104 std::vector
<ResolvedSchedClassAndPoints
> makePointsPerSchedClass() const;
106 template <typename EscapeTag
, EscapeTag Tag
>
107 void writeSnippet(raw_ostream
&OS
, ArrayRef
<uint8_t> Bytes
,
108 const char *Separator
) const;
110 const BenchmarkClustering
&Clustering_
;
111 const LLVMState
&State_
;
112 std::unique_ptr
<DisassemblerHelper
> DisasmHelper_
;
113 const double AnalysisInconsistencyEpsilonSquared_
;
114 const bool AnalysisDisplayUnstableOpcodes_
;
117 } // namespace exegesis
120 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H