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"
32 // A helper class to analyze benchmark results for a target.
35 Analysis(const LLVMState
&State
,
36 const BenchmarkClustering
&Clustering
,
37 double AnalysisInconsistencyEpsilon
,
38 bool AnalysisDisplayUnstableOpcodes
);
40 // Prints a csv of instructions for each cluster.
41 struct PrintClusters
{};
42 // Find potential errors in the scheduling information given measurements.
43 struct PrintSchedClassInconsistencies
{};
45 template <typename Pass
> Error
run(raw_ostream
&OS
) const;
48 using ClusterId
= BenchmarkClustering::ClusterId
;
50 // Represents the intersection of a sched class and a cluster.
51 class SchedClassCluster
{
53 const BenchmarkClustering::ClusterId
&id() const {
57 const std::vector
<size_t> &getPointIds() const { return PointIds
; }
59 void addPoint(size_t PointId
,
60 const BenchmarkClustering
&Clustering
);
62 // Return the cluster centroid.
63 const SchedClassClusterCentroid
&getCentroid() const { return Centroid
; }
65 // Returns true if the cluster representative measurements match that of SC.
67 measurementsMatch(const MCSubtargetInfo
&STI
, const ResolvedSchedClass
&SC
,
68 const BenchmarkClustering
&Clustering
,
69 const double AnalysisInconsistencyEpsilonSquared_
) const;
72 BenchmarkClustering::ClusterId ClusterId
;
73 std::vector
<size_t> PointIds
;
74 // Measurement stats for the points in the SchedClassCluster.
75 SchedClassClusterCentroid Centroid
;
78 void printInstructionRowCsv(size_t PointId
, raw_ostream
&OS
) const;
80 void printClusterRawHtml(const BenchmarkClustering::ClusterId
&Id
,
81 StringRef display_name
, llvm::raw_ostream
&OS
) const;
83 void printPointHtml(const Benchmark
&Point
,
84 llvm::raw_ostream
&OS
) const;
87 printSchedClassClustersHtml(const std::vector
<SchedClassCluster
> &Clusters
,
88 const ResolvedSchedClass
&SC
,
89 raw_ostream
&OS
) const;
90 void printSchedClassDescHtml(const ResolvedSchedClass
&SC
,
91 raw_ostream
&OS
) const;
93 // A pair of (Sched Class, indices of points that belong to the sched
95 struct ResolvedSchedClassAndPoints
{
96 explicit ResolvedSchedClassAndPoints(ResolvedSchedClass
&&RSC
);
98 ResolvedSchedClass RSC
;
99 std::vector
<size_t> PointIds
;
102 // Builds a list of ResolvedSchedClassAndPoints.
103 std::vector
<ResolvedSchedClassAndPoints
> makePointsPerSchedClass() const;
105 template <typename EscapeTag
, EscapeTag Tag
>
106 void writeSnippet(raw_ostream
&OS
, ArrayRef
<uint8_t> Bytes
,
107 const char *Separator
) const;
109 const BenchmarkClustering
&Clustering_
;
110 const LLVMState
&State_
;
111 std::unique_ptr
<DisassemblerHelper
> DisasmHelper_
;
112 const double AnalysisInconsistencyEpsilonSquared_
;
113 const bool AnalysisDisplayUnstableOpcodes_
;
116 } // namespace exegesis
119 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CLUSTERING_H