[llvm] r333886 - [llvm-exegesis][NFC] Use an enum instead of a string for benchmark mode.

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 4 04:43:40 PDT 2018


Author: courbet
Date: Mon Jun  4 04:43:40 2018
New Revision: 333886

URL: http://llvm.org/viewvc/llvm-project?rev=333886&view=rev
Log:
[llvm-exegesis][NFC] Use an enum instead of a string for benchmark mode.

Summary: YAML encoding is backwards-compatible.

Reviewers: gchatelet

Subscribers: tschuett, llvm-commits

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

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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Analysis.cpp Mon Jun  4 04:43:40 2018
@@ -319,8 +319,9 @@ bool Analysis::SchedClassCluster::measur
   std::vector<BenchmarkMeasure> SchedClassPoint(NumMeasurements);
   // Latency case.
   assert(!Clustering.getPoints().empty());
-  const std::string &Mode = Clustering.getPoints()[0].Key.Mode;
-  if (Mode == "latency") { // FIXME: use an enum.
+  const InstructionBenchmarkKey::ModeE Mode =
+      Clustering.getPoints()[0].Key.Mode;
+  if (Mode == InstructionBenchmarkKey::Latency) {
     if (NumMeasurements != 1) {
       llvm::errs()
           << "invalid number of measurements in latency mode: expected 1, got "
@@ -336,7 +337,7 @@ bool Analysis::SchedClassCluster::measur
           std::max<double>(SchedClassPoint[0].Value, WLE->Cycles);
     }
     ClusterCenterPoint[0].Value = Representative[0].avg();
-  } else if (Mode == "uops") {
+  } else if (Mode == InstructionBenchmarkKey::Uops) {
     for (int I = 0, E = Representative.size(); I < E; ++I) {
       // Find the pressure on ProcResIdx `Key`.
       uint16_t ProcResIdx = 0;
@@ -358,8 +359,8 @@ bool Analysis::SchedClassCluster::measur
       ClusterCenterPoint[I].Value = Representative[I].avg();
     }
   } else {
-    llvm::errs() << "unimplemented measurement matching for mode ''" << Mode
-                 << "''\n";
+    llvm::errs() << "unimplemented measurement matching for mode " << Mode
+                 << "\n";
     return false;
   }
   return Clustering.isNeighbour(ClusterCenterPoint, SchedClassPoint);

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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.cpp Mon Jun  4 04:43:40 2018
@@ -34,6 +34,16 @@ template <> struct MappingTraits<exegesi
   static const bool flow = true;
 };
 
+template <>
+struct ScalarEnumerationTraits<exegesis::InstructionBenchmarkKey::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);
+  }
+};
+
 template <> struct MappingTraits<exegesis::InstructionBenchmarkKey> {
   static void mapping(IO &Io, exegesis::InstructionBenchmarkKey &Obj) {
     Io.mapRequired("opcode_name", Obj.OpcodeName);

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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkResult.h Mon Jun  4 04:43:40 2018
@@ -27,8 +27,8 @@ namespace exegesis {
 struct InstructionBenchmarkKey {
   // The LLVM opcode name.
   std::string OpcodeName;
-  // The benchmark mode.
-  std::string Mode;
+  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;

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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Mon Jun  4 04:43:40 2018
@@ -37,7 +37,7 @@ InstructionBenchmark BenchmarkRunner::ru
   InstructionBenchmark InstrBenchmark;
 
   InstrBenchmark.Key.OpcodeName = State.getInstrInfo().getName(Opcode);
-  InstrBenchmark.Key.Mode = getDisplayName();
+  InstrBenchmark.Key.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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h Mon Jun  4 04:43:40 2018
@@ -54,7 +54,7 @@ protected:
   const llvm::MCRegisterInfo &MCRegisterInfo;
 
 private:
-  virtual const char *getDisplayName() const = 0;
+  virtual InstructionBenchmarkKey::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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp Mon Jun  4 04:43:40 2018
@@ -52,7 +52,9 @@ static llvm::Error makeError(llvm::Twine
 
 LatencyBenchmarkRunner::~LatencyBenchmarkRunner() = default;
 
-const char *LatencyBenchmarkRunner::getDisplayName() const { return "latency"; }
+InstructionBenchmarkKey::ModeE LatencyBenchmarkRunner::getMode() const {
+  return InstructionBenchmarkKey::Latency;
+}
 
 llvm::Expected<std::vector<llvm::MCInst>>
 LatencyBenchmarkRunner::createSnippet(RegisterAliasingTrackerCache &RATC,

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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.h Mon Jun  4 04:43:40 2018
@@ -25,7 +25,7 @@ public:
   ~LatencyBenchmarkRunner() override;
 
 private:
-  const char *getDisplayName() const override;
+  InstructionBenchmarkKey::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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp Mon Jun  4 04:43:40 2018
@@ -141,7 +141,9 @@ static llvm::Error makeError(llvm::Twine
 
 UopsBenchmarkRunner::~UopsBenchmarkRunner() = default;
 
-const char *UopsBenchmarkRunner::getDisplayName() const { return "uops"; }
+InstructionBenchmarkKey::ModeE UopsBenchmarkRunner::getMode() const {
+  return InstructionBenchmarkKey::Uops;
+}
 
 llvm::Expected<std::vector<llvm::MCInst>>
 UopsBenchmarkRunner::createSnippet(RegisterAliasingTrackerCache &RATC,

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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.h Mon Jun  4 04:43:40 2018
@@ -25,7 +25,7 @@ public:
   ~UopsBenchmarkRunner() override;
 
 private:
-  const char *getDisplayName() const override;
+  InstructionBenchmarkKey::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=333886&r1=333885&r2=333886&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp Mon Jun  4 04:43:40 2018
@@ -28,7 +28,7 @@ TEST(BenchmarkResultTest, WriteToAndRead
   InstructionBenchmark ToDisk;
 
   ToDisk.Key.OpcodeName = "name";
-  ToDisk.Key.Mode = "mode";
+  ToDisk.Key.Mode = InstructionBenchmarkKey::Latency;
   ToDisk.Key.Config = "config";
   ToDisk.CpuName = "cpu_name";
   ToDisk.LLVMTriple = "llvm_triple";




More information about the llvm-commits mailing list