[llvm] dbc76ef - [NFC][llvm-exegesis] Benchmark: move DumpObjectToDisk handling into `runConfiguration()`

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 18 06:52:18 PST 2022


Author: Roman Lebedev
Date: 2022-12-18T17:52:04+03:00
New Revision: dbc76ef7915f925970f7bae1c5b79f3dcf55d85e

URL: https://github.com/llvm/llvm-project/commit/dbc76ef7915f925970f7bae1c5b79f3dcf55d85e
DIFF: https://github.com/llvm/llvm-project/commit/dbc76ef7915f925970f7bae1c5b79f3dcf55d85e.diff

LOG: [NFC][llvm-exegesis] Benchmark: move DumpObjectToDisk handling into `runConfiguration()`

`getRunnableConfiguration()` may be executed in parallel,
and then this the output would become even less useful.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index eb90f4339ec6..37b33ae02113 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -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.";

diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
index 5bd9bc25f186..e55e2e109105 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
@@ -61,11 +61,10 @@ class BenchmarkRunner {
   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 {

diff  --git a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
index 160a313420b3..c17a29b2c34c 100644
--- a/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
+++ b/llvm/tools/llvm-exegesis/llvm-exegesis.cpp
@@ -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();
 


        


More information about the llvm-commits mailing list