[llvm] 41dd767 - [NFC][llvm-exegesis] `BenchmarkRunner::runConfiguration()`: deduplicate `DumpObjectToDisk` handling

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 17 12:15:13 PST 2022


Author: Roman Lebedev
Date: 2022-12-17T23:14:53+03:00
New Revision: 41dd767fee7508ac57c8783e401abc04f95e4e0f

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

LOG: [NFC][llvm-exegesis] `BenchmarkRunner::runConfiguration()`: deduplicate `DumpObjectToDisk` handling

Always assemble into buffer, that is then optionally dumped into file.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 2b4e6b74a450..8f25e21a0d59 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -178,16 +178,7 @@ Expected<InstructionBenchmark> BenchmarkRunner::runConfiguration(
       Instructions, InstrBenchmark.NumRepetitions, LoopBodySize);
 
   object::OwningBinary<object::ObjectFile> ObjectFile;
-  if (DumpObjectToDisk) {
-    auto ObjectFilePath = writeObjectFile(BC, Filler);
-    if (Error E = ObjectFilePath.takeError()) {
-      InstrBenchmark.Error = toString(std::move(E));
-      return InstrBenchmark;
-    }
-    outs() << "Check generated assembly with: /usr/bin/objdump -d "
-           << *ObjectFilePath << "\n";
-    ObjectFile = getObjectFromFile(*ObjectFilePath);
-  } else {
+  {
     SmallString<0> Buffer;
     raw_svector_ostream OS(Buffer);
     if (Error E = assembleToStream(State.getExegesisTarget(),
@@ -195,6 +186,15 @@ Expected<InstructionBenchmark> BenchmarkRunner::runConfiguration(
                                    BC.Key.RegisterInitialValues, Filler, OS)) {
       return std::move(E);
     }
+    if (DumpObjectToDisk) {
+      auto ObjectFilePath = writeObjectFile(Buffer);
+      if (Error E = ObjectFilePath.takeError()) {
+        InstrBenchmark.Error = toString(std::move(E));
+        return InstrBenchmark;
+      }
+      outs() << "Check generated assembly with: /usr/bin/objdump -d "
+             << *ObjectFilePath << "\n";
+    }
     ObjectFile = getObjectFromBuffer(OS.str());
   }
 
@@ -226,20 +226,15 @@ Expected<InstructionBenchmark> BenchmarkRunner::runConfiguration(
   return InstrBenchmark;
 }
 
-Expected<std::string>
-BenchmarkRunner::writeObjectFile(const BenchmarkCode &BC,
-                                 const FillFunction &FillFunction) const {
+Expected<std::string> BenchmarkRunner::writeObjectFile(StringRef Buffer) const {
   int ResultFD = 0;
   SmallString<256> ResultPath;
   if (Error E = errorCodeToError(
           sys::fs::createTemporaryFile("snippet", "o", ResultFD, ResultPath)))
     return std::move(E);
   raw_fd_ostream OFS(ResultFD, true /*ShouldClose*/);
-  if (Error E = assembleToStream(
-          State.getExegesisTarget(), State.createTargetMachine(), BC.LiveIns,
-          BC.Key.RegisterInitialValues, FillFunction, OFS)) {
-    return std::move(E);
-  }
+  OFS.write(Buffer.data(), Buffer.size());
+  OFS.flush();
   return std::string(ResultPath.str());
 }
 

diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
index 3932407bd961..f963ff0f6a86 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h
@@ -83,8 +83,7 @@ class BenchmarkRunner {
   virtual Expected<std::vector<BenchmarkMeasure>>
   runMeasurements(const FunctionExecutor &Executor) const = 0;
 
-  Expected<std::string> writeObjectFile(const BenchmarkCode &Configuration,
-                                        const FillFunction &Fill) const;
+  Expected<std::string> writeObjectFile(StringRef Buffer) const;
 
   const std::unique_ptr<ScratchSpace> Scratch;
 };


        


More information about the llvm-commits mailing list