From dbc76ef7915f925970f7bae1c5b79f3dcf55d85e Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sun, 18 Dec 2022 17:36:32 +0300 Subject: [PATCH] [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. --- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 30 ++++++++++++------------ llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h | 7 +++--- llvm/tools/llvm-exegesis/llvm-exegesis.cpp | 4 ++-- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index eb90f43..37b33ae 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -151,11 +151,9 @@ Expected> BenchmarkRunner::assembleSnippet( } Expected -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 -BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC) const { +BenchmarkRunner::runConfiguration(RunnableConfiguration &&RC, + bool DumpObjectToDisk) const { InstructionBenchmark &InstrBenchmark = RC.InstrBenchmark; object::OwningBinary &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 5bd9bc2..e55e2e1 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.h @@ -61,11 +61,10 @@ public: Expected getRunnableConfiguration(const BenchmarkCode &Configuration, unsigned NumRepetitions, unsigned LoopUnrollFactor, - const SnippetRepetitor &Repetitor, - bool DumpObjectToDisk) const; + const SnippetRepetitor &Repetitor) const; - Expected - runConfiguration(RunnableConfiguration &&RC) const; + Expected 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 160a313..c17a29b 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 &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(); -- 2.7.4