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"
30 // A helper class to analyze benchmark results for a target.
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;
46 using ClusterId
= BenchmarkClustering::ClusterId
;
48 // Represents the intersection of a sched class and a cluster.
49 class SchedClassCluster
{
51 const BenchmarkClustering::ClusterId
&id() const {
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.
65 measurementsMatch(const MCSubtargetInfo
&STI
, const ResolvedSchedClass
&SC
,
66 const BenchmarkClustering
&Clustering
,
67 const double AnalysisInconsistencyEpsilonSquared_
) const;
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;
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
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
116 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H