[NFC][llvm-exegesis] Benchmark: move DumpObjectToDisk handling into `runConfiguration()`
authorRoman Lebedev <lebedev.ri@gmail.com>
Sun, 18 Dec 2022 14:36:32 +0000 (17:36 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sun, 18 Dec 2022 14:52:04 +0000 (17:52 +0300)
`getRunnableConfiguration()` may be executed in parallel,
and then this the output would become even less useful.

llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
llvm/tools/llvm-exegesis/llvm-exegesis.cpp

index eb90f43..37b33ae 100644 (file)
@@ -151,11 +151,9 @@ Expected<SmallString<0>> BenchmarkRunner::assembleSnippet(
 }
 
 Expected<BenchmarkRunner::RunnableConfiguration>
-BenchmarkRunner::getRunnableConfiguration(const BenchmarkCode &BC,
-                                          unsigned NumRepetitions,
-                                          unsigned LoopBodySize,
-                                          const SnippetRepetitor &Repetitor,
-                                          bool DumpObjectToDisk) const {
+BenchmarkRunner::getRunnableConfiguration(
+    const BenchmarkCode &BC, unsigned NumRepetitions, unsigned LoopBodySize,
+    const SnippetRepetitor &Repetitor) const {
   RunnableConfiguration RC;
 
   InstructionBenchmark &InstrBenchmark = RC.InstrBenchmark;
@@ -193,15 +191,6 @@ BenchmarkRunner::getRunnableConfiguration(const BenchmarkCode &BC,
                                    LoopBodySize);
     if (Error E = Snippet.takeError())
       return std::move(E);
-    if (DumpObjectToDisk) {
-      auto ObjectFilePath = writeObjectFile(*Snippet);
-      if (Error E = ObjectFilePath.takeError()) {
-        InstrBenchmark.Error = toString(std::move(E));
-        return std::move(RC);
-      }
-      outs() << "Check generated assembly with: /usr/bin/objdump -d "
-             << *ObjectFilePath << "\n";
-    }
     RC.ObjectFile = getObjectFromBuffer(*Snippet);
   }
 
@@ -209,10 +198,21 @@ BenchmarkRunner::getRunnableConfiguration(const BenchmarkCode &BC,
 }
 
 Expected<InstructionBenchmark>
-BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC) const {
+BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC,
+                                  bool DumpObjectToDisk) const {
   InstructionBenchmark &InstrBenchmark = RC.InstrBenchmark;
   object::OwningBinary<object::ObjectFile> &ObjectFile = RC.ObjectFile;
 
+  if (DumpObjectToDisk) {
+    auto ObjectFilePath = writeObjectFile(ObjectFile.getBinary()->getData());
+    if (Error E = ObjectFilePath.takeError()) {
+      InstrBenchmark.Error = toString(std::move(E));
+      return std::move(InstrBenchmark);
+    }
+    outs() << "Check generated assembly with: /usr/bin/objdump -d "
+           << *ObjectFilePath << "\n";
+  }
+
   if (BenchmarkSkipMeasurements) {
     InstrBenchmark.Error =
         "in --skip-measurements mode, actual measurements skipped.";
index 5bd9bc2..e55e2e1 100644 (file)
@@ -61,11 +61,10 @@ public:
   Expected<RunnableConfiguration>
   getRunnableConfiguration(const BenchmarkCode &Configuration,
                            unsigned NumRepetitions, unsigned LoopUnrollFactor,
-                           const SnippetRepetitor &Repetitor,
-                           bool DumpObjectToDisk) const;
+                           const SnippetRepetitor &Repetitor) const;
 
-  Expected<InstructionBenchmark>
-  runConfiguration(RunnableConfiguration &&RC) const;
+  Expected<InstructionBenchmark> runConfiguration(RunnableConfiguration &&RC,
+                                                  bool DumpObjectToDisk) const;
 
   // Scratch space to run instructions that touch memory.
   struct ScratchSpace {
index 160a313..c17a29b 100644 (file)
@@ -342,9 +342,9 @@ static void runBenchmarkConfigurations(
     for (const std::unique_ptr<const SnippetRepetitor> &Repetitor :
          Repetitors) {
       auto RC = ExitOnErr(Runner.getRunnableConfiguration(
-          Conf, NumRepetitions, LoopBodySize, *Repetitor, DumpObjectToDisk));
+          Conf, NumRepetitions, LoopBodySize, *Repetitor));
       AllResults.emplace_back(
-          ExitOnErr(Runner.runConfiguration(std::move(RC))));
+          ExitOnErr(Runner.runConfiguration(std::move(RC), DumpObjectToDisk)));
     }
     InstructionBenchmark &Result = AllResults.front();