summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib/Analysis.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2018-05-14 11:30:56 +0000
committerClement Courbet <courbet@google.com>2018-05-14 11:30:56 +0000
commit3d479fe81cbc533ea4bbe74e51c3a1dd3ae8ffef (patch)
treee308918cdd0ba1058e769c1e649fd48858ad4998 /llvm/tools/llvm-exegesis/lib/Analysis.cpp
parentf639eb055330ee52bcf5d7acef628f4bab3158a0 (diff)
downloadbcm5719-llvm-3d479fe81cbc533ea4bbe74e51c3a1dd3ae8ffef.tar.gz
bcm5719-llvm-3d479fe81cbc533ea4bbe74e51c3a1dd3ae8ffef.zip
[llvm-exegesis] Add an analysis mode.
The analysis mode gives the user a clustered view of the measurement results and highlights any inconsistencies with the checked-in data. llvm-svn: 332229
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/Analysis.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/Analysis.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp
new file mode 100644
index 00000000000..48700218577
--- /dev/null
+++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp
@@ -0,0 +1,55 @@
+
+#include "Analysis.h"
+#include "llvm/Support/Format.h"
+
+namespace exegesis {
+
+namespace {
+
+// Prints a row representing an instruction, along with scheduling info and
+// point coordinates (measurements).
+void renderInstructionRow(const InstructionBenchmark &Point,
+ const size_t NameLen, llvm::raw_ostream &OS) {
+ OS << llvm::format("%*s", NameLen, Point.AsmTmpl.Name.c_str());
+ for (const auto &Measurement : Point.Measurements) {
+ OS << llvm::format(" %*.2f", Measurement.Key.size(), Measurement.Value);
+ }
+ OS << "\n";
+}
+
+void analyzeCluster(const std::vector<InstructionBenchmark> &Points,
+ const llvm::MCSubtargetInfo &STI,
+ const InstructionBenchmarkClustering::Cluster &Cluster,
+ llvm::raw_ostream &OS) {
+ // TODO:
+ // std::sort(Cluster.PointIndices.begin(), Cluster.PointIndices.end(),
+ // [](int PointIdA, int PointIdB) { return GetSchedClass(Points[PointIdA]) <
+ // GetSchedClass(Points[PointIdB]); });
+ OS << "Cluster:\n";
+ // Get max length of the name for alignement.
+ size_t NameLen = 0;
+ for (const auto &PointId : Cluster.PointIndices) {
+ NameLen = std::max(NameLen, Points[PointId].AsmTmpl.Name.size());
+ }
+
+ // Print all points.
+ for (const auto &PointId : Cluster.PointIndices) {
+ renderInstructionRow(Points[PointId], NameLen, OS);
+ }
+}
+
+} // namespace
+
+llvm::Error
+printAnalysisClusters(const InstructionBenchmarkClustering &Clustering,
+ const llvm::MCSubtargetInfo &STI, llvm::raw_ostream &OS) {
+
+ for (const auto &Cluster : Clustering.getValidClusters()) {
+ analyzeCluster(Clustering.getPoints(), STI, Cluster, OS);
+ OS << "\n\n\n";
+ }
+
+ return llvm::Error::success();
+}
+
+} // namespace exegesis
OpenPOWER on IntegriCloud