xref: /llvm-project/llvm/tools/llvm-exegesis/lib/Analysis.cpp (revision 4623da899102315c1a524efbe3c538f2f3b4fcbe)
1 
2 #include "Analysis.h"
3 #include "llvm/Support/Format.h"
4 
5 namespace exegesis {
6 
7 namespace {
8 
9 // Prints a row representing an instruction, along with scheduling info and
10 // point coordinates (measurements).
11 void renderInstructionRow(const InstructionBenchmark &Point,
12                           const size_t NameLen, llvm::raw_ostream &OS) {
13   OS << llvm::format("%*s", NameLen, Point.AsmTmpl.Name.c_str());
14   for (const auto &Measurement : Point.Measurements) {
15     OS << llvm::format("   %*.2f", Measurement.Key.size(), Measurement.Value);
16   }
17   OS << "\n";
18 }
19 
20 void printCluster(const std::vector<InstructionBenchmark> &Points,
21                   const llvm::MCSubtargetInfo &STI,
22                   const size_t ClusterId,
23                   const InstructionBenchmarkClustering::Cluster &Cluster,
24                   llvm::raw_ostream &OS) {
25   // TODO:
26   // GetSchedClass(Points[PointIdB]); });
27 
28   // Print all points.
29   for (const auto &PointId : Cluster.PointIndices) {
30     renderInstructionRow(Points[PointId], NameLen, OS);
31   }
32 }
33 
34 } // namespace
35 
36 llvm::Error
37 printAnalysisClusters(const InstructionBenchmarkClustering &Clustering,
38                       const llvm::MCSubtargetInfo &STI, llvm::raw_ostream &OS) {
39   OS << "cluster_id,key,";
40   for (size_t I = 0, E = Clustering.getValidClusters().size(); I < E; ++I) {
41     printCluster(Clustering.getPoints(), STI, I, Clustering.getValidClusters()[I], OS);
42     OS << "\n\n";
43   }
44 
45   return llvm::Error::success();
46 }
47 
48 } // namespace exegesis
49