[llvm] r334079 - [llvm-exegesis] move Mode from Key to BenchmarResult.

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 6 02:42:37 PDT 2018


Author: courbet
Date: Wed Jun  6 02:42:36 2018
New Revision: 334079

URL: http://llvm.org/viewvc/llvm-project?rev=334079&view=rev
Log:
[llvm-exegesis] move Mode from Key to BenchmarResult.

Moves the Mode field out of the Key. The existing yaml benchmark results can be fixed with the following script:

```
readonly FILE=$1
readonly MODE=latency # Change to uops to fix a uops benchmark.
cat $FILE | \
  sed "/^\ \+mode:\ \+$MODE$/d" | \
  sed "/^cpu_name.*$/i mode:            $MODE"
```

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

Authored by: Guillaume Chatelet

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/tools/llvm-exegesis/lib/BenchmarkRunner.h
    llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp
    llvm/trunk/tools/llvm-exegesis/lib/Latency.h
    llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp
    llvm/trunk/tools/llvm-exegesis/lib/Uops.h
    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=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp Wed Jun  6 02:42:36 2018
@@ -319,9 +319,8 @@ bool Analysis::SchedClassCluster::measur
   std::vector<BenchmarkMeasure> SchedClassPoint(NumMeasurements);
   // Latency case.
   assert(!Clustering.getPoints().empty());
-  const InstructionBenchmarkKey::ModeE Mode =
-      Clustering.getPoints()[0].Key.Mode;
-  if (Mode == InstructionBenchmarkKey::Latency) {
+  const InstructionBenchmark::ModeE Mode = Clustering.getPoints()[0].Mode;
+  if (Mode == InstructionBenchmark::Latency) {
     if (NumMeasurements != 1) {
       llvm::errs()
           << "invalid number of measurements in latency mode: expected 1, got "
@@ -337,7 +336,7 @@ bool Analysis::SchedClassCluster::measur
           std::max<double>(SchedClassPoint[0].Value, WLE->Cycles);
     }
     ClusterCenterPoint[0].Value = Representative[0].avg();
-  } else if (Mode == InstructionBenchmarkKey::Uops) {
+  } else if (Mode == InstructionBenchmark::Uops) {
     for (int I = 0, E = Representative.size(); I < E; ++I) {
       // Find the pressure on ProcResIdx `Key`.
       uint16_t ProcResIdx = 0;

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=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp Wed Jun  6 02:42:36 2018
@@ -68,12 +68,12 @@ template <> struct MappingTraits<exegesi
 };
 
 template <>
-struct ScalarEnumerationTraits<exegesis::InstructionBenchmarkKey::ModeE> {
+struct ScalarEnumerationTraits<exegesis::InstructionBenchmark::ModeE> {
   static void enumeration(IO &Io,
-                          exegesis::InstructionBenchmarkKey::ModeE &Value) {
-    Io.enumCase(Value, "", exegesis::InstructionBenchmarkKey::Unknown);
-    Io.enumCase(Value, "latency", exegesis::InstructionBenchmarkKey::Latency);
-    Io.enumCase(Value, "uops", exegesis::InstructionBenchmarkKey::Uops);
+                          exegesis::InstructionBenchmark::ModeE &Value) {
+    Io.enumCase(Value, "", exegesis::InstructionBenchmark::Unknown);
+    Io.enumCase(Value, "latency", exegesis::InstructionBenchmark::Latency);
+    Io.enumCase(Value, "uops", exegesis::InstructionBenchmark::Uops);
   }
 };
 
@@ -81,13 +81,13 @@ template <> struct MappingTraits<exegesi
   static void mapping(IO &Io, exegesis::InstructionBenchmarkKey &Obj) {
     Io.mapRequired("opcode_name", Obj.OpcodeName);
     Io.mapOptional("instructions", Obj.Instructions);
-    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("mode", Obj.Mode);
     Io.mapRequired("key", Obj.Key);
     Io.mapRequired("cpu_name", Obj.CpuName);
     Io.mapRequired("llvm_triple", Obj.LLVMTriple);

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=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h Wed Jun  6 02:42:36 2018
@@ -34,8 +34,6 @@ struct InstructionBenchmarkKey {
   // The LLVM opcode name.
   std::string OpcodeName; // FIXME: Deprecated, use Instructions below.
   std::vector<llvm::MCInst> Instructions;
-  enum ModeE { Unknown, Latency, Uops };
-  ModeE Mode;
   // An opaque configuration, that can be used to separate several benchmarks of
   // the same instruction under different configurations.
   std::string Config;
@@ -50,6 +48,8 @@ struct BenchmarkMeasure {
 // The result of an instruction benchmark.
 struct InstructionBenchmark {
   InstructionBenchmarkKey Key;
+  enum ModeE { Unknown, Latency, Uops };
+  ModeE Mode;
   std::string CpuName;
   std::string LLVMTriple;
   int NumRepetitions = 0;

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=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Wed Jun  6 02:42:36 2018
@@ -37,7 +37,7 @@ InstructionBenchmark BenchmarkRunner::ru
   InstructionBenchmark InstrBenchmark;
 
   InstrBenchmark.Key.OpcodeName = State.getInstrInfo().getName(Opcode);
-  InstrBenchmark.Key.Mode = getMode();
+  InstrBenchmark.Mode = getMode();
   InstrBenchmark.CpuName = State.getCpuName();
   InstrBenchmark.LLVMTriple = State.getTriple();
   InstrBenchmark.NumRepetitions = NumRepetitions;

Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h?rev=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h Wed Jun  6 02:42:36 2018
@@ -54,7 +54,7 @@ protected:
   const llvm::MCRegisterInfo &MCRegisterInfo;
 
 private:
-  virtual InstructionBenchmarkKey::ModeE getMode() const = 0;
+  virtual InstructionBenchmark::ModeE getMode() const = 0;
 
   virtual llvm::Expected<std::vector<llvm::MCInst>>
   createSnippet(RegisterAliasingTrackerCache &RATC, unsigned Opcode,

Modified: llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp?rev=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp Wed Jun  6 02:42:36 2018
@@ -52,8 +52,8 @@ static llvm::Error makeError(llvm::Twine
 
 LatencyBenchmarkRunner::~LatencyBenchmarkRunner() = default;
 
-InstructionBenchmarkKey::ModeE LatencyBenchmarkRunner::getMode() const {
-  return InstructionBenchmarkKey::Latency;
+InstructionBenchmark::ModeE LatencyBenchmarkRunner::getMode() const {
+  return InstructionBenchmark::Latency;
 }
 
 llvm::Expected<std::vector<llvm::MCInst>>

Modified: llvm/trunk/tools/llvm-exegesis/lib/Latency.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Latency.h?rev=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.h Wed Jun  6 02:42:36 2018
@@ -25,7 +25,7 @@ public:
   ~LatencyBenchmarkRunner() override;
 
 private:
-  InstructionBenchmarkKey::ModeE getMode() const override;
+  InstructionBenchmark::ModeE getMode() const override;
 
   llvm::Expected<std::vector<llvm::MCInst>>
   createSnippet(RegisterAliasingTrackerCache &RATC, unsigned OpcodeIndex,

Modified: llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp?rev=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp Wed Jun  6 02:42:36 2018
@@ -141,8 +141,8 @@ static llvm::Error makeError(llvm::Twine
 
 UopsBenchmarkRunner::~UopsBenchmarkRunner() = default;
 
-InstructionBenchmarkKey::ModeE UopsBenchmarkRunner::getMode() const {
-  return InstructionBenchmarkKey::Uops;
+InstructionBenchmark::ModeE UopsBenchmarkRunner::getMode() const {
+  return InstructionBenchmark::Uops;
 }
 
 llvm::Expected<std::vector<llvm::MCInst>>

Modified: llvm/trunk/tools/llvm-exegesis/lib/Uops.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Uops.h?rev=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.h Wed Jun  6 02:42:36 2018
@@ -25,7 +25,7 @@ public:
   ~UopsBenchmarkRunner() override;
 
 private:
-  InstructionBenchmarkKey::ModeE getMode() const override;
+  InstructionBenchmark::ModeE getMode() const override;
 
   llvm::Expected<std::vector<llvm::MCInst>>
   createSnippet(RegisterAliasingTrackerCache &RATC, unsigned Opcode,

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=334079&r1=334078&r2=334079&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp Wed Jun  6 02:42:36 2018
@@ -45,8 +45,8 @@ TEST(BenchmarkResultTest, WriteToAndRead
 
   ToDisk.Key.OpcodeName = "name";
   ToDisk.Key.Instructions.push_back(llvm::MCInstBuilder(kInstrId));
-  ToDisk.Key.Mode = InstructionBenchmarkKey::Latency;
   ToDisk.Key.Config = "config";
+  ToDisk.Mode = InstructionBenchmark::Latency;
   ToDisk.CpuName = "cpu_name";
   ToDisk.LLVMTriple = "llvm_triple";
   ToDisk.NumRepetitions = 1;
@@ -69,8 +69,8 @@ TEST(BenchmarkResultTest, WriteToAndRead
     EXPECT_EQ(FromDisk.Key.OpcodeName, ToDisk.Key.OpcodeName);
     EXPECT_THAT(FromDisk.Key.Instructions,
                 Pointwise(EqMCInst(), ToDisk.Key.Instructions));
-    EXPECT_EQ(FromDisk.Key.Mode, ToDisk.Key.Mode);
     EXPECT_EQ(FromDisk.Key.Config, ToDisk.Key.Config);
+    EXPECT_EQ(FromDisk.Mode, ToDisk.Mode);
     EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
     EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
     EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
@@ -87,8 +87,8 @@ TEST(BenchmarkResultTest, WriteToAndRead
     EXPECT_EQ(FromDisk.Key.OpcodeName, ToDisk.Key.OpcodeName);
     EXPECT_THAT(FromDisk.Key.Instructions,
                 Pointwise(EqMCInst(), ToDisk.Key.Instructions));
-    EXPECT_EQ(FromDisk.Key.Mode, ToDisk.Key.Mode);
     EXPECT_EQ(FromDisk.Key.Config, ToDisk.Key.Config);
+    EXPECT_EQ(FromDisk.Mode, ToDisk.Mode);
     EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
     EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
     EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);




More information about the llvm-commits mailing list