[llvm] r332348 - [llvm-exegesis] Split AsmTemplate.Name into components.

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 06:07:05 PDT 2018


Author: courbet
Date: Tue May 15 06:07:05 2018
New Revision: 332348

URL: http://llvm.org/viewvc/llvm-project?rev=332348&view=rev
Log:
[llvm-exegesis] Split AsmTemplate.Name into components.

Summary:
AsmTemplate becomes IntructionBenchmarkKey, which has three components.
This allows retreiving the opcode for analysis.

Reviewers: gchatelet

Subscribers: tschuett, llvm-commits

Differential Revision: https://reviews.llvm.org/D46873

Modified:
    llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
    llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
    llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h
    llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
    llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp

Modified: llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp?rev=332348&r1=332347&r2=332348&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp Tue May 15 06:07:05 2018
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "BenchmarkResult.h"
 #include "Analysis.h"
+#include "BenchmarkResult.h"
 #include "llvm/Support/FormatVariadic.h"
 #include <vector>
 
@@ -16,7 +16,7 @@ namespace exegesis {
 
 static const char kCsvSep = ',';
 
-static void writeCsvEscaped(llvm::raw_ostream& OS, const std::string& S) {
+static void writeCsvEscaped(llvm::raw_ostream &OS, const std::string &S) {
   if (std::find(S.begin(), S.end(), kCsvSep) == S.end()) {
     OS << S;
   } else {
@@ -35,10 +35,12 @@ static void writeCsvEscaped(llvm::raw_os
 // Prints a row representing an instruction, along with scheduling info and
 // point coordinates (measurements).
 static void printInstructionRow(const InstructionBenchmark &Point,
-                         const llvm::MCSubtargetInfo &STI,
-                         const size_t ClusterId, llvm::raw_ostream &OS) {
+                                const llvm::MCSubtargetInfo &STI,
+                                const size_t ClusterId, llvm::raw_ostream &OS) {
   OS << ClusterId << kCsvSep;
-  writeCsvEscaped(OS, Point.AsmTmpl.Name);
+  writeCsvEscaped(OS, Point.Key.OpcodeName);
+  OS << kCsvSep;
+  writeCsvEscaped(OS, Point.Key.Config);
   // FIXME: Print the sched class once InstructionBenchmark separates key into
   // (mnemonic, mode, opaque).
   for (const auto &Measurement : Point.Measurements) {
@@ -49,9 +51,10 @@ static void printInstructionRow(const In
 }
 
 static void printCluster(const std::vector<InstructionBenchmark> &Points,
-                  const llvm::MCSubtargetInfo &STI, const size_t ClusterId,
-                  const InstructionBenchmarkClustering::Cluster &Cluster,
-                  llvm::raw_ostream &OS) {
+                         const llvm::MCSubtargetInfo &STI,
+                         const size_t ClusterId,
+                         const InstructionBenchmarkClustering::Cluster &Cluster,
+                         llvm::raw_ostream &OS) {
   // Print all points.
   for (const auto &PointId : Cluster.PointIndices) {
     printInstructionRow(Points[PointId], STI, ClusterId, OS);
@@ -65,7 +68,8 @@ printAnalysisClusters(const InstructionB
     return llvm::Error::success();
 
   // Write the header.
-  OS << "cluster_id;key,sched_class";
+  OS << "cluster_id" << kCsvSep << "opcode_name" << kCsvSep << "config"
+     << kCsvSep << "sched_class";
   for (const auto &Measurement : Clustering.getPoints().front().Measurements) {
     OS << kCsvSep;
     writeCsvEscaped(OS, Measurement.Key);

Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp?rev=332348&r1=332347&r2=332348&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp Tue May 15 06:07:05 2018
@@ -34,20 +34,23 @@ template <> struct MappingTraits<exegesi
   static const bool flow = true;
 };
 
-template <> struct MappingTraits<exegesis::AsmTemplate> {
-  static void mapping(IO &Io, exegesis::AsmTemplate &Obj) {
-    Io.mapRequired("name", Obj.Name);
+template <> struct MappingTraits<exegesis::InstructionBenchmarkKey> {
+  static void mapping(IO &Io, exegesis::InstructionBenchmarkKey &Obj) {
+    Io.mapRequired("opcode_name", Obj.OpcodeName);
+    Io.mapRequired("mode", Obj.Mode);
+    Io.mapOptional("config", Obj.Config);
   }
 };
 
 template <> struct MappingTraits<exegesis::InstructionBenchmark> {
   static void mapping(IO &Io, exegesis::InstructionBenchmark &Obj) {
-    Io.mapRequired("asm_template", Obj.AsmTmpl);
+    Io.mapRequired("key", Obj.Key);
     Io.mapRequired("cpu_name", Obj.CpuName);
     Io.mapRequired("llvm_triple", Obj.LLVMTriple);
     Io.mapRequired("num_repetitions", Obj.NumRepetitions);
     Io.mapRequired("measurements", Obj.Measurements);
     Io.mapRequired("error", Obj.Error);
+    Io.mapOptional("info", Obj.Info);
   }
 };
 

Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h?rev=332348&r1=332347&r2=332348&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h Tue May 15 06:07:05 2018
@@ -23,8 +23,14 @@
 
 namespace exegesis {
 
-struct AsmTemplate {
-  std::string Name;
+struct InstructionBenchmarkKey {
+  // The LLVM opcode name.
+  std::string OpcodeName;
+  // The benchmark mode.
+  std::string Mode;
+  // An opaque configuration, that can be used to separate several benchmarks of
+  // the same instruction under different configurations.
+  std::string Config;
 };
 
 struct BenchmarkMeasure {
@@ -35,12 +41,13 @@ struct BenchmarkMeasure {
 
 // The result of an instruction benchmark.
 struct InstructionBenchmark {
-  AsmTemplate AsmTmpl;
+  InstructionBenchmarkKey Key;
   std::string CpuName;
   std::string LLVMTriple;
   int NumRepetitions = 0;
   std::vector<BenchmarkMeasure> Measurements;
   std::string Error;
+  std::string Info;
 
   static InstructionBenchmark readYamlOrDie(llvm::StringRef Filename);
   static std::vector<InstructionBenchmark> readYamlsOrDie(llvm::StringRef Filename);

Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp?rev=332348&r1=332347&r2=332348&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Tue May 15 06:07:05 2018
@@ -26,11 +26,8 @@ BenchmarkRunner::run(const LLVMState &St
                      const InstructionFilter &Filter) const {
   InstructionBenchmark InstrBenchmark;
 
-  InstrBenchmark.AsmTmpl.Name =
-      llvm::Twine(getDisplayName())
-          .concat(" ")
-          .concat(State.getInstrInfo().getName(Opcode))
-          .str();
+  InstrBenchmark.Key.OpcodeName = State.getInstrInfo().getName(Opcode);
+  InstrBenchmark.Key.Mode = getDisplayName();
   InstrBenchmark.CpuName = State.getCpuName();
   InstrBenchmark.LLVMTriple = State.getTriple();
   InstrBenchmark.NumRepetitions = NumRepetitions;

Modified: llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp?rev=332348&r1=332347&r2=332348&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp Tue May 15 06:07:05 2018
@@ -27,13 +27,16 @@ namespace {
 TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
   InstructionBenchmark ToDisk;
 
-  ToDisk.AsmTmpl.Name = "name";
+  ToDisk.Key.OpcodeName = "name";
+  ToDisk.Key.Mode = "mode";
+  ToDisk.Key.Config = "config";
   ToDisk.CpuName = "cpu_name";
   ToDisk.LLVMTriple = "llvm_triple";
   ToDisk.NumRepetitions = 1;
   ToDisk.Measurements.push_back(BenchmarkMeasure{"a", 1, "debug a"});
   ToDisk.Measurements.push_back(BenchmarkMeasure{"b", 2, ""});
   ToDisk.Error = "error";
+  ToDisk.Info = "info";
 
   llvm::SmallString<64> Filename;
   std::error_code EC;
@@ -47,24 +50,30 @@ TEST(BenchmarkResultTest, WriteToAndRead
     // One-element version.
     const auto FromDisk = InstructionBenchmark::readYamlOrDie(Filename);
 
-    EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
+    EXPECT_EQ(FromDisk.Key.OpcodeName, ToDisk.Key.OpcodeName);
+    EXPECT_EQ(FromDisk.Key.Mode, ToDisk.Key.Mode);
+    EXPECT_EQ(FromDisk.Key.Config, ToDisk.Key.Config);
     EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
     EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
     EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
     EXPECT_THAT(FromDisk.Measurements, ToDisk.Measurements);
     EXPECT_THAT(FromDisk.Error, ToDisk.Error);
+    EXPECT_EQ(FromDisk.Info, ToDisk.Info);
   }
   {
     // Vector version.
     const auto FromDiskVector = InstructionBenchmark::readYamlsOrDie(Filename);
     ASSERT_EQ(FromDiskVector.size(), size_t{1});
     const auto FromDisk = FromDiskVector[0];
-    EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
+    EXPECT_EQ(FromDisk.Key.OpcodeName, ToDisk.Key.OpcodeName);
+    EXPECT_EQ(FromDisk.Key.Mode, ToDisk.Key.Mode);
+    EXPECT_EQ(FromDisk.Key.Config, ToDisk.Key.Config);
     EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
     EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
     EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
     EXPECT_THAT(FromDisk.Measurements, ToDisk.Measurements);
     EXPECT_THAT(FromDisk.Error, ToDisk.Error);
+    EXPECT_EQ(FromDisk.Info, ToDisk.Info);
   }
 }
 




More information about the llvm-commits mailing list