[llvm] r334169 - [llvm-exegesis] Add a Configuration object for Benchmark.

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 7 01:11:55 PDT 2018


Author: gchatelet
Date: Thu Jun  7 01:11:54 2018
New Revision: 334169

URL: http://llvm.org/viewvc/llvm-project?rev=334169&view=rev
Log:
[llvm-exegesis] Add a Configuration object for Benchmark.

Summary: This is the first step to have the BenchmarkRunner create and measure many different configurations (different initial values for instance).

Reviewers: courbet

Subscribers: tschuett, llvm-commits

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

Modified:
    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

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=334169&r1=334168&r2=334169&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Thu Jun  7 01:11:54 2018
@@ -52,13 +52,14 @@ InstructionBenchmark BenchmarkRunner::ru
     return InstrBenchmark;
   }
   llvm::raw_string_ostream InfoStream(InstrBenchmark.Info);
-  llvm::Expected<std::vector<llvm::MCInst>> SnippetOrError =
-      createSnippet(RATC, Opcode, InfoStream);
-  if (llvm::Error E = SnippetOrError.takeError()) {
+  llvm::Expected<BenchmarkConfiguration> ConfigurationOrError =
+      createConfiguration(RATC, Opcode, InfoStream);
+  if (llvm::Error E = ConfigurationOrError.takeError()) {
     InstrBenchmark.Error = llvm::toString(std::move(E));
     return InstrBenchmark;
   }
-  std::vector<llvm::MCInst> &Snippet = SnippetOrError.get();
+  BenchmarkConfiguration &Configuration = ConfigurationOrError.get();
+  const std::vector<llvm::MCInst> &Snippet = Configuration.Snippet;
   if (Snippet.empty()) {
     InstrBenchmark.Error = "Empty snippet";
     return InstrBenchmark;

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=334169&r1=334168&r2=334169&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.h Thu Jun  7 01:11:54 2018
@@ -26,6 +26,17 @@
 
 namespace exegesis {
 
+// A collection of instructions that are to be assembled, executed and measured.
+struct BenchmarkConfiguration {
+  // This code is run before the Snippet is iterated. Since it is part of the
+  // measurement it should be as short as possible. It is usually used to setup
+  // the content of the Registers.
+  std::vector<llvm::MCInst> SnippetSetup;
+
+  // The sequence of instructions that are to be repeated.
+  std::vector<llvm::MCInst> Snippet;
+};
+
 // Common code for all benchmark modes.
 class BenchmarkRunner {
 public:
@@ -56,9 +67,9 @@ protected:
 private:
   virtual InstructionBenchmark::ModeE getMode() const = 0;
 
-  virtual llvm::Expected<std::vector<llvm::MCInst>>
-  createSnippet(RegisterAliasingTrackerCache &RATC, unsigned Opcode,
-                llvm::raw_ostream &Debug) const = 0;
+  virtual llvm::Expected<BenchmarkConfiguration>
+  createConfiguration(RegisterAliasingTrackerCache &RATC, unsigned Opcode,
+                      llvm::raw_ostream &Debug) const = 0;
 
   virtual std::vector<BenchmarkMeasure>
   runMeasurements(const ExecutableFunction &EF,

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=334169&r1=334168&r2=334169&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp Thu Jun  7 01:11:54 2018
@@ -56,11 +56,12 @@ InstructionBenchmark::ModeE LatencyBench
   return InstructionBenchmark::Latency;
 }
 
-llvm::Expected<std::vector<llvm::MCInst>>
-LatencyBenchmarkRunner::createSnippet(RegisterAliasingTrackerCache &RATC,
-                                      unsigned Opcode,
-                                      llvm::raw_ostream &Info) const {
-  std::vector<llvm::MCInst> Snippet;
+llvm::Expected<BenchmarkConfiguration>
+LatencyBenchmarkRunner::createConfiguration(RegisterAliasingTrackerCache &RATC,
+                                            unsigned Opcode,
+                                            llvm::raw_ostream &Info) const {
+  BenchmarkConfiguration Configuration;
+  std::vector<llvm::MCInst> &Snippet = Configuration.Snippet;
   const llvm::MCInstrDesc &MCInstrDesc = MCInstrInfo.get(Opcode);
   const Instruction ThisInstruction(MCInstrDesc, RATC);
 
@@ -77,7 +78,7 @@ LatencyBenchmarkRunner::createSnippet(Re
       Info << "implicit Self cycles, picking random values.\n";
     }
     Snippet.push_back(randomizeUnsetVariablesAndBuild(ThisInstruction));
-    return Snippet;
+    return Configuration;
   }
 
   // Let's try to create a dependency through another opcode.
@@ -102,7 +103,7 @@ LatencyBenchmarkRunner::createSnippet(Re
          << ".\n";
     Snippet.push_back(randomizeUnsetVariablesAndBuild(ThisInstruction));
     Snippet.push_back(randomizeUnsetVariablesAndBuild(OtherInstruction));
-    return Snippet;
+    return Configuration;
   }
 
   return makeError(

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=334169&r1=334168&r2=334169&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.h Thu Jun  7 01:11:54 2018
@@ -27,9 +27,9 @@ public:
 private:
   InstructionBenchmark::ModeE getMode() const override;
 
-  llvm::Expected<std::vector<llvm::MCInst>>
-  createSnippet(RegisterAliasingTrackerCache &RATC, unsigned OpcodeIndex,
-                llvm::raw_ostream &Info) const override;
+  llvm::Expected<BenchmarkConfiguration>
+  createConfiguration(RegisterAliasingTrackerCache &RATC, unsigned OpcodeIndex,
+                      llvm::raw_ostream &Info) const override;
 
   std::vector<BenchmarkMeasure>
   runMeasurements(const ExecutableFunction &EF,

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=334169&r1=334168&r2=334169&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.cpp Thu Jun  7 01:11:54 2018
@@ -145,11 +145,12 @@ InstructionBenchmark::ModeE UopsBenchmar
   return InstructionBenchmark::Uops;
 }
 
-llvm::Expected<std::vector<llvm::MCInst>>
-UopsBenchmarkRunner::createSnippet(RegisterAliasingTrackerCache &RATC,
-                                   unsigned Opcode,
-                                   llvm::raw_ostream &Info) const {
-  std::vector<llvm::MCInst> Snippet;
+llvm::Expected<BenchmarkConfiguration>
+UopsBenchmarkRunner::createConfiguration(RegisterAliasingTrackerCache &RATC,
+                                         unsigned Opcode,
+                                         llvm::raw_ostream &Info) const {
+  BenchmarkConfiguration Configuration;
+  std::vector<llvm::MCInst> &Snippet = Configuration.Snippet;
   const llvm::MCInstrDesc &MCInstrDesc = MCInstrInfo.get(Opcode);
   const Instruction Instruction(MCInstrDesc, RATC);
 
@@ -162,12 +163,12 @@ UopsBenchmarkRunner::createSnippet(Regis
   if (SelfAliasing.empty()) {
     Info << "instruction is parallel, repeating a random one.\n";
     Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction));
-    return Snippet;
+    return Configuration;
   }
   if (SelfAliasing.hasImplicitAliasing()) {
     Info << "instruction is serial, repeating a random one.\n";
     Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction));
-    return Snippet;
+    return Configuration;
   }
   const auto TiedVariables = getTiedVariables(Instruction);
   if (!TiedVariables.empty()) {
@@ -188,7 +189,7 @@ UopsBenchmarkRunner::createSnippet(Regis
       Var->AssignedValue = llvm::MCOperand::createReg(Reg);
       Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction));
     }
-    return Snippet;
+    return Configuration;
   }
   // No tied variables, we pick random values for defs.
   llvm::BitVector Defs(MCRegisterInfo.getNumRegs());
@@ -219,7 +220,7 @@ UopsBenchmarkRunner::createSnippet(Regis
   Info
       << "instruction has no tied variables picking Uses different from defs\n";
   Snippet.push_back(randomizeUnsetVariablesAndBuild(Instruction));
-  return Snippet;
+  return Configuration;
 }
 
 std::vector<BenchmarkMeasure>

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=334169&r1=334168&r2=334169&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Uops.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Uops.h Thu Jun  7 01:11:54 2018
@@ -27,9 +27,9 @@ public:
 private:
   InstructionBenchmark::ModeE getMode() const override;
 
-  llvm::Expected<std::vector<llvm::MCInst>>
-  createSnippet(RegisterAliasingTrackerCache &RATC, unsigned Opcode,
-                llvm::raw_ostream &Info) const override;
+  llvm::Expected<BenchmarkConfiguration>
+  createConfiguration(RegisterAliasingTrackerCache &RATC, unsigned Opcode,
+                      llvm::raw_ostream &Info) const override;
 
   std::vector<BenchmarkMeasure>
   runMeasurements(const ExecutableFunction &EF,




More information about the llvm-commits mailing list