From 41dd767fee7508ac57c8783e401abc04f95e4e0f Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sat, 17 Dec 2022 21:15:17 +0300 Subject: [PATCH] [NFC][llvm-exegesis] `BenchmarkRunner::runConfiguration()`: deduplicate `DumpObjectToDisk` handling Always assemble into buffer, that is then optionally dumped into file. --- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 31 ++++++++++-------------- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h | 3 +-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 2b4e6b7..8f25e21 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -178,16 +178,7 @@ Expected BenchmarkRunner::runConfiguration( Instructions, InstrBenchmark.NumRepetitions, LoopBodySize); object::OwningBinary 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 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 BenchmarkRunner::runConfiguration( return InstrBenchmark; } -Expected -BenchmarkRunner::writeObjectFile(const BenchmarkCode &BC, - const FillFunction &FillFunction) const { +Expected 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 3932407..f963ff0 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -83,8 +83,7 @@ private: virtual Expected> runMeasurements(const FunctionExecutor &Executor) const = 0; - Expected writeObjectFile(const BenchmarkCode &Configuration, - const FillFunction &Fill) const; + Expected writeObjectFile(StringRef Buffer) const; const std::unique_ptr Scratch; }; -- 2.7.4